From a4849fa4f02e5eb65215c192576f751e46d3722b Mon Sep 17 00:00:00 2001 From: MaysWind Date: Thu, 8 Aug 2024 22:29:01 +0800 Subject: [PATCH] add notification when user registers --- conf/ezbookkeeping.ini | 10 ++++++++-- pkg/api/users.go | 2 +- pkg/settings/setting.go | 6 ++++-- pkg/settings/setting_container.go | 19 +++++++++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/conf/ezbookkeeping.ini b/conf/ezbookkeeping.ini index cd16d905..0e529f11 100644 --- a/conf/ezbookkeeping.ini +++ b/conf/ezbookkeeping.ini @@ -203,12 +203,18 @@ avatar_provider = internal enable_export = true [notification] +# Set to true to display custom notification in home page every time users register +enable_notification_after_register = false + +# The notification content displayed each time users register, it supports multi-language configuration +# Add an underscore and a language tag after the setting key to configure the notification content in that language, the same below +# For example, after_login_notification_content_zh_hans means the notification content in Simplified Chinese +after_register_notification_content = + # Set to true to display custom notification in home page every time users login enable_notification_after_login = false # The notification content displayed each time users log in, it supports multi-language configuration -# Add an underscore and a language tag after the setting key to configure the notification content in that language, the same below -# For example, after_login_notification_content_zh_hans means the notification content in Simplified Chinese after_login_notification_content = # Set to true to display custom notification in home page every time users open the app diff --git a/pkg/api/users.go b/pkg/api/users.go index c7d55269..e34614ec 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, c.GetClientLocale()), + NotificationContent: settings.Container.GetAfterRegisterNotificationContent(user.Language, c.GetClientLocale()), }, NeedVerifyEmail: settings.Container.Current.EnableUserVerifyEmail && settings.Container.Current.EnableUserForceVerifyEmail, PresetCategoriesSaved: presetCategoriesSaved, diff --git a/pkg/settings/setting.go b/pkg/settings/setting.go index df187af5..908da7d2 100644 --- a/pkg/settings/setting.go +++ b/pkg/settings/setting.go @@ -279,8 +279,9 @@ type Config struct { EnableDataExport bool // Notification - AfterLoginNotification NotificationConfig - AfterOpenNotification NotificationConfig + AfterRegisterNotification NotificationConfig + AfterLoginNotification NotificationConfig + AfterOpenNotification NotificationConfig // Map MapProvider string @@ -748,6 +749,7 @@ func loadDataConfiguration(config *Config, configFile *ini.File, sectionName str } func loadNotificationConfiguration(config *Config, configFile *ini.File, sectionName string) error { + config.AfterRegisterNotification = getNotificationConfiguration(configFile, sectionName, "enable_notification_after_register", "after_register_notification_content") config.AfterLoginNotification = getNotificationConfiguration(configFile, sectionName, "enable_notification_after_login", "after_login_notification_content") config.AfterOpenNotification = getNotificationConfiguration(configFile, sectionName, "enable_notification_after_open", "after_open_notification_content") diff --git a/pkg/settings/setting_container.go b/pkg/settings/setting_container.go index 15f2232e..be8a0388 100644 --- a/pkg/settings/setting_container.go +++ b/pkg/settings/setting_container.go @@ -17,6 +17,25 @@ func SetCurrentConfig(config *Config) { Container.Current = config } +// GetAfterRegisterNotificationContent returns the notification content displayed each time users register +func (c *ConfigContainer) GetAfterRegisterNotificationContent(userLanguage string, clientLanguage string) string { + language := userLanguage + + if language == "" { + language = clientLanguage + } + + if !c.Current.AfterRegisterNotification.Enabled { + return "" + } + + if multiLanguageContent, exists := c.Current.AfterRegisterNotification.MultiLanguageContent[language]; exists { + return multiLanguageContent + } + + return c.Current.AfterRegisterNotification.DefaultContent +} + // GetAfterLoginNotificationContent returns the notification content displayed each time users log in func (c *ConfigContainer) GetAfterLoginNotificationContent(userLanguage string, clientLanguage string) string { language := userLanguage