# HG changeset patch # User Sascha L. Teichmann # Date 1561046693 -7200 # Node ID ed4820efb7e63cc699000cef23d275526e00c1eb # Parent 1525ead37a2e2a7024f347ac0ec8231ca4fe90b9 Password reset: Send redirect to server starting page when reset succeeded. diff -r 1525ead37a2e -r ed4820efb7e6 pkg/controllers/pwreset.go --- 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 } diff -r 1525ead37a2e -r ed4820efb7e6 pkg/controllers/routes.go --- 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{