go-urlsh/internal/web/root.go

29 lines
553 B
Go
Raw Normal View History

2023-04-27 12:34:24 +02:00
package web
import (
"codeberg.org/lauralani/go-urlsh/internal/db"
"github.com/gofiber/fiber/v2"
)
func HandleAdminRootGet(c *fiber.Ctx) error {
cookie := c.Cookies("gourlsh_auth")
if cookie == "" {
c.Location("/admin/login")
c.Status(fiber.StatusSeeOther)
return nil
}
if db.IsCookieValid(cookie) {
// Render index template
return c.Render("index", fiber.Map{
"Title": "It works",
"Plat": "almost",
})
} else {
c.ClearCookie("gourlsh_auth")
c.Location("/admin/login")
c.Status(fiber.StatusSeeOther)
return nil
}
}