From 074792be8fe24c789da81fc980081e5a128faa87 Mon Sep 17 00:00:00 2001 From: Vicente Ferrari Smith Date: Mon, 25 May 2026 10:32:36 +0200 Subject: [PATCH] . --- cmd/party/api/users.go | 5 +++++ cmd/party/routes.go | 2 +- cmd/party/web/users.go | 19 ++++++++++--------- web/html/activated.frag.tmpl | 5 +++++ web/html/activated.page.tmpl | 8 ++------ 5 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 web/html/activated.frag.tmpl diff --git a/cmd/party/api/users.go b/cmd/party/api/users.go index 6e1427d..be0cc1f 100644 --- a/cmd/party/api/users.go +++ b/cmd/party/api/users.go @@ -53,6 +53,11 @@ func (api *Api) CreateUser(w http.ResponseWriter, r *http.Request) { return } + api.App.Logger.PrintInfo("user registered", map[string]string{ + "user_id": strconv.FormatInt(user.ID, 10), + "email": user.Email, + }) + if err = common.WriteJSON(w, http.StatusCreated, common.Envelope{"user": user, "authentication_token": authToken}, nil); err != nil { api.errorResponse(w, r, err) } diff --git a/cmd/party/routes.go b/cmd/party/routes.go index 250bb37..45b8e33 100644 --- a/cmd/party/routes.go +++ b/cmd/party/routes.go @@ -63,7 +63,7 @@ func routes(app *common.Application) http.Handler { webMux.HandleFunc("GET /users", web.RequirePermission("users:read", web.UsersPage)) webMux.HandleFunc("GET /users/me", web.RequireAuthenticatedUser(web.ProfilePage)) webMux.HandleFunc("GET /users/activated", web.ActivatePage) - webMux.HandleFunc("POST /users/activated", web.ActivateUserAction) + webMux.HandleFunc("PUT /users/activated", web.ActivateUserAction) webMux.HandleFunc("DELETE /users/{id}", web.RequirePermission("users:write", web.DeleteUserAction)) webMux.HandleFunc("GET /mps", web.MembersOfParliamentPage) diff --git a/cmd/party/web/users.go b/cmd/party/web/users.go index 9be22cd..441ede2 100644 --- a/cmd/party/web/users.go +++ b/cmd/party/web/users.go @@ -65,7 +65,11 @@ func (web *Web) RegisterUserPage(w http.ResponseWriter, r *http.Request) { } setCookie(w, authToken.Plaintext, authToken.Expiry) - http.Redirect(w, r, "/issues", http.StatusSeeOther) + if web.App.Config.Env == "production" { + http.Redirect(w, r, "/users/activated", http.StatusSeeOther) + } else { + http.Redirect(w, r, "/issues", http.StatusSeeOther) + } } func (web *Web) ProfilePage(w http.ResponseWriter, r *http.Request) { @@ -158,19 +162,16 @@ func (web *Web) ActivateUserAction(w http.ResponseWriter, r *http.Request) { web.App.LogError(r, err) msg = "Aktivierung fehlgeschlagen. Bitte versuchen Sie es erneut." } - web.render(w, r, http.StatusUnprocessableEntity, "activated", struct { - AuthenticatedUser *data.User - FormErrors []string - Token string + web.renderFragment(w, r, http.StatusUnprocessableEntity, "activated", struct { + FormErrors []string }{ - AuthenticatedUser: common.GetUser(r), - FormErrors: []string{msg}, - Token: token, + FormErrors: []string{msg}, }) return } - http.Redirect(w, r, "/", http.StatusSeeOther) + w.Header().Set("HX-Redirect", "/") + w.WriteHeader(http.StatusOK) } func (web *Web) DeleteUserAction(w http.ResponseWriter, r *http.Request) { diff --git a/web/html/activated.frag.tmpl b/web/html/activated.frag.tmpl new file mode 100644 index 0000000..4aa7297 --- /dev/null +++ b/web/html/activated.frag.tmpl @@ -0,0 +1,5 @@ +{{define "activated"}} +
+ {{range .FormErrors}}

{{.}}

{{end}} +
+{{end}} diff --git a/web/html/activated.page.tmpl b/web/html/activated.page.tmpl index 5ae4f64..8924251 100644 --- a/web/html/activated.page.tmpl +++ b/web/html/activated.page.tmpl @@ -8,13 +8,9 @@

Konto aktivieren

Geben Sie Ihren Aktivierungstoken ein, um Ihr Konto freizuschalten.

- {{if .FormErrors}} -
- {{range .FormErrors}}

{{.}}

{{end}} -
- {{end}} +
-
+