CHANGE: user login style

This commit is contained in:
2025-02-21 20:44:35 +01:00
parent f6e77bda66
commit 3be2a47c56
8 changed files with 122 additions and 30 deletions

View File

@@ -21,18 +21,18 @@ func CreateSessionManager(lifetime time.Duration) *scs.SessionManager {
func LoginHandler(w http.ResponseWriter, r *http.Request){
switch r.Method{
case http.MethodGet: showForm(w, r)
case http.MethodGet: showForm(w, r, false)
break
case http.MethodPost: loginUser(w, r)
break
default:
showForm(w, r)
showForm(w, r, false)
break
}
}
func showForm(w http.ResponseWriter, r *http.Request){
templates.LoginForm().Render(r.Context(), w)
func showForm(w http.ResponseWriter, r *http.Request, failed bool){
templates.LoginForm(failed).Render(r.Context(), w)
}
func loginUser(w http.ResponseWriter, r *http.Request){
@@ -66,7 +66,9 @@ func loginUser(w http.ResponseWriter, r *http.Request){
log.Printf("New succesfull user login from %s %s!\n", user.Vorname, user.Name)
Session.Put(r.Context(), "user", user.PersonalNummer)
http.Redirect(w, r, "/time", http.StatusSeeOther) //with this browser always uses GET
}else{
showForm(w, r, true)
}
showForm(w, r)
showForm(w, r, false)
}