diff options
| author | Alexander Kavon <hawk@alexkavon.com> | 2023-12-01 00:45:31 -0500 |
|---|---|---|
| committer | Alexander Kavon <hawk@alexkavon.com> | 2023-12-01 00:45:31 -0500 |
| commit | bc47e526e962c1c5bce850de312c6e5fbaf16458 (patch) | |
| tree | c3a832edf869e75e3fd87494939a34a846778431 /src/user/routes.go | |
| parent | 17af6e1a5017285b680a7d0a1dace1e1a1612ab9 (diff) | |
settled on map[string]interface{} for passing data to view, automatically append session struct, fixed nil session checks, updated templates to use map variable names
Diffstat (limited to 'src/user/routes.go')
| -rw-r--r-- | src/user/routes.go | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/user/routes.go b/src/user/routes.go index 3bcab06..d8c8d43 100644 --- a/src/user/routes.go +++ b/src/user/routes.go @@ -56,7 +56,7 @@ var Routes = server.Routes{ func Create(s *server.Server) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - s.Ui.Render(w, "user/create", nil) + s.Ui.Render(w, r, "user/create", nil) } } @@ -98,7 +98,7 @@ func Store(s *server.Server) http.HandlerFunc { func LoginForm(s *server.Server) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - s.Ui.Render(w, "user/login", nil) + s.Ui.Render(w, r, "user/login", nil) } } @@ -113,16 +113,16 @@ func Login(s *server.Server) http.HandlerFunc { func Logout(s *server.Server) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session := r.Context().Value("session").(*sessions.Session) - session.Destroy(w) + if session := r.Context().Value(sessions.SessionCtxKey("session")); session != nil { + session.(*sessions.Session).Destroy(w) + } http.Redirect(w, r, "/u/auth", http.StatusSeeOther) } } func Show(s *server.Server) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session := r.Context().Value(sessions.SessionCtxKey("session")).(*sessions.Session) - username := session.Get("username").(string) - s.Ui.Render(w, "user/me", &struct{ Message, Username string }{"Congrats on getting this far!", username}) + pageData := map[string]any{"message": "Congrats on getting this far!"} + s.Ui.Render(w, r, "user/me", pageData) } } |
