This commit is contained in:
@@ -15,9 +15,9 @@ func LoginGetHandler(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
logger := slog.Get(c)
|
||||
logger.Info("LoginGetHandler", "user", user)
|
||||
logger.Info("LoginGetHandler", globals.UserKey, user)
|
||||
if user != nil {
|
||||
c.HTML(http.StatusBadRequest, "login.tmpl", gin.H{
|
||||
c.HTML(http.StatusBadRequest, "login.html", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"login": globals.LoginUrl,
|
||||
@@ -26,7 +26,7 @@ func LoginGetHandler(c *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
c.HTML(http.StatusOK, "login.tmpl", gin.H{
|
||||
c.HTML(http.StatusOK, "login.html", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"login": globals.LoginUrl,
|
||||
@@ -41,7 +41,7 @@ func LoginPostHandler(c *gin.Context) {
|
||||
logger := slog.Get(c)
|
||||
logger.Info("LoginPostHandler", "user", user)
|
||||
if user != nil {
|
||||
c.HTML(http.StatusBadRequest, "login.tmpl", gin.H{
|
||||
c.HTML(http.StatusBadRequest, "login.html", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"login": globals.LoginUrl,
|
||||
@@ -54,7 +54,7 @@ func LoginPostHandler(c *gin.Context) {
|
||||
password := c.PostForm("password")
|
||||
|
||||
if helpers.EmptyUserPass(username, password) {
|
||||
c.HTML(http.StatusBadRequest, "login.tmpl", gin.H{
|
||||
c.HTML(http.StatusBadRequest, "login.html", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"login": globals.LoginUrl,
|
||||
@@ -63,7 +63,7 @@ func LoginPostHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
if !helpers.CheckUserPass(username, password) {
|
||||
c.HTML(http.StatusUnauthorized, "login.tmpl", gin.H{
|
||||
c.HTML(http.StatusUnauthorized, "login.html", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"login": globals.LoginUrl,
|
||||
@@ -73,7 +73,7 @@ func LoginPostHandler(c *gin.Context) {
|
||||
|
||||
session.Set(globals.UserKey, username)
|
||||
if err := session.Save(); err != nil {
|
||||
c.HTML(http.StatusInternalServerError, "login.tmpl", gin.H{
|
||||
c.HTML(http.StatusInternalServerError, "login.html", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"login": globals.LoginUrl,
|
||||
@@ -90,7 +90,7 @@ func LogoutGetHandler(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
logger := slog.Get(c)
|
||||
logger.Info("LogoutGetHandler", "user", user)
|
||||
logger.Info("LogoutGetHandler", globals.UserKey, user)
|
||||
if user == nil {
|
||||
logger.Info("Invalid session token")
|
||||
return
|
||||
|
||||
@@ -13,11 +13,12 @@ func IndexGetHandler(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
logger := slog.Get(c)
|
||||
logger.Info("IndexGetHandler", "user", user)
|
||||
c.HTML(http.StatusOK, "index.tmpl", gin.H{
|
||||
logger.Info("IndexGetHandler", globals.UserKey, user)
|
||||
c.HTML(http.StatusOK, "home.html", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"content": "This is an index page...",
|
||||
"login": globals.LoginUrl,
|
||||
"logout": globals.LogoutUrl,
|
||||
"user": user,
|
||||
})
|
||||
|
||||
@@ -30,25 +30,24 @@ func ListMediaLoFis(c *gin.Context) {
|
||||
result := schema.DB.Find(&lofis)
|
||||
log.Printf("found %d MediaLoFis", result.RowsAffected)
|
||||
c.JSON(http.StatusOK, lofis)
|
||||
// c.JSON(http.StatusOK, gin.H{
|
||||
// "message": "All MediaLoFis",
|
||||
// "lofis": lofis,
|
||||
// })
|
||||
}
|
||||
|
||||
func ListMediaActorsGetHandler(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
logger := slog.Get(c)
|
||||
|
||||
var actors []schema.MediaActor
|
||||
|
||||
result := schema.DB.Find(&actors)
|
||||
log.Printf("found %d MediaActors", result.RowsAffected)
|
||||
c.HTML(http.StatusOK, "media_actor.tmpl", gin.H{
|
||||
logger.Info("ListMediaActorsGetHandler", "count", result.RowsAffected)
|
||||
c.HTML(http.StatusOK, "mediaactors.html", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"content": "Media Actors...",
|
||||
"actors": actors,
|
||||
"login": globals.LoginUrl,
|
||||
"logout": globals.LogoutUrl,
|
||||
"user": user,
|
||||
})
|
||||
}
|
||||
@@ -61,12 +60,14 @@ func ListMediaFilesGetHandler(c *gin.Context) {
|
||||
var files []schema.MediaFile
|
||||
|
||||
result := schema.DB.Find(&files)
|
||||
logger.Info("found MediaFiles", "count", result.RowsAffected)
|
||||
c.HTML(http.StatusOK, "media_files.tmpl", gin.H{
|
||||
logger.Info("ListMediaFilesGetHandler", "count", result.RowsAffected)
|
||||
c.HTML(http.StatusOK, "mediafiles.html", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"content": "Media Files...",
|
||||
"files": files,
|
||||
"login": globals.LoginUrl,
|
||||
"logout": globals.LogoutUrl,
|
||||
"user": user,
|
||||
})
|
||||
|
||||
@@ -80,14 +81,14 @@ func ListMediaLoFisGetHandler(c *gin.Context) {
|
||||
var lofis []schema.MediaLoFi
|
||||
|
||||
result := schema.DB.Find(&lofis)
|
||||
logger.Info("found MediaActors", "count", result.RowsAffected)
|
||||
c.HTML(http.StatusOK, "media_lofi.tmpl", gin.H{
|
||||
logger.Info("ListMediaLoFisGetHandler", "count", result.RowsAffected)
|
||||
c.HTML(http.StatusOK, "media_lofi.html", gin.H{
|
||||
"title": "Kontor Gin",
|
||||
"version": "0.4.0",
|
||||
"content": "Media LoFis...",
|
||||
"lofis": lofis,
|
||||
"login": globals.LoginUrl,
|
||||
"logout": globals.LogoutUrl,
|
||||
"user": user,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@ const UserKey = "user"
|
||||
|
||||
const Version = "0.4.0"
|
||||
|
||||
const LoginUrl = "/login"
|
||||
const LoginUrl = "/auth/login"
|
||||
|
||||
const LogoutUrl = "/exit"
|
||||
const LogoutUrl = "/auth/logout"
|
||||
|
||||
@@ -3,21 +3,32 @@ package routes
|
||||
import (
|
||||
"kontor-api-gin/pkg/controllers"
|
||||
"kontor-api-gin/pkg/globals"
|
||||
"kontor-api-gin/pkg/middleware"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func PublicRoutes(g *gin.RouterGroup) {
|
||||
func PublicRoutes(g *gin.Engine) {
|
||||
g.GET("/health", controllers.HealthGetHandler)
|
||||
g.GET(globals.LoginUrl, controllers.LoginGetHandler)
|
||||
g.POST(globals.LoginUrl, controllers.LoginPostHandler)
|
||||
g.GET("/comic/comics", controllers.ListComicsGetHandler)
|
||||
g.GET("", controllers.IndexGetHandler)
|
||||
g.GET("/", controllers.IndexGetHandler)
|
||||
}
|
||||
|
||||
func ProtectedRoutes(g *gin.RouterGroup) {
|
||||
g.GET(globals.LogoutUrl, controllers.LogoutGetHandler)
|
||||
g.GET("/media/actors", controllers.ListMediaActorsGetHandler)
|
||||
// g.GET("/media/files", controllers.ListMediaFilesGetHandler)
|
||||
g.GET("/media/lofis", controllers.ListMediaLoFisGetHandler)
|
||||
func ComicRoutes(g *gin.Engine) {
|
||||
g.GET("/comic/comics", controllers.ListComicsGetHandler)
|
||||
}
|
||||
|
||||
func MediaRoutes(g *gin.Engine) {
|
||||
media := g.Group("/media")
|
||||
media.Use(middleware.AuthRequired)
|
||||
media.GET("/actors", controllers.ListMediaActorsGetHandler)
|
||||
media.GET("/files", controllers.ListMediaFilesGetHandler)
|
||||
media.GET("/lofis", controllers.ListMediaLoFisGetHandler)
|
||||
}
|
||||
|
||||
func ProtectedRoutes(g *gin.Engine) {
|
||||
auth := g.Group("/auth")
|
||||
auth.Use(middleware.AuthRequired)
|
||||
auth.GET("/logout", controllers.LogoutGetHandler)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user