Skip to content

Commit a129c0c

Browse files
lunnywolfogre
andauthored
Fix 500 when deleting account with incorrect password or unsupported login type (#29579) (#29656)
Fix #26210 Backport #29579 Co-authored-by: Jason Song <[email protected]>
1 parent bd7de0c commit a129c0c

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

options/locale/locale_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ enterred_invalid_repo_name = The repository name you entered is incorrect.
567567
enterred_invalid_org_name = The organization name you entered is incorrect.
568568
enterred_invalid_owner_name = The new owner name is not valid.
569569
enterred_invalid_password = The password you entered is incorrect.
570+
unset_password = The login user has not set the password.
571+
unsupported_login_type = The login type is not supported to delete account.
570572
user_not_exist = The user does not exist.
571573
team_not_exist = The team does not exist.
572574
last_org_owner = You cannot remove the last user from the 'owners' team. There must be at least one owner for an organization.

routers/web/user/setting/account.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"code.gitea.io/gitea/modules/timeutil"
2020
"code.gitea.io/gitea/modules/web"
2121
"code.gitea.io/gitea/services/auth"
22+
"code.gitea.io/gitea/services/auth/source/db"
23+
"code.gitea.io/gitea/services/auth/source/smtp"
2224
"code.gitea.io/gitea/services/forms"
2325
"code.gitea.io/gitea/services/mailer"
2426
"code.gitea.io/gitea/services/user"
@@ -236,11 +238,24 @@ func DeleteAccount(ctx *context.Context) {
236238
ctx.Data["PageIsSettingsAccount"] = true
237239

238240
if _, _, err := auth.UserSignIn(ctx, ctx.Doer.Name, ctx.FormString("password")); err != nil {
239-
if user_model.IsErrUserNotExist(err) {
241+
switch {
242+
case user_model.IsErrUserNotExist(err):
243+
loadAccountData(ctx)
244+
245+
ctx.RenderWithErr(ctx.Tr("form.user_not_exist"), tplSettingsAccount, nil)
246+
case errors.Is(err, smtp.ErrUnsupportedLoginType):
247+
loadAccountData(ctx)
248+
249+
ctx.RenderWithErr(ctx.Tr("form.unsupported_login_type"), tplSettingsAccount, nil)
250+
case errors.As(err, &db.ErrUserPasswordNotSet{}):
251+
loadAccountData(ctx)
252+
253+
ctx.RenderWithErr(ctx.Tr("form.unset_password"), tplSettingsAccount, nil)
254+
case errors.As(err, &db.ErrUserPasswordInvalid{}):
240255
loadAccountData(ctx)
241256

242257
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), tplSettingsAccount, nil)
243-
} else {
258+
default:
244259
ctx.ServerError("UserSignIn", err)
245260
}
246261
return

0 commit comments

Comments
 (0)