mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-17 16:24:25 +08:00
fix toast message is wrong when modify email to an existed one
This commit is contained in:
@@ -5,7 +5,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrDatabaseTypeInvalid = NewSystemError(SYSTEM_SUBCATEGORY_DATABASE, 0, http.StatusInternalServerError, "database type is invalid")
|
||||
ErrDatabaseHostInvalid = NewSystemError(SYSTEM_SUBCATEGORY_DATABASE, 1, http.StatusInternalServerError, "database host is invalid")
|
||||
ErrDatabaseIsNull = NewSystemError(SYSTEM_SUBCATEGORY_DATABASE, 2, http.StatusInternalServerError, "database cannot be null")
|
||||
ErrDatabaseTypeInvalid = NewSystemError(SYSTEM_SUBCATEGORY_DATABASE, 0, http.StatusInternalServerError, "database type is invalid")
|
||||
ErrDatabaseHostInvalid = NewSystemError(SYSTEM_SUBCATEGORY_DATABASE, 1, http.StatusInternalServerError, "database host is invalid")
|
||||
ErrDatabaseIsNull = NewSystemError(SYSTEM_SUBCATEGORY_DATABASE, 2, http.StatusInternalServerError, "database cannot be null")
|
||||
ErrDatabaseOperationFailed = NewSystemError(SYSTEM_SUBCATEGORY_DATABASE, 3, http.StatusInternalServerError, "database operation failed")
|
||||
)
|
||||
|
||||
@@ -157,6 +157,14 @@ func (s *UserService) UpdateUser(user *models.User) (keyProfileUpdated bool, err
|
||||
keyProfileUpdated = false
|
||||
|
||||
if user.Email != "" {
|
||||
exists, err := s.ExistsEmail(user.Email)
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
} else if exists {
|
||||
return false, errs.ErrUserEmailAlreadyExists
|
||||
}
|
||||
|
||||
user.EmailVerified = false
|
||||
|
||||
updateCols = append(updateCols, "email")
|
||||
@@ -184,6 +192,10 @@ func (s *UserService) UpdateUser(user *models.User) (keyProfileUpdated bool, err
|
||||
err = s.UserDB().DoTransaction(func(sess *xorm.Session) error {
|
||||
updatedRows, err := sess.ID(user.Uid).Where("deleted=?", false).Cols(updateCols...).Update(user)
|
||||
|
||||
if err != nil {
|
||||
return errs.ErrDatabaseOperationFailed
|
||||
}
|
||||
|
||||
if updatedRows < 1 {
|
||||
return errs.ErrUserNotFound
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user