package routes import ( "git.matterlinux.xyz/matter/security/lib" "git.matterlinux.xyz/matter/security/log" "github.com/gofiber/fiber/v2" ) func MiddleAuth(c *fiber.Ctx) error { cookie := c.Cookies("auth") if cookie == "" { return c.Redirect("/login") } users, err := lib.LoadUsers() if err != nil { log.Error("Failed to load users: %s", err.Error()) return lib.RenderError(c, 500) } for _, u := range users { if u.Cookie == "notset" || u.Cookie == "" { continue } if cookie == u.Cookie { return c.Next() } } c.ClearCookie("auth") return c.Redirect("/login") } func GET_Manage(c *fiber.Ctx) error { return c.Render("manage", fiber.Map{}) } func GET_Logout(c *fiber.Ctx) error { user, err := lib.GetUser(c) if err != nil { log.Error("Failed to load user: %s", err.Error()) return lib.RenderError(c, 500) } user.Cookie = "notset" err = lib.UpdateUser(user) if err != nil { log.Error("Failed to save users: %s", err.Error()) return lib.RenderError(c, 500) } return c.Redirect("/login") }