modify text and field name

This commit is contained in:
MaysWind
2023-08-27 23:02:52 +08:00
parent 0951006063
commit 03274725be
15 changed files with 59 additions and 59 deletions
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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")
)
+1 -1
View File
@@ -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")
)
+7 -7
View File
@@ -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()
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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)
+3 -3
View File
@@ -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")
+1 -1
View File
@@ -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
+30 -30
View File
@@ -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)