Have got logout working

This commit is contained in:
Leon Mika 2026-02-25 22:30:28 +11:00
parent 01c6e9de87
commit b7e0269e9d
7 changed files with 66 additions and 10 deletions

View file

@ -29,12 +29,21 @@ func (lh *LoginHandler) Login(c fiber.Ctx) error {
return nil
}
func (lh *LoginHandler) Logout(c fiber.Ctx) error {
sess := session.FromContext(c)
sess.Destroy()
return c.Redirect().To("/login")
}
func (lh *LoginHandler) DoLogin(c fiber.Ctx) error {
var req struct {
Username string `form:"username"`
Password string `form:"password"`
LoginChallenge string `form:"_login_challenge"`
}
if err := c.Bind().Body(&req); err != nil {
return c.Status(fiber.StatusBadRequest).SendString("Failed to parse request body")
}
if req.Username == "" || req.Password == "" {
return c.Status(fiber.StatusBadRequest).SendString("Username and password are required")
@ -43,7 +52,7 @@ func (lh *LoginHandler) DoLogin(c fiber.Ctx) error {
sess := session.FromContext(c)
challenge, _ := sess.Get("_login_challenge").(string)
if challenge == req.LoginChallenge {
if challenge != req.LoginChallenge {
return c.Redirect().To("/login")
}