Mercurial > gemma
changeset 3721:ed4820efb7e6
Password reset: Send redirect to server starting page when reset succeeded.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 20 Jun 2019 18:04:53 +0200 |
parents | 1525ead37a2e |
children | f180de37903c |
files | pkg/controllers/pwreset.go pkg/controllers/routes.go |
diffstat | 2 files changed, 18 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/controllers/pwreset.go Thu Jun 20 17:09:31 2019 +0200 +++ b/pkg/controllers/pwreset.go Thu Jun 20 18:04:53 2019 +0200 @@ -288,15 +288,11 @@ return } -func passwordReset( - _ interface{}, - req *http.Request, - _ *sql.Conn, -) (jr JSONResult, err error) { +func passwordReset(rw http.ResponseWriter, req *http.Request) { hash := mux.Vars(req)["hash"] - if _, err = hex.DecodeString(hash); err != nil { - err = JSONError{http.StatusBadRequest, "Invalid hash"} + if _, err := hex.DecodeString(hash); err != nil { + http.Error(rw, "invalid hash", http.StatusBadRequest) return } @@ -304,7 +300,7 @@ ctx := req.Context() - if err = auth.RunAs( + if err := auth.RunAs( ctx, pwResetRole, func(conn *sql.Conn) error { err := conn.QueryRowContext(ctx, findRequestSQL, hash).Scan(&email, &user) switch { @@ -324,12 +320,18 @@ _, err = conn.ExecContext(ctx, deleteRequestSQL, hash) return err }); err == nil { - body := changedMessageBody(useHTTPS(req), user, password, host(req)) - if err = misc.SendMail(email, "Password Reset Done", body); err == nil { - jr.Result = &struct { - SendTo string `json:"send-to"` - }{email} + https := useHTTPS(req) + server := host(req) + body := changedMessageBody(https, user, password, server) + if err = misc.SendMail(email, "Password Reset Done", body); err != nil { + log.Printf("error: %v\n", err) + http.Error( + rw, + http.StatusText(http.StatusInternalServerError), + http.StatusInternalServerError) + return } + var url = https + "://" + server + http.Redirect(rw, req, url, http.StatusSeeOther) } - return }
--- a/pkg/controllers/routes.go Thu Jun 20 17:09:31 2019 +0200 +++ b/pkg/controllers/routes.go Thu Jun 20 18:04:53 2019 +0200 @@ -104,10 +104,8 @@ NoConn: true, }).Methods(http.MethodPost) - api.Handle("/users/passwordreset/{hash}", &JSONHandler{ - Handle: passwordReset, - NoConn: true, - }).Methods(http.MethodGet) + api.HandleFunc("/users/passwordreset/{hash}", passwordReset). + Methods(http.MethodGet) // Print templates api.Handle("/templates", any(&JSONHandler{