|
|
@ -821,9 +821,8 @@ func ChangeUserName(u *User, newUserName string) (err error) { |
|
|
|
return os.Rename(UserPath(u.Name), UserPath(newUserName)) |
|
|
|
return os.Rename(UserPath(u.Name), UserPath(newUserName)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func updateUser(e Engine, u *User) error { |
|
|
|
// checkDupEmail checks whether there are the same email with the user
|
|
|
|
// Organization does not need email
|
|
|
|
func checkDupEmail(e Engine, u *User) error { |
|
|
|
if !u.IsOrganization() { |
|
|
|
|
|
|
|
u.Email = strings.ToLower(u.Email) |
|
|
|
u.Email = strings.ToLower(u.Email) |
|
|
|
has, err := e. |
|
|
|
has, err := e. |
|
|
|
Where("id!=?", u.ID). |
|
|
|
Where("id!=?", u.ID). |
|
|
@ -835,7 +834,13 @@ func updateUser(e Engine, u *User) error { |
|
|
|
} else if has { |
|
|
|
} else if has { |
|
|
|
return ErrEmailAlreadyUsed{u.Email} |
|
|
|
return ErrEmailAlreadyUsed{u.Email} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func updateUser(e Engine, u *User) error { |
|
|
|
|
|
|
|
// Organization does not need email
|
|
|
|
|
|
|
|
u.Email = strings.ToLower(u.Email) |
|
|
|
|
|
|
|
if !u.IsOrganization() { |
|
|
|
if len(u.AvatarEmail) == 0 { |
|
|
|
if len(u.AvatarEmail) == 0 { |
|
|
|
u.AvatarEmail = u.Email |
|
|
|
u.AvatarEmail = u.Email |
|
|
|
} |
|
|
|
} |
|
|
@ -857,6 +862,16 @@ func UpdateUser(u *User) error { |
|
|
|
return updateUser(x, u) |
|
|
|
return updateUser(x, u) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// UpdateUserSetting updates user's settings.
|
|
|
|
|
|
|
|
func UpdateUserSetting(u *User) error { |
|
|
|
|
|
|
|
if !u.IsOrganization() { |
|
|
|
|
|
|
|
if err := checkDupEmail(x, u); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return updateUser(x, u) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// deleteBeans deletes all given beans, beans should contain delete conditions.
|
|
|
|
// deleteBeans deletes all given beans, beans should contain delete conditions.
|
|
|
|
func deleteBeans(e Engine, beans ...interface{}) (err error) { |
|
|
|
func deleteBeans(e Engine, beans ...interface{}) (err error) { |
|
|
|
for i := range beans { |
|
|
|
for i := range beans { |
|
|
|