From 9c6f2a132dcafa8d6c1ace6a0c01b2e8569c65c7 Mon Sep 17 00:00:00 2001
From: Lunny Xiao <xiaolunwen@gmail.com>
Date: Wed, 23 Oct 2024 09:28:28 +0800
Subject: [PATCH 1/3] Add warn log when deleting inactive users (#32318)

Add log for the problem #31480

(cherry picked from commit a264c46fb04112c5ec2c1b2acd523a2e4450da40)

Conflicts:
	- services/user/user.go
	  Resolved by manually adding the log line.
---
 services/user/user.go | 1 +
 1 file changed, 1 insertion(+)

diff --git a/services/user/user.go b/services/user/user.go
index 4e983eb9f6..653f5a9cd2 100644
--- a/services/user/user.go
+++ b/services/user/user.go
@@ -306,6 +306,7 @@ func DeleteInactiveUsers(ctx context.Context, olderThan time.Duration) error {
 			// Ignore users that were set inactive by admin.
 			if models.IsErrUserOwnRepos(err) || models.IsErrUserHasOrgs(err) ||
 				models.IsErrUserOwnPackages(err) || models.IsErrDeleteLastAdminUser(err) {
+				log.Warn("Inactive user %q has repositories, organizations or packages, skipping deletion: %v", u.Name, err)
 				continue
 			}
 			return err

From 768402c8841db5e8acc97919149ba329d5124e17 Mon Sep 17 00:00:00 2001
From: Lunny Xiao <xiaolunwen@gmail.com>
Date: Wed, 23 Oct 2024 14:41:00 +0800
Subject: [PATCH 2/3] Fix disable 2fa bug (#32320)

(cherry picked from commit 2abdbe88b5d16dcb345d27b73f1d9738f2d826dd)
---
 routers/web/user/setting/security/2fa.go | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/routers/web/user/setting/security/2fa.go b/routers/web/user/setting/security/2fa.go
index a145867ea4..7c85c0e4b7 100644
--- a/routers/web/user/setting/security/2fa.go
+++ b/routers/web/user/setting/security/2fa.go
@@ -34,8 +34,9 @@ func RegenerateScratchTwoFactor(ctx *context.Context) {
 		if auth.IsErrTwoFactorNotEnrolled(err) {
 			ctx.Flash.Error(ctx.Tr("settings.twofa_not_enrolled"))
 			ctx.Redirect(setting.AppSubURL + "/user/settings/security")
+		} else {
+			ctx.ServerError("SettingsTwoFactor: Failed to GetTwoFactorByUID", err)
 		}
-		ctx.ServerError("SettingsTwoFactor: Failed to GetTwoFactorByUID", err)
 		return
 	}
 
@@ -64,8 +65,9 @@ func DisableTwoFactor(ctx *context.Context) {
 		if auth.IsErrTwoFactorNotEnrolled(err) {
 			ctx.Flash.Error(ctx.Tr("settings.twofa_not_enrolled"))
 			ctx.Redirect(setting.AppSubURL + "/user/settings/security")
+		} else {
+			ctx.ServerError("SettingsTwoFactor: Failed to GetTwoFactorByUID", err)
 		}
-		ctx.ServerError("SettingsTwoFactor: Failed to GetTwoFactorByUID", err)
 		return
 	}
 
@@ -74,8 +76,9 @@ func DisableTwoFactor(ctx *context.Context) {
 			// There is a potential DB race here - we must have been disabled by another request in the intervening period
 			ctx.Flash.Success(ctx.Tr("settings.twofa_disabled"))
 			ctx.Redirect(setting.AppSubURL + "/user/settings/security")
+		} else {
+			ctx.ServerError("SettingsTwoFactor: Failed to DeleteTwoFactorByID", err)
 		}
-		ctx.ServerError("SettingsTwoFactor: Failed to DeleteTwoFactorByID", err)
 		return
 	}
 

From d763886daeeb1fa6bc91eb81003f096cf03ad438 Mon Sep 17 00:00:00 2001
From: Earl Warren <contact@earl-warren.org>
Date: Sun, 27 Oct 2024 12:05:14 +0100
Subject: [PATCH 3/3] chore(release-notes): notes for the week 2024-44-v9.0
 weekly cherry pick

---
 release-notes/5715.md | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 release-notes/5715.md

diff --git a/release-notes/5715.md b/release-notes/5715.md
new file mode 100644
index 0000000000..fa8a2cc533
--- /dev/null
+++ b/release-notes/5715.md
@@ -0,0 +1 @@
+fix: [commit](https://codeberg.org/forgejo/forgejo/commit/768402c8841db5e8acc97919149ba329d5124e17) Fix disable 2fa bug