Skip to content

Commit ce8a98f

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

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
@@ -584,6 +584,8 @@ enterred_invalid_repo_name = The repository name you entered is incorrect.
584584
enterred_invalid_org_name = The organization name you entered is incorrect.
585585
enterred_invalid_owner_name = The new owner name is not valid.
586586
enterred_invalid_password = The password you entered is incorrect.
587+
unset_password = The login user has not set the password.
588+
unsupported_login_type = The login type is not supported to delete account.
587589
user_not_exist = The user does not exist.
588590
team_not_exist = The team does not exist.
589591
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/context"
2325
"code.gitea.io/gitea/services/forms"
2426
"code.gitea.io/gitea/services/mailer"
@@ -242,11 +244,24 @@ func DeleteAccount(ctx *context.Context) {
242244
ctx.Data["PageIsSettingsAccount"] = true
243245

244246
if _, _, err := auth.UserSignIn(ctx, ctx.Doer.Name, ctx.FormString("password")); err != nil {
245-
if user_model.IsErrUserNotExist(err) {
247+
switch {
248+
case user_model.IsErrUserNotExist(err):
249+
loadAccountData(ctx)
250+
251+
ctx.RenderWithErr(ctx.Tr("form.user_not_exist"), tplSettingsAccount, nil)
252+
case errors.Is(err, smtp.ErrUnsupportedLoginType):
253+
loadAccountData(ctx)
254+
255+
ctx.RenderWithErr(ctx.Tr("form.unsupported_login_type"), tplSettingsAccount, nil)
256+
case errors.As(err, &db.ErrUserPasswordNotSet{}):
257+
loadAccountData(ctx)
258+
259+
ctx.RenderWithErr(ctx.Tr("form.unset_password"), tplSettingsAccount, nil)
260+
case errors.As(err, &db.ErrUserPasswordInvalid{}):
246261
loadAccountData(ctx)
247262

248263
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), tplSettingsAccount, nil)
249-
} else {
264+
default:
250265
ctx.ServerError("UserSignIn", err)
251266
}
252267
return

0 commit comments

Comments
 (0)