@@ -821,21 +821,26 @@ func ChangeUserName(u *User, newUserName string) (err error) {
821821 return os .Rename (UserPath (u .Name ), UserPath (newUserName ))
822822}
823823
824+ // checkDupEmail checks whether there are the same email with the user
825+ func checkDupEmail (e Engine , u * User ) error {
826+ u .Email = strings .ToLower (u .Email )
827+ has , err := e .
828+ Where ("id!=?" , u .ID ).
829+ And ("type=?" , u .Type ).
830+ And ("email=?" , u .Email ).
831+ Get (new (User ))
832+ if err != nil {
833+ return err
834+ } else if has {
835+ return ErrEmailAlreadyUsed {u .Email }
836+ }
837+ return nil
838+ }
839+
824840func updateUser (e Engine , u * User ) error {
825841 // Organization does not need email
842+ u .Email = strings .ToLower (u .Email )
826843 if ! u .IsOrganization () {
827- u .Email = strings .ToLower (u .Email )
828- has , err := e .
829- Where ("id!=?" , u .ID ).
830- And ("type=?" , u .Type ).
831- And ("email=?" , u .Email ).
832- Get (new (User ))
833- if err != nil {
834- return err
835- } else if has {
836- return ErrEmailAlreadyUsed {u .Email }
837- }
838-
839844 if len (u .AvatarEmail ) == 0 {
840845 u .AvatarEmail = u .Email
841846 }
@@ -857,6 +862,16 @@ func UpdateUser(u *User) error {
857862 return updateUser (x , u )
858863}
859864
865+ // UpdateUserSetting updates user's settings.
866+ func UpdateUserSetting (u * User ) error {
867+ if ! u .IsOrganization () {
868+ if err := checkDupEmail (x , u ); err != nil {
869+ return err
870+ }
871+ }
872+ return updateUser (x , u )
873+ }
874+
860875// deleteBeans deletes all given beans, beans should contain delete conditions.
861876func deleteBeans (e Engine , beans ... interface {}) (err error ) {
862877 for i := range beans {
0 commit comments