|
|
@ -14,7 +14,6 @@ import ( |
|
|
|
"errors" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
_ "image/jpeg" // Needed for jpeg support
|
|
|
|
_ "image/jpeg" // Needed for jpeg support
|
|
|
|
"net/mail" |
|
|
|
|
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"path/filepath" |
|
|
|
"path/filepath" |
|
|
|
"regexp" |
|
|
|
"regexp" |
|
|
@ -809,9 +808,8 @@ func CreateUser(u *User) (err error) { |
|
|
|
return ErrEmailAlreadyUsed{u.Email} |
|
|
|
return ErrEmailAlreadyUsed{u.Email} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_, err = mail.ParseAddress(u.Email) |
|
|
|
if err = ValidateEmail(u.Email); err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return ErrEmailInvalid{u.Email} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
isExist, err = isEmailUsed(sess, u.Email) |
|
|
|
isExist, err = isEmailUsed(sess, u.Email) |
|
|
@ -956,11 +954,10 @@ func checkDupEmail(e Engine, u *User) error { |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func updateUser(e Engine, u *User) error { |
|
|
|
func updateUser(e Engine, u *User) (err error) { |
|
|
|
u.Email = strings.ToLower(u.Email) |
|
|
|
u.Email = strings.ToLower(u.Email) |
|
|
|
_, err := mail.ParseAddress(u.Email) |
|
|
|
if err = ValidateEmail(u.Email); err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return ErrEmailInvalid{u.Email} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
_, err = e.ID(u.ID).AllCols().Update(u) |
|
|
|
_, err = e.ID(u.ID).AllCols().Update(u) |
|
|
|
return err |
|
|
|
return err |
|
|
@ -982,13 +979,21 @@ func updateUserCols(e Engine, u *User, cols ...string) error { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// UpdateUserSetting updates user's settings.
|
|
|
|
// UpdateUserSetting updates user's settings.
|
|
|
|
func UpdateUserSetting(u *User) error { |
|
|
|
func UpdateUserSetting(u *User) (err error) { |
|
|
|
|
|
|
|
sess := x.NewSession() |
|
|
|
|
|
|
|
defer sess.Close() |
|
|
|
|
|
|
|
if err = sess.Begin(); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
if !u.IsOrganization() { |
|
|
|
if !u.IsOrganization() { |
|
|
|
if err := checkDupEmail(x, u); err != nil { |
|
|
|
if err = checkDupEmail(sess, u); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return updateUser(x, u) |
|
|
|
if err = updateUser(sess, u); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return sess.Commit() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// deleteBeans deletes all given beans, beans should contain delete conditions.
|
|
|
|
// deleteBeans deletes all given beans, beans should contain delete conditions.
|
|
|
|