handlers: handle err on redirects
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-04-19 04:09:24 +02:00
parent ff252df692
commit 773b10e60b
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ

@ -169,7 +169,7 @@ func Signin() echo.HandlerFunc {
log.Info("got session")
// if err := session.Valid(); err == nil && session.Expires.After(time.Now()) {
if err := session.Valid(); err == nil {
c.Redirect(302, "/home")
return c.Redirect(302, "/home")
} else {
log.Warn("invalid (or expired) session", "error", err.Error())
}
@ -212,18 +212,14 @@ func SigninPost(client *ent.Client) echo.HandlerFunc {
} else {
log.Info("username was not set, returning to /signin")
c.Redirect(302, "/signin")
return nil
return c.Redirect(302, "/signin")
}
if passwd := c.Request().FormValue("password"); passwd != "" {
password = passwd
} else {
log.Info("password was not set, returning to /signin")
c.Redirect(302, "/signin")
return nil
return c.Redirect(302, "/signin")
}
ctx := context.WithValue(context.Background(), "logger", log)
@ -232,7 +228,7 @@ func SigninPost(client *ent.Client) echo.HandlerFunc {
if usr.Password != password {
log.Warn("wrong user credentials, redirecting to /signin")
c.Redirect(302, "/signin")
return c.Redirect(302, "/signin")
}
} else {
// just log the error instead of returning it to the user and
@ -244,9 +240,7 @@ func SigninPost(client *ent.Client) echo.HandlerFunc {
http.StatusText(http.StatusUnauthorized)+" "+err.Error(),
))
c.Redirect(302, "/signin")
return nil
return c.Redirect(302, "/signin")
}
secure := c.Request().URL.Scheme == "https"
@ -261,9 +255,7 @@ func SigninPost(client *ent.Client) echo.HandlerFunc {
}
c.SetCookie(cookieSession)
c.Redirect(301, "/home")
return nil
return c.Redirect(301, "/home")
}
}
@ -279,7 +271,7 @@ func Signup() echo.HandlerFunc {
log.Info("got session")
// if err := session.Valid(); err == nil && session.Expires.After(time.Now()) {
if err := session.Valid(); err == nil {
c.Redirect(302, "/home")
return c.Redirect(302, "/home")
} else {
log.Warn("invalid (or expired) session", "error", err.Error())
}
@ -350,9 +342,7 @@ func SignupPost(client *ent.Client) echo.HandlerFunc {
} else {
log.Info("user registration: username was not set, returning to /signup")
c.Redirect(302, "/signup")
return nil
return c.Redirect(302, "/signup")
}
secure := c.Request().URL.Scheme == "https"
@ -366,9 +356,7 @@ func SignupPost(client *ent.Client) echo.HandlerFunc {
}
c.SetCookie(cookieSession)
c.Redirect(301, "/home")
return nil
return c.Redirect(301, "/home")
}
}
@ -437,9 +425,7 @@ func Logout() echo.HandlerFunc {
if errors.Is(err, http.ErrNoCookie) {
log.Info("nobody to log out, redirecting to /signin")
c.Redirect(302, "/signin")
return nil
return c.Redirect(302, "/signin")
}
log.Warnf("error: %q", err)