Skip to content

Commit

Permalink
return error entity when verify email is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
mayswind committed Sep 10, 2023
1 parent 35ac069 commit ca14770
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/api/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.Context) (interface{}, *errs

// UserSendVerifyEmailByUnloginUserHandler sends unlogin user verify email
func (a *UsersApi) UserSendVerifyEmailByUnloginUserHandler(c *core.Context) (interface{}, *errs.Error) {
if !settings.Container.Current.EnableUserVerifyEmail {
return nil, errs.ErrEmailValidationNotAllowed
}

var userResendVerifyEmailReq models.UserResendVerifyEmailRequest
err := c.ShouldBindJSON(&userResendVerifyEmailReq)

Expand Down Expand Up @@ -462,6 +466,10 @@ func (a *UsersApi) UserSendVerifyEmailByUnloginUserHandler(c *core.Context) (int

// UserSendVerifyEmailByLoginedUserHandler sends logined user verify email
func (a *UsersApi) UserSendVerifyEmailByLoginedUserHandler(c *core.Context) (interface{}, *errs.Error) {
if !settings.Container.Current.EnableUserVerifyEmail {
return nil, errs.ErrEmailValidationNotAllowed
}

uid := c.GetCurrentUid()
user, err := a.users.GetUserById(c, uid)

Expand Down
4 changes: 4 additions & 0 deletions pkg/cli/user_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ func (l *UserDataCli) DisableUser(c *cli.Context, username string) error {

// ResendVerifyEmail resends an email with account activation link
func (l *UserDataCli) ResendVerifyEmail(c *cli.Context, username string) error {
if !settings.Container.Current.EnableUserVerifyEmail {
return errs.ErrEmailValidationNotAllowed
}

if username == "" {
log.BootErrorf("[user_data.ResendVerifyEmail] user name is empty")
return errs.ErrUsernameIsEmpty
Expand Down
1 change: 1 addition & 0 deletions pkg/errs/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ var (
ErrNewPasswordEqualsOldInvalid = NewNormalError(NormalSubcategoryUser, 19, http.StatusBadRequest, "new password equals old password")
ErrEmailIsNotVerified = NewNormalError(NormalSubcategoryUser, 20, http.StatusBadRequest, "email is not verified")
ErrEmailIsVerified = NewNormalError(NormalSubcategoryUser, 21, http.StatusBadRequest, "email is verified")
ErrEmailValidationNotAllowed = NewNormalError(NormalSubcategoryUser, 22, http.StatusBadRequest, "email validation not allowed")
)
1 change: 1 addition & 0 deletions src/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ export default {
'new password equals old password': 'New password equals old password',
'email is not verified': 'Email is not verified',
'email is verified': 'Email is verified',
'email validation not allowed': 'Email validation is not allowed',
'unauthorized access': 'Unauthorized access',
'current token is invalid': 'Current token is invalid',
'current token is expired': 'Current token is expired',
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh_Hans.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ export default {
'new password equals old password': '新密码与旧密码相同',
'email is not verified': '邮箱还未验证通过',
'email is verified': '邮箱已经验证过',
'email validation not allowed': '不允许邮箱验证',
'unauthorized access': '未授权的登录',
'current token is invalid': '当前认证令牌无效',
'current token is expired': '当前认证令牌已过期',
Expand Down

0 comments on commit ca14770

Please sign in to comment.