Skip to content

Commit 66061d2

Browse files
lunnywolfogre
authored andcommitted
Fix 500 when deleting account with incorrect password or unsupported login type (go-gitea#29579) (go-gitea#29656)
Fix go-gitea#26210 Backport go-gitea#29579 Co-authored-by: Jason Song <[email protected]> (cherry picked from commit a129c0c)
1 parent e151e04 commit 66061d2

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

options/locales/gitea_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,8 @@ enterred_invalid_repo_name = The repository name you entered is incorrect.
574574
enterred_invalid_org_name = The organization name you entered is incorrect.
575575
enterred_invalid_owner_name = The new owner name is not valid.
576576
enterred_invalid_password = The password you entered is incorrect.
577+
unset_password = The login user has not set the password.
578+
unsupported_login_type = The login type is not supported to delete account.
577579
user_not_exist = The user does not exist.
578580
team_not_exist = The team does not exist.
579581
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"
@@ -245,11 +247,24 @@ func DeleteAccount(ctx *context.Context) {
245247
ctx.Data["PageIsSettingsAccount"] = true
246248

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

251266
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), tplSettingsAccount, nil)
252-
} else {
267+
default:
253268
ctx.ServerError("UserSignIn", err)
254269
}
255270
return

0 commit comments

Comments
 (0)