diff options
author | 6543 <6543@obermui.de> | 2020-11-20 22:45:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-20 23:45:55 +0200 |
commit | f915161a2f1f4a1c436e7a96cfc88f61ae8fbce6 (patch) | |
tree | 1e5d4511c676a17532fb3aad0dc2b4f6623ba8db /models/user.go | |
parent | 1bb5c09b5d973ac184922380b1e6379875ac5fa7 (diff) | |
download | gitea-f915161a2f1f4a1c436e7a96cfc88f61ae8fbce6.tar.gz gitea-f915161a2f1f4a1c436e7a96cfc88f61ae8fbce6.zip |
skip email validation on empty string (#13627)
- move validation into its own function
- use a session for UpdateUserSetting
Diffstat (limited to 'models/user.go')
-rw-r--r-- | models/user.go | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/models/user.go b/models/user.go index 9489ff4e8b..2a76995578 100644 --- a/models/user.go +++ b/models/user.go @@ -14,7 +14,6 @@ import ( "errors" "fmt" _ "image/jpeg" // Needed for jpeg support - "net/mail" "os" "path/filepath" "regexp" @@ -809,9 +808,8 @@ func CreateUser(u *User) (err error) { return ErrEmailAlreadyUsed{u.Email} } - _, err = mail.ParseAddress(u.Email) - if err != nil { - return ErrEmailInvalid{u.Email} + if err = ValidateEmail(u.Email); err != nil { + return err } isExist, err = isEmailUsed(sess, u.Email) @@ -956,11 +954,10 @@ func checkDupEmail(e Engine, u *User) error { return nil } -func updateUser(e Engine, u *User) error { +func updateUser(e Engine, u *User) (err error) { u.Email = strings.ToLower(u.Email) - _, err := mail.ParseAddress(u.Email) - if err != nil { - return ErrEmailInvalid{u.Email} + if err = ValidateEmail(u.Email); err != nil { + return err } _, err = e.ID(u.ID).AllCols().Update(u) return err @@ -982,13 +979,21 @@ func updateUserCols(e Engine, u *User, cols ...string) error { } // 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 err := checkDupEmail(x, u); err != nil { + if err = checkDupEmail(sess, u); err != nil { 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. |