|
@@ -88,6 +88,10 @@ func (a *SettingController) updateSetting(c *gin.Context) {
|
|
|
}
|
|
}
|
|
|
oldTwoFactor, twoFactorErr := a.settingService.GetTwoFactorEnable()
|
|
oldTwoFactor, twoFactorErr := a.settingService.GetTwoFactorEnable()
|
|
|
oldPanelOutbound, _ := a.settingService.GetPanelOutbound()
|
|
oldPanelOutbound, _ := a.settingService.GetPanelOutbound()
|
|
|
|
|
+ oldTgEnable, _ := a.settingService.GetTgbotEnabled()
|
|
|
|
|
+ oldTgToken, _ := a.settingService.GetTgBotToken()
|
|
|
|
|
+ oldTgChatId, _ := a.settingService.GetTgBotChatId()
|
|
|
|
|
+ oldTgAPIServer, _ := a.settingService.GetTgBotAPIServer()
|
|
|
err := a.settingService.UpdateAllSetting(allSetting)
|
|
err := a.settingService.UpdateAllSetting(allSetting)
|
|
|
if err == nil && twoFactorErr == nil && !oldTwoFactor && allSetting.TwoFactorEnable {
|
|
if err == nil && twoFactorErr == nil && !oldTwoFactor && allSetting.TwoFactorEnable {
|
|
|
if bumpErr := a.userService.BumpLoginEpoch(); bumpErr != nil {
|
|
if bumpErr := a.userService.BumpLoginEpoch(); bumpErr != nil {
|
|
@@ -102,6 +106,16 @@ func (a *SettingController) updateSetting(c *gin.Context) {
|
|
|
logger.Warning("apply panel outbound change failed:", applyErr)
|
|
logger.Warning("apply panel outbound change failed:", applyErr)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // UpdateAllSetting already restored a redacted-blank token, so allSetting.TgBotToken is the effective value to compare.
|
|
|
|
|
+ if err == nil && reloadTgbotFunc != nil {
|
|
|
|
|
+ tgChanged := oldTgEnable != allSetting.TgBotEnable ||
|
|
|
|
|
+ (allSetting.TgBotEnable && (oldTgToken != allSetting.TgBotToken ||
|
|
|
|
|
+ oldTgChatId != allSetting.TgBotChatId ||
|
|
|
|
|
+ oldTgAPIServer != allSetting.TgBotAPIServer))
|
|
|
|
|
+ if tgChanged {
|
|
|
|
|
+ reloadTgbotFunc()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
jsonMsg(c, I18nWeb(c, "pages.settings.toasts.modifySettings"), err)
|
|
jsonMsg(c, I18nWeb(c, "pages.settings.toasts.modifySettings"), err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -252,6 +266,11 @@ var testTgFunc func() error
|
|
|
// SetTestTgFunc registers the function used to test Telegram sending.
|
|
// SetTestTgFunc registers the function used to test Telegram sending.
|
|
|
func SetTestTgFunc(fn func() error) { testTgFunc = fn }
|
|
func SetTestTgFunc(fn func() error) { testTgFunc = fn }
|
|
|
|
|
|
|
|
|
|
+// reloadTgbotFunc is wired from the web layer; importing tgbot here would be a circular dependency.
|
|
|
|
|
+var reloadTgbotFunc func()
|
|
|
|
|
+
|
|
|
|
|
+func SetReloadTgbotFunc(fn func()) { reloadTgbotFunc = fn }
|
|
|
|
|
+
|
|
|
// emailService is set from web layer.
|
|
// emailService is set from web layer.
|
|
|
var emailService *email.EmailService
|
|
var emailService *email.EmailService
|
|
|
|
|
|