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