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.DatabaseConfig.DatabasePassword = "****"
|
||||||
clonedConfig.SmtpConfig.SmtpPasswd = "****"
|
clonedConfig.SMTPConfig.SMTPPasswd = "****"
|
||||||
clonedConfig.SecretKey = "****"
|
clonedConfig.SecretKey = "****"
|
||||||
|
|
||||||
return clonedConfig
|
return clonedConfig
|
||||||
|
|||||||
+2
-2
@@ -80,8 +80,8 @@ func sendTestMail(c *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !config.EnableSmtp || mail.Container.Current == nil {
|
if !config.EnableSMTP || mail.Container.Current == nil {
|
||||||
return errs.ErrSmtpServerNotEnabled
|
return errs.ErrSMTPServerNotEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
toAddress := c.String("to")
|
toAddress := c.String("to")
|
||||||
|
|||||||
@@ -69,10 +69,10 @@ log_query = false
|
|||||||
auto_update_database = true
|
auto_update_database = true
|
||||||
|
|
||||||
[mail]
|
[mail]
|
||||||
# Set to true to enable sending mail by smtp server
|
# Set to true to enable sending mail by SMTP server
|
||||||
enable_smtp = false
|
enable_smtp = false
|
||||||
|
|
||||||
# Smtp Server connection configuration
|
# SMTP Server connection configuration
|
||||||
smtp_host = 127.0.0.1:25
|
smtp_host = 127.0.0.1:25
|
||||||
smtp_user =
|
smtp_user =
|
||||||
smtp_passwd =
|
smtp_passwd =
|
||||||
@@ -112,8 +112,8 @@ token_expired_time = 2592000
|
|||||||
# Temporary token expired seconds (0 - 4294967295), default is 300 (5 minutes)
|
# Temporary token expired seconds (0 - 4294967295), default is 300 (5 minutes)
|
||||||
temporary_token_expired_time = 300
|
temporary_token_expired_time = 300
|
||||||
|
|
||||||
# Forget password token expired seconds (0 - 4294967295), default is 3600 (60 minutes)
|
# Password reset token expired seconds (0 - 4294967295), default is 3600 (60 minutes)
|
||||||
forget_password_token_expired_time = 3600
|
password_reset_token_expired_time = 3600
|
||||||
|
|
||||||
# Add X-Request-Id header to response to track user request or error, default is true
|
# Add X-Request-Id header to response to track user request or error, default is true
|
||||||
request_id_header = true
|
request_id_header = true
|
||||||
@@ -122,7 +122,7 @@ request_id_header = true
|
|||||||
# Set to true to allow users to register account by themselves
|
# Set to true to allow users to register account by themselves
|
||||||
enable_register = true
|
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
|
enable_forget_password = true
|
||||||
|
|
||||||
# User avatar provider, supports the following types:
|
# User avatar provider, supports the following types:
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ type TokenType byte
|
|||||||
const (
|
const (
|
||||||
USER_TOKEN_TYPE_NORMAL TokenType = 1
|
USER_TOKEN_TYPE_NORMAL TokenType = 1
|
||||||
USER_TOKEN_TYPE_REQUIRE_2FA TokenType = 2
|
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
|
// UserTokenClaims represents user token
|
||||||
|
|||||||
+2
-2
@@ -4,6 +4,6 @@ import "net/http"
|
|||||||
|
|
||||||
// Error codes related to mail
|
// Error codes related to mail
|
||||||
var (
|
var (
|
||||||
ErrSmtpServerNotEnabled = NewSystemError(SystemSubcategoryMail, 0, http.StatusInternalServerError, "smtp server is not enabled")
|
ErrSMTPServerNotEnabled = NewSystemError(SystemSubcategoryMail, 0, http.StatusInternalServerError, "SMTP server is not enabled")
|
||||||
ErrSmtpServerHostInvalid = NewSystemError(SystemSubcategoryMail, 1, http.StatusInternalServerError, "smtp server host is invalid")
|
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")
|
ErrTokenRecordNotFound = NewNormalError(NormalSubcategoryToken, 10, http.StatusBadRequest, "token is not found")
|
||||||
ErrTokenExpired = NewNormalError(NormalSubcategoryToken, 11, http.StatusBadRequest, "token is expired")
|
ErrTokenExpired = NewNormalError(NormalSubcategoryToken, 11, http.StatusBadRequest, "token is expired")
|
||||||
ErrTokenIsEmpty = NewNormalError(NormalSubcategoryToken, 12, http.StatusBadRequest, "token is empty")
|
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
|
// NewDefaultMailer returns a new default mailer
|
||||||
func NewDefaultMailer(smtpConfig *settings.SmtpConfig) (*DefaultMailer, error) {
|
func NewDefaultMailer(smtpConfig *settings.SMTPConfig) (*DefaultMailer, error) {
|
||||||
host, portStr, err := net.SplitHostPort(smtpConfig.SmtpHost)
|
host, portStr, err := net.SplitHostPort(smtpConfig.SMTPHost)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errs.ErrSmtpServerHostInvalid
|
return nil, errs.ErrSMTPServerHostInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
port, err := utils.StringToInt(portStr)
|
port, err := utils.StringToInt(portStr)
|
||||||
|
|
||||||
if err != nil {
|
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{
|
dialer.TLSConfig = &tls.Config{
|
||||||
ServerName: host,
|
ServerName: host,
|
||||||
InsecureSkipVerify: smtpConfig.SmtpSkipTLSVerify,
|
InsecureSkipVerify: smtpConfig.SMTPSkipTLSVerify,
|
||||||
}
|
}
|
||||||
|
|
||||||
mailer := &DefaultMailer{
|
mailer := &DefaultMailer{
|
||||||
@@ -48,7 +48,7 @@ func NewDefaultMailer(smtpConfig *settings.SmtpConfig) (*DefaultMailer, error) {
|
|||||||
// SendMail sends an email according to argument
|
// SendMail sends an email according to argument
|
||||||
func (m *DefaultMailer) SendMail(message *MailMessage) error {
|
func (m *DefaultMailer) SendMail(message *MailMessage) error {
|
||||||
if m.dialer == nil {
|
if m.dialer == nil {
|
||||||
return errs.ErrSmtpServerNotEnabled
|
return errs.ErrSMTPServerNotEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
mailMessage := mail.NewMessage()
|
mailMessage := mail.NewMessage()
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ var (
|
|||||||
|
|
||||||
// InitializeMailer initializes the current mailer according to the config
|
// InitializeMailer initializes the current mailer according to the config
|
||||||
func InitializeMailer(config *settings.Config) error {
|
func InitializeMailer(config *settings.Config) error {
|
||||||
if !config.EnableSmtp {
|
if !config.EnableSMTP {
|
||||||
Container.Current = nil
|
Container.Current = nil
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
mailer, err := NewDefaultMailer(config.SmtpConfig)
|
mailer, err := NewDefaultMailer(config.SMTPConfig)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ func JWTResetPasswordAuthorization(c *core.Context) {
|
|||||||
return
|
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)
|
log.WarnfWithRequestId(c, "[authorization.JWTResetPasswordAuthorization] user \"uid:%d\" token is not for password request", claims.Uid)
|
||||||
utils.PrintJsonErrorResult(c, errs.ErrCurrentInvalidToken)
|
utils.PrintJsonErrorResult(c, errs.ErrCurrentInvalidToken)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ type ServiceUsingMailer struct {
|
|||||||
// SendMail sends an email according to argument
|
// SendMail sends an email according to argument
|
||||||
func (s *ServiceUsingMailer) SendMail(message *mail.MailMessage) error {
|
func (s *ServiceUsingMailer) SendMail(message *mail.MailMessage) error {
|
||||||
if s.container.Current == nil {
|
if s.container.Current == nil {
|
||||||
return errs.ErrSmtpServerNotEnabled
|
return errs.ErrSMTPServerNotEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.container.Current.SendMail(message)
|
return s.container.Current.SendMail(message)
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ var (
|
|||||||
|
|
||||||
// SendPasswordResetEmail sends password reset email according to specified parameters
|
// SendPasswordResetEmail sends password reset email according to specified parameters
|
||||||
func (s *ForgetPasswordService) SendPasswordResetEmail(user *models.User, passwordResetToken string, backupLocale string) error {
|
func (s *ForgetPasswordService) SendPasswordResetEmail(user *models.User, passwordResetToken string, backupLocale string) error {
|
||||||
if !s.CurrentConfig().EnableSmtp {
|
if !s.CurrentConfig().EnableSMTP {
|
||||||
return errs.ErrSmtpServerNotEnabled
|
return errs.ErrSMTPServerNotEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
locale := user.Language
|
locale := user.Language
|
||||||
@@ -48,7 +48,7 @@ func (s *ForgetPasswordService) SendPasswordResetEmail(user *models.User, passwo
|
|||||||
localeTextItems := locales.GetLocaleTextItems(locale)
|
localeTextItems := locales.GetLocaleTextItems(locale)
|
||||||
forgetPasswordTextItems := localeTextItems.ForgetPasswordMailTextItems
|
forgetPasswordTextItems := localeTextItems.ForgetPasswordMailTextItems
|
||||||
|
|
||||||
expireTimeInMinutes := s.CurrentConfig().ForgetPasswordTokenExpiredTimeDuration.Minutes()
|
expireTimeInMinutes := s.CurrentConfig().PasswordResetTokenExpiredTimeDuration.Minutes()
|
||||||
passwordResetUrl := fmt.Sprintf(passwordResetUrlFormat, s.CurrentConfig().RootUrl, url.QueryEscape(passwordResetToken))
|
passwordResetUrl := fmt.Sprintf(passwordResetUrlFormat, s.CurrentConfig().RootUrl, url.QueryEscape(passwordResetToken))
|
||||||
|
|
||||||
tmpl, err := templates.GetTemplate("email/password_reset")
|
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
|
// 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) {
|
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
|
// DeleteToken deletes given token from database
|
||||||
|
|||||||
+30
-30
@@ -113,10 +113,10 @@ const (
|
|||||||
defaultLogMode string = "console"
|
defaultLogMode string = "console"
|
||||||
defaultLoglevel Level = LOGLEVEL_INFO
|
defaultLoglevel Level = LOGLEVEL_INFO
|
||||||
|
|
||||||
defaultSecretKey string = "ezbookkeeping"
|
defaultSecretKey string = "ezbookkeeping"
|
||||||
defaultTokenExpiredTime uint32 = 604800 // 7 days
|
defaultTokenExpiredTime uint32 = 604800 // 7 days
|
||||||
defaultTemporaryTokenExpiredTime uint32 = 300 // 5 minutes
|
defaultTemporaryTokenExpiredTime uint32 = 300 // 5 minutes
|
||||||
defaultForgetPasswordTokenExpiredTime uint32 = 3600 // 60 minutes
|
defaultPasswordResetTokenExpiredTime uint32 = 3600 // 60 minutes
|
||||||
|
|
||||||
defaultExchangeRatesDataRequestTimeout uint32 = 10000 // 10 seconds
|
defaultExchangeRatesDataRequestTimeout uint32 = 10000 // 10 seconds
|
||||||
)
|
)
|
||||||
@@ -138,12 +138,12 @@ type DatabaseConfig struct {
|
|||||||
ConnectionMaxLifeTime uint32
|
ConnectionMaxLifeTime uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
// SmtpConfig represents the smtp setting config
|
// SMTPConfig represents the SMTP setting config
|
||||||
type SmtpConfig struct {
|
type SMTPConfig struct {
|
||||||
SmtpHost string
|
SMTPHost string
|
||||||
SmtpUser string
|
SMTPUser string
|
||||||
SmtpPasswd string
|
SMTPPasswd string
|
||||||
SmtpSkipTLSVerify bool
|
SMTPSkipTLSVerify bool
|
||||||
FromAddress string
|
FromAddress string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,8 +178,8 @@ type Config struct {
|
|||||||
AutoUpdateDatabase bool
|
AutoUpdateDatabase bool
|
||||||
|
|
||||||
// Mail
|
// Mail
|
||||||
EnableSmtp bool
|
EnableSMTP bool
|
||||||
SmtpConfig *SmtpConfig
|
SMTPConfig *SMTPConfig
|
||||||
|
|
||||||
// Log
|
// Log
|
||||||
LogModes []string
|
LogModes []string
|
||||||
@@ -194,15 +194,15 @@ type Config struct {
|
|||||||
UuidServerId uint8
|
UuidServerId uint8
|
||||||
|
|
||||||
// Secret
|
// Secret
|
||||||
SecretKey string
|
SecretKey string
|
||||||
EnableTwoFactor bool
|
EnableTwoFactor bool
|
||||||
TokenExpiredTime uint32
|
TokenExpiredTime uint32
|
||||||
TokenExpiredTimeDuration time.Duration
|
TokenExpiredTimeDuration time.Duration
|
||||||
TemporaryTokenExpiredTime uint32
|
TemporaryTokenExpiredTime uint32
|
||||||
TemporaryTokenExpiredTimeDuration time.Duration
|
TemporaryTokenExpiredTimeDuration time.Duration
|
||||||
ForgetPasswordTokenExpiredTime uint32
|
PasswordResetTokenExpiredTime uint32
|
||||||
ForgetPasswordTokenExpiredTimeDuration time.Duration
|
PasswordResetTokenExpiredTimeDuration time.Duration
|
||||||
EnableRequestIdHeader bool
|
EnableRequestIdHeader bool
|
||||||
|
|
||||||
// User
|
// User
|
||||||
EnableUserRegister bool
|
EnableUserRegister bool
|
||||||
@@ -418,17 +418,17 @@ func loadDatabaseConfiguration(config *Config, configFile *ini.File, sectionName
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadMailConfiguration(config *Config, configFile *ini.File, sectionName string) error {
|
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 := &SMTPConfig{}
|
||||||
smtpConfig.SmtpHost = getConfigItemStringValue(configFile, sectionName, "smtp_host")
|
smtpConfig.SMTPHost = getConfigItemStringValue(configFile, sectionName, "smtp_host")
|
||||||
smtpConfig.SmtpUser = getConfigItemStringValue(configFile, sectionName, "smtp_user")
|
smtpConfig.SMTPUser = getConfigItemStringValue(configFile, sectionName, "smtp_user")
|
||||||
smtpConfig.SmtpPasswd = getConfigItemStringValue(configFile, sectionName, "smtp_passwd")
|
smtpConfig.SMTPPasswd = getConfigItemStringValue(configFile, sectionName, "smtp_passwd")
|
||||||
smtpConfig.SmtpSkipTLSVerify = getConfigItemBoolValue(configFile, sectionName, "smtp_skip_tls_verify", false)
|
smtpConfig.SMTPSkipTLSVerify = getConfigItemBoolValue(configFile, sectionName, "smtp_skip_tls_verify", false)
|
||||||
|
|
||||||
smtpConfig.FromAddress = getConfigItemStringValue(configFile, sectionName, "from_address")
|
smtpConfig.FromAddress = getConfigItemStringValue(configFile, sectionName, "from_address")
|
||||||
|
|
||||||
config.SmtpConfig = smtpConfig
|
config.SMTPConfig = smtpConfig
|
||||||
|
|
||||||
return nil
|
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.TemporaryTokenExpiredTime = getConfigItemUint32Value(configFile, sectionName, "temporary_token_expired_time", defaultTemporaryTokenExpiredTime)
|
||||||
config.TemporaryTokenExpiredTimeDuration = time.Duration(config.TemporaryTokenExpiredTime) * time.Second
|
config.TemporaryTokenExpiredTimeDuration = time.Duration(config.TemporaryTokenExpiredTime) * time.Second
|
||||||
|
|
||||||
config.ForgetPasswordTokenExpiredTime = getConfigItemUint32Value(configFile, sectionName, "forget_password_token_expired_time", defaultForgetPasswordTokenExpiredTime)
|
config.PasswordResetTokenExpiredTime = getConfigItemUint32Value(configFile, sectionName, "password_reset_token_expired_time", defaultPasswordResetTokenExpiredTime)
|
||||||
config.ForgetPasswordTokenExpiredTimeDuration = time.Duration(config.ForgetPasswordTokenExpiredTime) * time.Second
|
config.PasswordResetTokenExpiredTimeDuration = time.Duration(config.PasswordResetTokenExpiredTime) * time.Second
|
||||||
|
|
||||||
config.EnableRequestIdHeader = getConfigItemBoolValue(configFile, sectionName, "request_id_header", true)
|
config.EnableRequestIdHeader = getConfigItemBoolValue(configFile, sectionName, "request_id_header", true)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -558,7 +558,7 @@ export default {
|
|||||||
'api not found': 'Failed to request api',
|
'api not found': 'Failed to request api',
|
||||||
'not implemented': 'Not implemented',
|
'not implemented': 'Not implemented',
|
||||||
'database operation failed': 'Database operation failed',
|
'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',
|
'incomplete or incorrect submission': 'Incomplete or incorrect submission',
|
||||||
'operation failed': 'Operation failed',
|
'operation failed': 'Operation failed',
|
||||||
'nothing will be updated': 'Nothing will be updated',
|
'nothing will be updated': 'Nothing will be updated',
|
||||||
|
|||||||
@@ -558,7 +558,7 @@ export default {
|
|||||||
'api not found': '接口调用失败',
|
'api not found': '接口调用失败',
|
||||||
'not implemented': '未实现',
|
'not implemented': '未实现',
|
||||||
'database operation failed': '数据库操作失败',
|
'database operation failed': '数据库操作失败',
|
||||||
'smtp server is not enabled': 'Smtp 服务器没有启用',
|
'SMTP server is not enabled': 'SMTP 服务器没有启用',
|
||||||
'incomplete or incorrect submission': '提交不完整或不正确',
|
'incomplete or incorrect submission': '提交不完整或不正确',
|
||||||
'operation failed': '操作失败',
|
'operation failed': '操作失败',
|
||||||
'nothing will be updated': '没有内容更新',
|
'nothing will be updated': '没有内容更新',
|
||||||
|
|||||||
Reference in New Issue
Block a user