/*
* Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
*
* This file is licensed under AGPL-3.0-or-later, see NOTICE and LICENSE for
* more information.
*/
package middlewares
import (
"net/http"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
)
func IsAuthenticated(c *gin.Context) {
if sessions.Default(c).Get("profile") == nil {
// TODO: This should probably be validated somehow... DB lookup or something.
c.Redirect(http.StatusSeeOther, "/login")
c.Abort()
} else {
c.Next()
}
}
func CanLogin(c *gin.Context) {
if sessions.Default(c).Get("profile") != nil {
// Don't allow the login page if logged in
c.Redirect(http.StatusSeeOther, "/")
} else {
c.Next()
}
}