added cookie login

This commit is contained in:
2025-10-04 12:49:04 -06:00
parent f728eb21b0
commit 3ef8d6b9a6
7 changed files with 172 additions and 15 deletions
+10 -2
View File
@@ -16,6 +16,7 @@ import (
"git.erbosoft.com/amy/amsterdam/database"
"git.erbosoft.com/amy/amsterdam/email"
"git.erbosoft.com/amy/amsterdam/ui"
"github.com/labstack/gommon/log"
)
/* LoginForm renders the Amsterdam login form.
@@ -108,7 +109,14 @@ func Login(ctxt ui.AmContext) (string, any, error) {
}
ctxt.ReplaceUser(user)
if dlg.Field("saveme").IsChecked() {
// TODO: cookie set
// create and save an authentication token
authString, cerr := user.NewAuthToken()
if cerr == nil {
ctxt.SetLoginCookie(authString)
} else {
log.Errorf("unable to generate auth string for uid %d: %v", user.Uid, cerr)
}
}
// TODO: bounce to E-mail verify if we can do so
return "redirect", target, nil
@@ -135,7 +143,7 @@ func Logout(ctxt ui.AmContext) (string, any, error) {
}
if !ctxt.CurrentUser().IsAnon {
// TODO: erase login cookie
ctxt.ClearLoginCookie()
ctxt.ClearSession()
}
return "redirect", target, nil