From 25335293ebf7c70eed8e1492197877275ac95796 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 19 Apr 2023 22:08:17 +0200 Subject: [PATCH] chore: clean up handlers pkg --- handlers/config.go | 5 +---- handlers/handlers.go | 16 +++++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/handlers/config.go b/handlers/config.go index a778fd7..e7a82c0 100644 --- a/handlers/config.go +++ b/handlers/config.go @@ -24,16 +24,13 @@ func setConfig(c *config.Config) { } } -func getConfig() *config.Config { - return conf -} - func setAppVer(v string) { appver = v } func InitHandlers(version string, appconf *config.Config, tmpls fs.FS) { log = slogging.GetLogger() + setConfig(appconf) setAppVer(version) initTemplates(tmpls) diff --git a/handlers/handlers.go b/handlers/handlers.go index 607e072..59e4f53 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -146,9 +146,9 @@ func Signin() echo.HandlerFunc { // if err := session.Valid(); err == nil && session.Expires.After(time.Now()) { if err := session.Valid(); err == nil { return c.Redirect(302, "/home") - } else { - log.Warn("invalid (or expired) session", "error", err.Error()) } + + log.Warn("invalid (or expired) session", "error", err.Error()) } tpl := getTmpl("signin.tmpl") @@ -189,6 +189,7 @@ func SigninPost(client *ent.Client) echo.HandlerFunc { return c.Redirect(302, "/signin") } + if passwd := c.Request().FormValue("password"); passwd != "" { password = passwd } else { @@ -197,7 +198,7 @@ func SigninPost(client *ent.Client) echo.HandlerFunc { return c.Redirect(302, "/signin") } - ctx := context.WithValue(context.Background(), "l", log) + ctx := context.WithValue(context.Background(), "l", log) //nolint:staticcheck,revive if usr, err := moduser.QueryUser(ctx, client, username); err == nil { log.Info("queried user:", &usr.ID) @@ -219,7 +220,7 @@ func SigninPost(client *ent.Client) echo.HandlerFunc { return c.Redirect(302, "/signin") } - secure := c.Request().URL.Scheme == "https" + secure := c.Request().URL.Scheme == "https" //nolint:goconst cookieSession := &http.Cookie{ Name: "session", @@ -300,7 +301,7 @@ func SignupPost(client *ent.Client) echo.HandlerFunc { username = uname if passwd := c.Request().FormValue("password"); passwd != "" { - ctx := context.WithValue(context.Background(), "l", log) + ctx := context.WithValue(context.Background(), "l", log) // nolint:staticcheck,revive u, err := moduser.CreateUser(ctx, client, username, passwd) if err != nil { @@ -322,7 +323,7 @@ func SignupPost(client *ent.Client) echo.HandlerFunc { return c.Redirect(302, "/signup") } - secure := c.Request().URL.Scheme == "https" + secure := c.Request().URL.Scheme == "https" //nolint:goconst cookieSession := &http.Cookie{ Name: "session", Value: username, @@ -342,6 +343,7 @@ func Home() echo.HandlerFunc { var username string tpl := getTmpl("home.tmpl") + session, err := c.Cookie("session") if err != nil { if err == http.ErrNoCookie { @@ -418,7 +420,7 @@ func Logout() echo.HandlerFunc { log.Infof("logging out user '%s'", username) - secure := c.Request().URL.Scheme == "https" + secure := c.Request().URL.Scheme == "https" //nolint:goconst cookieSession := &http.Cookie{ Name: "session", Value: "",