From 03274725be17a91a067674ef9a769699a46c80f3 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 27 Aug 2023 23:02:52 +0800 Subject: [PATCH] modify text and field name --- cmd/initializer.go | 2 +- cmd/utility.go | 4 +-- conf/ezbookkeeping.ini | 10 +++--- pkg/core/token_claims.go | 2 +- pkg/errs/mail.go | 4 +-- pkg/errs/token.go | 2 +- pkg/mail/default_mailer.go | 14 ++++---- pkg/mail/mailer_container.go | 4 +-- pkg/middlewares/authorization.go | 2 +- pkg/services/base.go | 2 +- pkg/services/forget_passwords.go | 6 ++-- pkg/services/tokens.go | 2 +- pkg/settings/setting.go | 60 ++++++++++++++++---------------- src/locales/en.js | 2 +- src/locales/zh_Hans.js | 2 +- 15 files changed, 59 insertions(+), 59 deletions(-) diff --git a/cmd/initializer.go b/cmd/initializer.go index fcbf4e34..5c259e51 100644 --- a/cmd/initializer.go +++ b/cmd/initializer.go @@ -120,7 +120,7 @@ func getConfigWithoutSensitiveData(config *settings.Config) *settings.Config { } clonedConfig.DatabaseConfig.DatabasePassword = "****" - clonedConfig.SmtpConfig.SmtpPasswd = "****" + clonedConfig.SMTPConfig.SMTPPasswd = "****" clonedConfig.SecretKey = "****" return clonedConfig diff --git a/cmd/utility.go b/cmd/utility.go index feca2faf..c2f4bbd3 100644 --- a/cmd/utility.go +++ b/cmd/utility.go @@ -80,8 +80,8 @@ func sendTestMail(c *cli.Context) error { return err } - if !config.EnableSmtp || mail.Container.Current == nil { - return errs.ErrSmtpServerNotEnabled + if !config.EnableSMTP || mail.Container.Current == nil { + return errs.ErrSMTPServerNotEnabled } toAddress := c.String("to") diff --git a/conf/ezbookkeeping.ini b/conf/ezbookkeeping.ini index 7eb98f34..edccfc06 100644 --- a/conf/ezbookkeeping.ini +++ b/conf/ezbookkeeping.ini @@ -69,10 +69,10 @@ log_query = false auto_update_database = true [mail] -# Set to true to enable sending mail by smtp server +# Set to true to enable sending mail by SMTP server enable_smtp = false -# Smtp Server connection configuration +# SMTP Server connection configuration smtp_host = 127.0.0.1:25 smtp_user = smtp_passwd = @@ -112,8 +112,8 @@ token_expired_time = 2592000 # Temporary token expired seconds (0 - 4294967295), default is 300 (5 minutes) temporary_token_expired_time = 300 -# Forget password token expired seconds (0 - 4294967295), default is 3600 (60 minutes) -forget_password_token_expired_time = 3600 +# Password reset token expired seconds (0 - 4294967295), default is 3600 (60 minutes) +password_reset_token_expired_time = 3600 # Add X-Request-Id header to response to track user request or error, default is true request_id_header = true @@ -122,7 +122,7 @@ request_id_header = true # Set to true to allow users to register account by themselves enable_register = true -# Set to true to allow users to reset password by email verification code +# Set to true to allow users to reset password enable_forget_password = true # User avatar provider, supports the following types: diff --git a/pkg/core/token_claims.go b/pkg/core/token_claims.go index 7e2fef83..c41c53be 100644 --- a/pkg/core/token_claims.go +++ b/pkg/core/token_claims.go @@ -13,7 +13,7 @@ type TokenType byte const ( USER_TOKEN_TYPE_NORMAL TokenType = 1 USER_TOKEN_TYPE_REQUIRE_2FA TokenType = 2 - USER_TOKEN_TYPE_RESET_PASSWORD TokenType = 3 + USER_TOKEN_TYPE_PASSWORD_RESET TokenType = 4 ) // UserTokenClaims represents user token diff --git a/pkg/errs/mail.go b/pkg/errs/mail.go index 480d315e..c6fa9908 100644 --- a/pkg/errs/mail.go +++ b/pkg/errs/mail.go @@ -4,6 +4,6 @@ import "net/http" // Error codes related to mail var ( - ErrSmtpServerNotEnabled = NewSystemError(SystemSubcategoryMail, 0, http.StatusInternalServerError, "smtp server is not enabled") - ErrSmtpServerHostInvalid = NewSystemError(SystemSubcategoryMail, 1, http.StatusInternalServerError, "smtp server host is invalid") + ErrSMTPServerNotEnabled = NewSystemError(SystemSubcategoryMail, 0, http.StatusInternalServerError, "SMTP server is not enabled") + ErrSMTPServerHostInvalid = NewSystemError(SystemSubcategoryMail, 1, http.StatusInternalServerError, "SMTP server host is invalid") ) diff --git a/pkg/errs/token.go b/pkg/errs/token.go index 09214241..5c6728ee 100644 --- a/pkg/errs/token.go +++ b/pkg/errs/token.go @@ -19,5 +19,5 @@ var ( ErrTokenRecordNotFound = NewNormalError(NormalSubcategoryToken, 10, http.StatusBadRequest, "token is not found") ErrTokenExpired = NewNormalError(NormalSubcategoryToken, 11, http.StatusBadRequest, "token is expired") ErrTokenIsEmpty = NewNormalError(NormalSubcategoryToken, 12, http.StatusBadRequest, "token is empty") - ErrPasswordResetTokenIsInvalidOrExpired = NewNormalError(NormalSubcategoryToken, 13, http.StatusBadRequest, "password reset token is invalid or expired") + ErrPasswordResetTokenIsInvalidOrExpired = NewNormalError(NormalSubcategoryToken, 14, http.StatusBadRequest, "password reset token is invalid or expired") ) diff --git a/pkg/mail/default_mailer.go b/pkg/mail/default_mailer.go index 9d71fddd..fd4055ad 100644 --- a/pkg/mail/default_mailer.go +++ b/pkg/mail/default_mailer.go @@ -18,23 +18,23 @@ type DefaultMailer struct { } // NewDefaultMailer returns a new default mailer -func NewDefaultMailer(smtpConfig *settings.SmtpConfig) (*DefaultMailer, error) { - host, portStr, err := net.SplitHostPort(smtpConfig.SmtpHost) +func NewDefaultMailer(smtpConfig *settings.SMTPConfig) (*DefaultMailer, error) { + host, portStr, err := net.SplitHostPort(smtpConfig.SMTPHost) if err != nil { - return nil, errs.ErrSmtpServerHostInvalid + return nil, errs.ErrSMTPServerHostInvalid } port, err := utils.StringToInt(portStr) if err != nil { - return nil, errs.ErrSmtpServerHostInvalid + return nil, errs.ErrSMTPServerHostInvalid } - dialer := mail.NewDialer(host, port, smtpConfig.SmtpUser, smtpConfig.SmtpPasswd) + dialer := mail.NewDialer(host, port, smtpConfig.SMTPUser, smtpConfig.SMTPPasswd) dialer.TLSConfig = &tls.Config{ ServerName: host, - InsecureSkipVerify: smtpConfig.SmtpSkipTLSVerify, + InsecureSkipVerify: smtpConfig.SMTPSkipTLSVerify, } mailer := &DefaultMailer{ @@ -48,7 +48,7 @@ func NewDefaultMailer(smtpConfig *settings.SmtpConfig) (*DefaultMailer, error) { // SendMail sends an email according to argument func (m *DefaultMailer) SendMail(message *MailMessage) error { if m.dialer == nil { - return errs.ErrSmtpServerNotEnabled + return errs.ErrSMTPServerNotEnabled } mailMessage := mail.NewMessage() diff --git a/pkg/mail/mailer_container.go b/pkg/mail/mailer_container.go index 351a030d..db945ccb 100644 --- a/pkg/mail/mailer_container.go +++ b/pkg/mail/mailer_container.go @@ -16,12 +16,12 @@ var ( // InitializeMailer initializes the current mailer according to the config func InitializeMailer(config *settings.Config) error { - if !config.EnableSmtp { + if !config.EnableSMTP { Container.Current = nil return nil } - mailer, err := NewDefaultMailer(config.SmtpConfig) + mailer, err := NewDefaultMailer(config.SMTPConfig) if err != nil { return err diff --git a/pkg/middlewares/authorization.go b/pkg/middlewares/authorization.go index 3feb6c6f..618998a9 100644 --- a/pkg/middlewares/authorization.go +++ b/pkg/middlewares/authorization.go @@ -65,7 +65,7 @@ func JWTResetPasswordAuthorization(c *core.Context) { return } - if claims.Type != core.USER_TOKEN_TYPE_RESET_PASSWORD { + if claims.Type != core.USER_TOKEN_TYPE_PASSWORD_RESET { log.WarnfWithRequestId(c, "[authorization.JWTResetPasswordAuthorization] user \"uid:%d\" token is not for password request", claims.Uid) utils.PrintJsonErrorResult(c, errs.ErrCurrentInvalidToken) return diff --git a/pkg/services/base.go b/pkg/services/base.go index c42080e0..b81bb5d6 100644 --- a/pkg/services/base.go +++ b/pkg/services/base.go @@ -46,7 +46,7 @@ type ServiceUsingMailer struct { // SendMail sends an email according to argument func (s *ServiceUsingMailer) SendMail(message *mail.MailMessage) error { if s.container.Current == nil { - return errs.ErrSmtpServerNotEnabled + return errs.ErrSMTPServerNotEnabled } return s.container.Current.SendMail(message) diff --git a/pkg/services/forget_passwords.go b/pkg/services/forget_passwords.go index a1d7ea61..12e9111a 100644 --- a/pkg/services/forget_passwords.go +++ b/pkg/services/forget_passwords.go @@ -35,8 +35,8 @@ var ( // SendPasswordResetEmail sends password reset email according to specified parameters func (s *ForgetPasswordService) SendPasswordResetEmail(user *models.User, passwordResetToken string, backupLocale string) error { - if !s.CurrentConfig().EnableSmtp { - return errs.ErrSmtpServerNotEnabled + if !s.CurrentConfig().EnableSMTP { + return errs.ErrSMTPServerNotEnabled } locale := user.Language @@ -48,7 +48,7 @@ func (s *ForgetPasswordService) SendPasswordResetEmail(user *models.User, passwo localeTextItems := locales.GetLocaleTextItems(locale) forgetPasswordTextItems := localeTextItems.ForgetPasswordMailTextItems - expireTimeInMinutes := s.CurrentConfig().ForgetPasswordTokenExpiredTimeDuration.Minutes() + expireTimeInMinutes := s.CurrentConfig().PasswordResetTokenExpiredTimeDuration.Minutes() passwordResetUrl := fmt.Sprintf(passwordResetUrlFormat, s.CurrentConfig().RootUrl, url.QueryEscape(passwordResetToken)) tmpl, err := templates.GetTemplate("email/password_reset") diff --git a/pkg/services/tokens.go b/pkg/services/tokens.go index c4dc0aaf..94e4b837 100644 --- a/pkg/services/tokens.go +++ b/pkg/services/tokens.go @@ -90,7 +90,7 @@ func (s *TokenService) CreateRequire2FAToken(user *models.User, ctx *core.Contex // CreatePasswordResetToken generates a new password reset token and saves to database func (s *TokenService) CreatePasswordResetToken(user *models.User, ctx *core.Context) (string, *core.UserTokenClaims, error) { - return s.createToken(user, core.USER_TOKEN_TYPE_RESET_PASSWORD, s.getUserAgent(ctx), s.CurrentConfig().ForgetPasswordTokenExpiredTimeDuration) + return s.createToken(user, core.USER_TOKEN_TYPE_PASSWORD_RESET, s.getUserAgent(ctx), s.CurrentConfig().PasswordResetTokenExpiredTimeDuration) } // DeleteToken deletes given token from database diff --git a/pkg/settings/setting.go b/pkg/settings/setting.go index 85ec51f4..8aed3bfc 100644 --- a/pkg/settings/setting.go +++ b/pkg/settings/setting.go @@ -113,10 +113,10 @@ const ( defaultLogMode string = "console" defaultLoglevel Level = LOGLEVEL_INFO - defaultSecretKey string = "ezbookkeeping" - defaultTokenExpiredTime uint32 = 604800 // 7 days - defaultTemporaryTokenExpiredTime uint32 = 300 // 5 minutes - defaultForgetPasswordTokenExpiredTime uint32 = 3600 // 60 minutes + defaultSecretKey string = "ezbookkeeping" + defaultTokenExpiredTime uint32 = 604800 // 7 days + defaultTemporaryTokenExpiredTime uint32 = 300 // 5 minutes + defaultPasswordResetTokenExpiredTime uint32 = 3600 // 60 minutes defaultExchangeRatesDataRequestTimeout uint32 = 10000 // 10 seconds ) @@ -138,12 +138,12 @@ type DatabaseConfig struct { ConnectionMaxLifeTime uint32 } -// SmtpConfig represents the smtp setting config -type SmtpConfig struct { - SmtpHost string - SmtpUser string - SmtpPasswd string - SmtpSkipTLSVerify bool +// SMTPConfig represents the SMTP setting config +type SMTPConfig struct { + SMTPHost string + SMTPUser string + SMTPPasswd string + SMTPSkipTLSVerify bool FromAddress string } @@ -178,8 +178,8 @@ type Config struct { AutoUpdateDatabase bool // Mail - EnableSmtp bool - SmtpConfig *SmtpConfig + EnableSMTP bool + SMTPConfig *SMTPConfig // Log LogModes []string @@ -194,15 +194,15 @@ type Config struct { UuidServerId uint8 // Secret - SecretKey string - EnableTwoFactor bool - TokenExpiredTime uint32 - TokenExpiredTimeDuration time.Duration - TemporaryTokenExpiredTime uint32 - TemporaryTokenExpiredTimeDuration time.Duration - ForgetPasswordTokenExpiredTime uint32 - ForgetPasswordTokenExpiredTimeDuration time.Duration - EnableRequestIdHeader bool + SecretKey string + EnableTwoFactor bool + TokenExpiredTime uint32 + TokenExpiredTimeDuration time.Duration + TemporaryTokenExpiredTime uint32 + TemporaryTokenExpiredTimeDuration time.Duration + PasswordResetTokenExpiredTime uint32 + PasswordResetTokenExpiredTimeDuration time.Duration + EnableRequestIdHeader bool // User EnableUserRegister bool @@ -418,17 +418,17 @@ func loadDatabaseConfiguration(config *Config, configFile *ini.File, sectionName } func loadMailConfiguration(config *Config, configFile *ini.File, sectionName string) error { - config.EnableSmtp = getConfigItemBoolValue(configFile, sectionName, "enable_smtp", false) + config.EnableSMTP = getConfigItemBoolValue(configFile, sectionName, "enable_smtp", false) - smtpConfig := &SmtpConfig{} - smtpConfig.SmtpHost = getConfigItemStringValue(configFile, sectionName, "smtp_host") - smtpConfig.SmtpUser = getConfigItemStringValue(configFile, sectionName, "smtp_user") - smtpConfig.SmtpPasswd = getConfigItemStringValue(configFile, sectionName, "smtp_passwd") - smtpConfig.SmtpSkipTLSVerify = getConfigItemBoolValue(configFile, sectionName, "smtp_skip_tls_verify", false) + smtpConfig := &SMTPConfig{} + smtpConfig.SMTPHost = getConfigItemStringValue(configFile, sectionName, "smtp_host") + smtpConfig.SMTPUser = getConfigItemStringValue(configFile, sectionName, "smtp_user") + smtpConfig.SMTPPasswd = getConfigItemStringValue(configFile, sectionName, "smtp_passwd") + smtpConfig.SMTPSkipTLSVerify = getConfigItemBoolValue(configFile, sectionName, "smtp_skip_tls_verify", false) smtpConfig.FromAddress = getConfigItemStringValue(configFile, sectionName, "from_address") - config.SmtpConfig = smtpConfig + config.SMTPConfig = smtpConfig return nil } @@ -481,8 +481,8 @@ func loadSecurityConfiguration(config *Config, configFile *ini.File, sectionName config.TemporaryTokenExpiredTime = getConfigItemUint32Value(configFile, sectionName, "temporary_token_expired_time", defaultTemporaryTokenExpiredTime) config.TemporaryTokenExpiredTimeDuration = time.Duration(config.TemporaryTokenExpiredTime) * time.Second - config.ForgetPasswordTokenExpiredTime = getConfigItemUint32Value(configFile, sectionName, "forget_password_token_expired_time", defaultForgetPasswordTokenExpiredTime) - config.ForgetPasswordTokenExpiredTimeDuration = time.Duration(config.ForgetPasswordTokenExpiredTime) * time.Second + config.PasswordResetTokenExpiredTime = getConfigItemUint32Value(configFile, sectionName, "password_reset_token_expired_time", defaultPasswordResetTokenExpiredTime) + config.PasswordResetTokenExpiredTimeDuration = time.Duration(config.PasswordResetTokenExpiredTime) * time.Second config.EnableRequestIdHeader = getConfigItemBoolValue(configFile, sectionName, "request_id_header", true) diff --git a/src/locales/en.js b/src/locales/en.js index f5a3f6a5..4c79816e 100644 --- a/src/locales/en.js +++ b/src/locales/en.js @@ -558,7 +558,7 @@ export default { 'api not found': 'Failed to request api', 'not implemented': 'Not implemented', 'database operation failed': 'Database operation failed', - 'smtp server is not enabled': 'Smtp server is not enabled', + 'SMTP server is not enabled': 'SMTP server is not enabled', 'incomplete or incorrect submission': 'Incomplete or incorrect submission', 'operation failed': 'Operation failed', 'nothing will be updated': 'Nothing will be updated', diff --git a/src/locales/zh_Hans.js b/src/locales/zh_Hans.js index 5f29171b..c11f6ec4 100644 --- a/src/locales/zh_Hans.js +++ b/src/locales/zh_Hans.js @@ -558,7 +558,7 @@ export default { 'api not found': '接口调用失败', 'not implemented': '未实现', 'database operation failed': '数据库操作失败', - 'smtp server is not enabled': 'Smtp 服务器没有启用', + 'SMTP server is not enabled': 'SMTP 服务器没有启用', 'incomplete or incorrect submission': '提交不完整或不正确', 'operation failed': '操作失败', 'nothing will be updated': '没有内容更新',