mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-16 07:57:33 +08:00
profile page supports resending verify email
This commit is contained in:
@@ -131,7 +131,7 @@ func (a *ForgetPasswordsApi) UserResetPasswordHandler(c *core.Context) (interfac
|
||||
Password: request.Password,
|
||||
}
|
||||
|
||||
_, err = a.users.UpdateUser(c, userNew, false)
|
||||
_, _, err = a.users.UpdateUser(c, userNew, false)
|
||||
|
||||
if err != nil {
|
||||
log.ErrorfWithRequestId(c, "[forget_passwords.UserResetPasswordHandler] failed to update user \"uid:%d\", because %s", user.Uid, err.Error())
|
||||
|
||||
+5
-1
@@ -324,13 +324,17 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.Context) (interface{}, *errs
|
||||
return nil, errs.ErrNothingWillBeUpdated
|
||||
}
|
||||
|
||||
keyProfileUpdated, err := a.users.UpdateUser(c, userNew, modifyUserLanguage)
|
||||
keyProfileUpdated, emailSetToUnverified, err := a.users.UpdateUser(c, userNew, modifyUserLanguage)
|
||||
|
||||
if err != nil {
|
||||
log.ErrorfWithRequestId(c, "[users.UserUpdateProfileHandler] failed to update user \"uid:%d\", because %s", user.Uid, err.Error())
|
||||
return nil, errs.Or(err, errs.ErrOperationFailed)
|
||||
}
|
||||
|
||||
if emailSetToUnverified {
|
||||
user.EmailVerified = false
|
||||
}
|
||||
|
||||
log.InfofWithRequestId(c, "[users.UserUpdateProfileHandler] user \"uid:%d\" has updated successfully", user.Uid)
|
||||
|
||||
resp := &models.UserProfileUpdateResponse{
|
||||
|
||||
@@ -145,7 +145,7 @@ func (l *UserDataCli) ModifyUserPassword(c *cli.Context, username string, passwo
|
||||
Password: password,
|
||||
}
|
||||
|
||||
_, err = l.users.UpdateUser(nil, userNew, false)
|
||||
_, _, err = l.users.UpdateUser(nil, userNew, false)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.ModifyUserPassword] failed to update user \"%s\" password, because %s", user.Username, err.Error())
|
||||
|
||||
@@ -89,6 +89,7 @@ type UserBasicInfo struct {
|
||||
ShortDateFormat ShortDateFormat `json:"shortDateFormat"`
|
||||
LongTimeFormat LongTimeFormat `json:"longTimeFormat"`
|
||||
ShortTimeFormat ShortTimeFormat `json:"shortTimeFormat"`
|
||||
EmailVerified bool `json:"emailVerified"`
|
||||
}
|
||||
|
||||
// UserLoginRequest represents all parameters of user login request
|
||||
@@ -227,6 +228,7 @@ func (u *User) ToUserBasicInfo() *UserBasicInfo {
|
||||
ShortDateFormat: u.ShortDateFormat,
|
||||
LongTimeFormat: u.LongTimeFormat,
|
||||
ShortTimeFormat: u.ShortTimeFormat,
|
||||
EmailVerified: u.EmailVerified,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -168,29 +168,32 @@ func (s *UserService) CreateUser(c *core.Context, user *models.User) error {
|
||||
}
|
||||
|
||||
// UpdateUser saves an existed user model to database
|
||||
func (s *UserService) UpdateUser(c *core.Context, user *models.User, modifyUserLanguage bool) (keyProfileUpdated bool, err error) {
|
||||
func (s *UserService) UpdateUser(c *core.Context, user *models.User, modifyUserLanguage bool) (keyProfileUpdated bool, emailSetToUnverified bool, err error) {
|
||||
if user.Uid <= 0 {
|
||||
return false, errs.ErrUserIdInvalid
|
||||
return false, false, errs.ErrUserIdInvalid
|
||||
}
|
||||
|
||||
updateCols := make([]string, 0, 8)
|
||||
|
||||
now := time.Now().Unix()
|
||||
keyProfileUpdated = false
|
||||
emailSetToUnverified = false
|
||||
|
||||
if user.Email != "" {
|
||||
exists, err := s.ExistsEmail(c, user.Email)
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
return false, false, err
|
||||
} else if exists {
|
||||
return false, errs.ErrUserEmailAlreadyExists
|
||||
return false, false, errs.ErrUserEmailAlreadyExists
|
||||
}
|
||||
|
||||
user.EmailVerified = false
|
||||
|
||||
updateCols = append(updateCols, "email")
|
||||
updateCols = append(updateCols, "email_verified")
|
||||
|
||||
emailSetToUnverified = true
|
||||
}
|
||||
|
||||
if user.Password != "" {
|
||||
@@ -256,10 +259,10 @@ func (s *UserService) UpdateUser(c *core.Context, user *models.User, modifyUserL
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
return false, false, err
|
||||
}
|
||||
|
||||
return keyProfileUpdated, nil
|
||||
return keyProfileUpdated, emailSetToUnverified, nil
|
||||
}
|
||||
|
||||
// UpdateUserLastLoginTime updates the last login time field
|
||||
|
||||
Reference in New Issue
Block a user