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) {
appver = v
}
func InitHandlers(version string, appconf *config.Config, tmpls fs.FS) {
log = slogging.GetLogger()
setConfig(appconf)
setAppVer(version)
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 {
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: "",