@@ -821,21 +821,26 @@ func ChangeUserName(u *User, newUserName string) (err error) {
821
821
return os .Rename (UserPath (u .Name ), UserPath (newUserName ))
822
822
}
823
823
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
+
824
840
func updateUser (e Engine , u * User ) error {
825
841
// Organization does not need email
842
+ u .Email = strings .ToLower (u .Email )
826
843
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
-
839
844
if len (u .AvatarEmail ) == 0 {
840
845
u .AvatarEmail = u .Email
841
846
}
@@ -857,6 +862,16 @@ func UpdateUser(u *User) error {
857
862
return updateUser (x , u )
858
863
}
859
864
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
+
860
875
// deleteBeans deletes all given beans, beans should contain delete conditions.
861
876
func deleteBeans (e Engine , beans ... interface {}) (err error ) {
862
877
for i := range beans {
0 commit comments