From 5d11e6e13f7254a72874dabee6c1cf4e81f5ec52 Mon Sep 17 00:00:00 2001 From: "Shishkevich D." <135337715+shishkevichd@users.noreply.github.com> Date: Wed, 2 Jul 2025 16:25:25 +0700 Subject: chore: reset two-factor authentication after changing admin credentials (#3029) * chore: add `resetTwoFactor` argument for main.go fixes #3025 * chore: reset two-factor authentication after changing admin credentials * chore: reset two-factor authentication after changing admin credentials --------- Co-authored-by: somebodywashere <68244480+somebodywashere@users.noreply.github.com> Co-authored-by: Sanaei --- web/service/setting.go | 8 ++++++++ web/service/user.go | 10 ++++++++++ 2 files changed, 18 insertions(+) (limited to 'web/service') diff --git a/web/service/setting.go b/web/service/setting.go index 62d66c11..868d55bc 100644 --- a/web/service/setting.go +++ b/web/service/setting.go @@ -322,10 +322,18 @@ func (s *SettingService) GetTwoFactorEnable() (bool, error) { return s.getBool("twoFactorEnable") } +func (s *SettingService) SetTwoFactorEnable(value bool) error { + return s.setBool("twoFactorEnable", value) +} + func (s *SettingService) GetTwoFactorToken() (string, error) { return s.getString("twoFactorToken") } +func (s *SettingService) SetTwoFactorToken(value string) error { + return s.setString("twoFactorToken", value) +} + func (s *SettingService) GetPort() (int, error) { return s.getInt("webPort") } diff --git a/web/service/user.go b/web/service/user.go index f0b04f52..ff5b8531 100644 --- a/web/service/user.go +++ b/web/service/user.go @@ -79,6 +79,16 @@ func (s *UserService) UpdateUser(id int, username string, password string) error return err } + twoFactorEnable, err := s.settingService.GetTwoFactorEnable() + if err != nil { + return err + } + + if twoFactorEnable { + s.settingService.SetTwoFactorEnable(false) + s.settingService.SetTwoFactorToken("") + } + return db.Model(model.User{}). Where("id = ?", id). Updates(map[string]any{"username": username, "password": hashedPassword}). -- cgit v1.2.3