Have got logout working
This commit is contained in:
parent
01c6e9de87
commit
b7e0269e9d
7 changed files with 66 additions and 10 deletions
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue