chore: clean up handlers pkg
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-04-19 22:08:17 +02:00
parent ee98acef74
commit 25335293eb
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
2 changed files with 10 additions and 11 deletions

@ -24,16 +24,13 @@ func setConfig(c *config.Config) {
} }
} }
func getConfig() *config.Config {
return conf
}
func setAppVer(v string) { func setAppVer(v string) {
appver = v appver = v
} }
func InitHandlers(version string, appconf *config.Config, tmpls fs.FS) { func InitHandlers(version string, appconf *config.Config, tmpls fs.FS) {
log = slogging.GetLogger() log = slogging.GetLogger()
setConfig(appconf) setConfig(appconf)
setAppVer(version) setAppVer(version)
initTemplates(tmpls) initTemplates(tmpls)

@ -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 && session.Expires.After(time.Now()) {
if err := session.Valid(); err == nil { if err := session.Valid(); err == nil {
return c.Redirect(302, "/home") 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") tpl := getTmpl("signin.tmpl")
@ -189,6 +189,7 @@ func SigninPost(client *ent.Client) echo.HandlerFunc {
return c.Redirect(302, "/signin") return c.Redirect(302, "/signin")
} }
if passwd := c.Request().FormValue("password"); passwd != "" { if passwd := c.Request().FormValue("password"); passwd != "" {
password = passwd password = passwd
} else { } else {
@ -197,7 +198,7 @@ func SigninPost(client *ent.Client) echo.HandlerFunc {
return c.Redirect(302, "/signin") 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 { if usr, err := moduser.QueryUser(ctx, client, username); err == nil {
log.Info("queried user:", &usr.ID) log.Info("queried user:", &usr.ID)
@ -219,7 +220,7 @@ func SigninPost(client *ent.Client) echo.HandlerFunc {
return c.Redirect(302, "/signin") return c.Redirect(302, "/signin")
} }
secure := c.Request().URL.Scheme == "https" secure := c.Request().URL.Scheme == "https" //nolint:goconst
cookieSession := &http.Cookie{ cookieSession := &http.Cookie{
Name: "session", Name: "session",
@ -300,7 +301,7 @@ func SignupPost(client *ent.Client) echo.HandlerFunc {
username = uname username = uname
if passwd := c.Request().FormValue("password"); passwd != "" { 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) u, err := moduser.CreateUser(ctx, client, username, passwd)
if err != nil { if err != nil {
@ -322,7 +323,7 @@ func SignupPost(client *ent.Client) echo.HandlerFunc {
return c.Redirect(302, "/signup") return c.Redirect(302, "/signup")
} }
secure := c.Request().URL.Scheme == "https" secure := c.Request().URL.Scheme == "https" //nolint:goconst
cookieSession := &http.Cookie{ cookieSession := &http.Cookie{
Name: "session", Name: "session",
Value: username, Value: username,
@ -342,6 +343,7 @@ func Home() echo.HandlerFunc {
var username string var username string
tpl := getTmpl("home.tmpl") tpl := getTmpl("home.tmpl")
session, err := c.Cookie("session") session, err := c.Cookie("session")
if err != nil { if err != nil {
if err == http.ErrNoCookie { if err == http.ErrNoCookie {
@ -418,7 +420,7 @@ func Logout() echo.HandlerFunc {
log.Infof("logging out user '%s'", username) log.Infof("logging out user '%s'", username)
secure := c.Request().URL.Scheme == "https" secure := c.Request().URL.Scheme == "https" //nolint:goconst
cookieSession := &http.Cookie{ cookieSession := &http.Cookie{
Name: "session", Name: "session",
Value: "", Value: "",