use client language if user language is set to system default
This commit is contained in:
@@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+2
-2
@@ -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)
|
||||
|
||||
@@ -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 ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user