diff --git a/pkg/api/authorizations.go b/pkg/api/authorizations.go index cd73253e..1abf574a 100644 --- a/pkg/api/authorizations.go +++ b/pkg/api/authorizations.go @@ -104,7 +104,7 @@ func (a *AuthorizationsApi) AuthorizeHandler(c *core.Context) (any, *errs.Error) log.InfofWithRequestId(c, "[authorizations.AuthorizeHandler] user \"uid:%d\" has logined, token type is %d, token will be expired at %d", user.Uid, claims.Type, claims.ExpiresAt) - authResp := a.getAuthResponse(token, twoFactorEnable, user) + authResp := a.getAuthResponse(c, token, twoFactorEnable, user) return authResp, nil } @@ -167,7 +167,7 @@ func (a *AuthorizationsApi) TwoFactorAuthorizeHandler(c *core.Context) (any, *er log.InfofWithRequestId(c, "[authorizations.TwoFactorAuthorizeHandler] user \"uid:%d\" has authorized two-factor via passcode, token will be expired at %d", user.Uid, claims.ExpiresAt) - authResp := a.getAuthResponse(token, false, user) + authResp := a.getAuthResponse(c, token, false, user) return authResp, nil } @@ -236,15 +236,15 @@ func (a *AuthorizationsApi) TwoFactorAuthorizeByRecoveryCodeHandler(c *core.Cont log.InfofWithRequestId(c, "[authorizations.TwoFactorAuthorizeByRecoveryCodeHandler] user \"uid:%d\" has authorized two-factor via recovery code \"%s\", token will be expired at %d", user.Uid, credential.RecoveryCode, claims.ExpiresAt) - authResp := a.getAuthResponse(token, false, user) + authResp := a.getAuthResponse(c, token, false, user) return authResp, nil } -func (a *AuthorizationsApi) getAuthResponse(token string, need2FA bool, user *models.User) *models.AuthResponse { +func (a *AuthorizationsApi) getAuthResponse(c *core.Context, token string, need2FA bool, user *models.User) *models.AuthResponse { return &models.AuthResponse{ Token: token, Need2FA: need2FA, User: user.ToUserBasicInfo(), - NotificationContent: settings.Container.GetAfterLoginNotificationContent(user.Language), + NotificationContent: settings.Container.GetAfterLoginNotificationContent(user.Language, c.GetClientLocale()), } } diff --git a/pkg/api/tokens.go b/pkg/api/tokens.go index e679d09a..863bd245 100644 --- a/pkg/api/tokens.go +++ b/pkg/api/tokens.go @@ -205,7 +205,7 @@ func (a *TokensApi) TokenRefreshHandler(c *core.Context) (any, *errs.Error) { refreshResp := &models.TokenRefreshResponse{ User: user.ToUserBasicInfo(), - NotificationContent: settings.Container.GetAfterOpenNotificationContent(user.Language), + NotificationContent: settings.Container.GetAfterOpenNotificationContent(user.Language, c.GetClientLocale()), } return refreshResp, nil @@ -234,7 +234,7 @@ func (a *TokensApi) TokenRefreshHandler(c *core.Context) (any, *errs.Error) { NewToken: token, OldTokenId: a.tokens.GenerateTokenId(oldTokenRecord), User: user.ToUserBasicInfo(), - NotificationContent: settings.Container.GetAfterOpenNotificationContent(user.Language), + NotificationContent: settings.Container.GetAfterOpenNotificationContent(user.Language, c.GetClientLocale()), } return refreshResp, nil diff --git a/pkg/api/users.go b/pkg/api/users.go index 78ae9617..c7d55269 100644 --- a/pkg/api/users.go +++ b/pkg/api/users.go @@ -93,7 +93,7 @@ func (a *UsersApi) UserRegisterHandler(c *core.Context) (any, *errs.Error) { AuthResponse: models.AuthResponse{ Need2FA: false, User: user.ToUserBasicInfo(), - NotificationContent: settings.Container.GetAfterLoginNotificationContent(user.Language), + NotificationContent: settings.Container.GetAfterLoginNotificationContent(user.Language, c.GetClientLocale()), }, NeedVerifyEmail: settings.Container.Current.EnableUserVerifyEmail && settings.Container.Current.EnableUserForceVerifyEmail, PresetCategoriesSaved: presetCategoriesSaved, @@ -188,7 +188,7 @@ func (a *UsersApi) UserEmailVerifyHandler(c *core.Context) (any, *errs.Error) { resp.NewToken = token resp.User = user.ToUserBasicInfo() - resp.NotificationContent = settings.Container.GetAfterLoginNotificationContent(user.Language) + resp.NotificationContent = settings.Container.GetAfterLoginNotificationContent(user.Language, c.GetClientLocale()) c.SetTextualToken(token) c.SetTokenClaims(claims) diff --git a/pkg/settings/setting_container.go b/pkg/settings/setting_container.go index b19a38ec..15f2232e 100644 --- a/pkg/settings/setting_container.go +++ b/pkg/settings/setting_container.go @@ -18,7 +18,13 @@ func SetCurrentConfig(config *Config) { } // GetAfterLoginNotificationContent returns the notification content displayed each time users log in -func (c *ConfigContainer) GetAfterLoginNotificationContent(language string) string { +func (c *ConfigContainer) GetAfterLoginNotificationContent(userLanguage string, clientLanguage string) string { + language := userLanguage + + if language == "" { + language = clientLanguage + } + if !c.Current.AfterLoginNotification.Enabled { return "" } @@ -31,7 +37,13 @@ func (c *ConfigContainer) GetAfterLoginNotificationContent(language string) stri } // GetAfterOpenNotificationContent returns the notification content displayed each time users open the app -func (c *ConfigContainer) GetAfterOpenNotificationContent(language string) string { +func (c *ConfigContainer) GetAfterOpenNotificationContent(userLanguage string, clientLanguage string) string { + language := userLanguage + + if language == "" { + language = clientLanguage + } + if !c.Current.AfterOpenNotification.Enabled { return "" }