Files
2022-02-15 14:21:23 +00:00

29 lines
898 B
Go

package setup
import (
"gitlab.thpeetz.de/domain-thpeetz/kalorienmanager.git/pkg/admin"
"gitlab.thpeetz.de/domain-thpeetz/kalorienmanager.git/pkg/auth"
"gitlab.thpeetz.de/domain-thpeetz/kalorienmanager.git/pkg/util"
"github.com/gin-gonic/gin"
)
// InitializeRoutes setup the routes for Kalorien Manager web application.
func InitializeRoutes(router *gin.Engine) {
// Use the setUserStatus middleware for every route to set a flag
// indicating whether the request was from an authenticated user or not
router.Use(auth.SetSessionStatus())
// Handle the index route
router.GET("/", util.ShowIndexPage)
userRoutes := router.Group("/user")
{
userRoutes.GET("/login", auth.EnsureNotLoggedIn(), admin.ShowLoginPage)
userRoutes.POST("/login", auth.EnsureNotLoggedIn(), admin.PerformLogin)
userRoutes.GET("/logout", auth.EnsureLoggedIn(), admin.Logout)
}
admin.GetRoutes(router)
}