summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2017-02-25 22:53:57 +0800
committerGitHub <noreply@github.com>2017-02-25 22:53:57 +0800
commite8e56da9ac321aacb3c06968997a45c2f133cd4e (patch)
treecaff61d672cfb50a71c594bc506b4f51c5723f86
parentddb0287bf61f1c4271eef92f61e297101b708671 (diff)
downloadgitea-e8e56da9ac321aacb3c06968997a45c2f133cd4e.tar.gz
gitea-e8e56da9ac321aacb3c06968997a45c2f133cd4e.zip
fix #13 (#1042)
-rw-r--r--models/user.go39
-rw-r--r--routers/user/setting.go2
2 files changed, 28 insertions, 13 deletions
diff --git a/models/user.go b/models/user.go
index 55cffe1952..4b019d8d32 100644
--- a/models/user.go
+++ b/models/user.go
@@ -821,21 +821,26 @@ func ChangeUserName(u *User, newUserName string) (err error) {
return os.Rename(UserPath(u.Name), UserPath(newUserName))
}
+// checkDupEmail checks whether there are the same email with the user
+func checkDupEmail(e Engine, u *User) error {
+ u.Email = strings.ToLower(u.Email)
+ has, err := e.
+ Where("id!=?", u.ID).
+ And("type=?", u.Type).
+ And("email=?", u.Email).
+ Get(new(User))
+ if err != nil {
+ return err
+ } else if has {
+ 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() {
- u.Email = strings.ToLower(u.Email)
- has, err := e.
- Where("id!=?", u.ID).
- And("type=?", u.Type).
- And("email=?", u.Email).
- Get(new(User))
- if err != nil {
- return err
- } else if has {
- return ErrEmailAlreadyUsed{u.Email}
- }
-
if len(u.AvatarEmail) == 0 {
u.AvatarEmail = u.Email
}
@@ -857,6 +862,16 @@ func UpdateUser(u *User) error {
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.
func deleteBeans(e Engine, beans ...interface{}) (err error) {
for i := range beans {
diff --git a/routers/user/setting.go b/routers/user/setting.go
index 16ba2bb050..66ee680fb5 100644
--- a/routers/user/setting.go
+++ b/routers/user/setting.go
@@ -104,7 +104,7 @@ func SettingsPost(ctx *context.Context, form auth.UpdateProfileForm) {
ctx.User.KeepEmailPrivate = form.KeepEmailPrivate
ctx.User.Website = form.Website
ctx.User.Location = form.Location
- if err := models.UpdateUser(ctx.User); err != nil {
+ if err := models.UpdateUserSetting(ctx.User); err != nil {
if _, ok := err.(models.ErrEmailAlreadyUsed); ok {
ctx.Flash.Error(ctx.Tr("form.email_been_used"))
ctx.Redirect(setting.AppSubURL + "/user/settings")