diff --git a/pkg/errs/database.go b/pkg/errs/database.go index b531be47..170257a2 100644 --- a/pkg/errs/database.go +++ b/pkg/errs/database.go @@ -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") ) diff --git a/pkg/services/users.go b/pkg/services/users.go index 2cdee866..5dfd8b32 100644 --- a/pkg/services/users.go +++ b/pkg/services/users.go @@ -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 } diff --git a/src/locales/en.js b/src/locales/en.js index a1df2aeb..782286fb 100644 --- a/src/locales/en.js +++ b/src/locales/en.js @@ -174,6 +174,7 @@ export default { 'error': { 'system error': 'System Error', 'api not found': 'Failed to request api', + 'database operation failed': 'Database operation failed', 'incomplete or incorrect submission': 'Incomplete or incorrect submission', 'operation failed': 'Operation failed', 'nothing will be updated': 'Nothing will be updated', diff --git a/src/locales/zh_Hans.js b/src/locales/zh_Hans.js index d2d8f976..cde4f159 100644 --- a/src/locales/zh_Hans.js +++ b/src/locales/zh_Hans.js @@ -174,6 +174,7 @@ export default { 'error': { 'system error': '系统错误', 'api not found': '接口调用失败', + 'database operation failed': '数据库操作失败', 'incomplete or incorrect submission': '提交不完整或不正确', 'operation failed': '操作失败', 'nothing will be updated': '没有内容更新',