commit aea56eb3f71a73d1f36175c0dc1db71826a30e37
parent 825777978c0c6e7d21819be2ff3c3768e446deab
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Fri, 9 Feb 2024 18:36:53 -0800
simplify disable 2fa code
Diffstat:
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/pkg/database/tableUsers.go b/pkg/database/tableUsers.go
@@ -363,6 +363,10 @@ func (u *User) DoSave(db *DkfDB) {
}
}
+func (u *User) Disable2FA(db *DkfDB) {
+ db.db.Model(u).Select("TwoFactorSecret", "TwoFactorRecovery").Updates(User{TwoFactorSecret: "", TwoFactorRecovery: ""})
+}
+
func (u *User) SetAgePublicKey(db *DkfDB, agePublicKey string) {
db.db.Model(u).Select("AgePublicKey").Updates(User{AgePublicKey: agePublicKey})
}
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -459,9 +459,7 @@ func TwoFactorAuthenticationDisableHandler(c echo.Context) error {
data.ErrorPassword = "Invalid password"
return c.Render(http.StatusOK, "disable-totp", data)
}
- authUser.TwoFactorSecret = ""
- authUser.TwoFactorRecovery = ""
- authUser.DoSave(db)
+ authUser.Disable2FA(db)
db.CreateSecurityLog(authUser.ID, database.TotpDisabledSecurityLog)
return c.Render(http.StatusOK, "flash", FlashResponse{"Two-factor authentication disabled", "/settings/account", "alert-success"})
}