Skip to content

Commit 9881b8a

Browse files
authored
Add more descriptive error on forgot password page (#26848)
## Changes - Forces flashed error to render immediately when forgot password code is incorrect or has expired. - Adds a link back to the `forgot_password` page so that the user can restart the process (in the event that their link has expired)
1 parent 04771b5 commit 9881b8a

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ email_not_associate = The email address is not associated with any account.
379379
send_reset_mail = Send Account Recovery Email
380380
reset_password = Account Recovery
381381
invalid_code = Your confirmation code is invalid or has expired.
382+
invalid_code_forgot_password = Your confirmation code is invalid or has expired. Click <a href="%s">here</a> to start a new session.
382383
invalid_password = Your password does not match the password that was used to create the account.
383384
reset_password_helper = Recover Account
384385
reset_password_wrong_user = You are signed in as %s, but the account recovery link is meant for %s

routers/web/auth/password.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package auth
55

66
import (
77
"errors"
8+
"fmt"
89
"net/http"
910

1011
"code.gitea.io/gitea/models/auth"
@@ -108,14 +109,14 @@ func commonResetPassword(ctx *context.Context) (*user_model.User, *auth.TwoFacto
108109
}
109110

110111
if len(code) == 0 {
111-
ctx.Flash.Error(ctx.Tr("auth.invalid_code"))
112+
ctx.Flash.Error(ctx.Tr("auth.invalid_code_forgot_password", fmt.Sprintf("%s/user/forgot_password", setting.AppSubURL)), true)
112113
return nil, nil
113114
}
114115

115116
// Fail early, don't frustrate the user
116117
u := user_model.VerifyUserActiveCode(code)
117118
if u == nil {
118-
ctx.Flash.Error(ctx.Tr("auth.invalid_code"))
119+
ctx.Flash.Error(ctx.Tr("auth.invalid_code_forgot_password", fmt.Sprintf("%s/user/forgot_password", setting.AppSubURL)), true)
119120
return nil, nil
120121
}
121122

@@ -134,7 +135,7 @@ func commonResetPassword(ctx *context.Context) (*user_model.User, *auth.TwoFacto
134135
ctx.Data["user_email"] = u.Email
135136

136137
if nil != ctx.Doer && u.ID != ctx.Doer.ID {
137-
ctx.Flash.Error(ctx.Tr("auth.reset_password_wrong_user", ctx.Doer.Email, u.Email))
138+
ctx.Flash.Error(ctx.Tr("auth.reset_password_wrong_user", ctx.Doer.Email, u.Email), true)
138139
return nil, nil
139140
}
140141

templates/user/auth/reset_passwd.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
{{end}}
5858
</div>
5959
{{else}}
60-
<p class="center">{{.locale.Tr "auth.invalid_code"}}</p>
60+
<p class="center">{{.locale.Tr "auth.invalid_code_forgot_password" (printf "%s/user/forgot_password" AppSubUrl) | Str2html}}</p>
6161
{{end}}
6262
</div>
6363
</form>

0 commit comments

Comments
 (0)