modify text and field name
This commit is contained in:
+1
-1
@@ -120,7 +120,7 @@ func getConfigWithoutSensitiveData(config *settings.Config) *settings.Config {
|
||||
}
|
||||
|
||||
clonedConfig.DatabaseConfig.DatabasePassword = "****"
|
||||
clonedConfig.SmtpConfig.SmtpPasswd = "****"
|
||||
clonedConfig.SMTPConfig.SMTPPasswd = "****"
|
||||
clonedConfig.SecretKey = "****"
|
||||
|
||||
return clonedConfig
|
||||
|
||||
+2
-2
@@ -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")
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
@@ -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
@@ -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")
|
||||
)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
+20
-20
@@ -116,7 +116,7 @@ const (
|
||||
defaultSecretKey string = "ezbookkeeping"
|
||||
defaultTokenExpiredTime uint32 = 604800 // 7 days
|
||||
defaultTemporaryTokenExpiredTime uint32 = 300 // 5 minutes
|
||||
defaultForgetPasswordTokenExpiredTime uint32 = 3600 // 60 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
|
||||
@@ -200,8 +200,8 @@ type Config struct {
|
||||
TokenExpiredTimeDuration time.Duration
|
||||
TemporaryTokenExpiredTime uint32
|
||||
TemporaryTokenExpiredTimeDuration time.Duration
|
||||
ForgetPasswordTokenExpiredTime uint32
|
||||
ForgetPasswordTokenExpiredTimeDuration time.Duration
|
||||
PasswordResetTokenExpiredTime uint32
|
||||
PasswordResetTokenExpiredTimeDuration time.Duration
|
||||
EnableRequestIdHeader bool
|
||||
|
||||
// User
|
||||
@@ -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)
|
||||
|
||||
|
||||
+1
-1
@@ -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',
|
||||
|
||||
@@ -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': '没有内容更新',
|
||||
|
||||
Reference in New Issue
Block a user