summaryrefslogtreecommitdiffstats
path: root/models/user_mail.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-11-20 22:45:55 +0100
committerGitHub <noreply@github.com>2020-11-20 23:45:55 +0200
commitf915161a2f1f4a1c436e7a96cfc88f61ae8fbce6 (patch)
tree1e5d4511c676a17532fb3aad0dc2b4f6623ba8db /models/user_mail.go
parent1bb5c09b5d973ac184922380b1e6379875ac5fa7 (diff)
downloadgitea-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_mail.go')
-rw-r--r--models/user_mail.go25
1 files changed, 19 insertions, 6 deletions
diff --git a/models/user_mail.go b/models/user_mail.go
index e15b5a3adf..1e56a5cd83 100644
--- a/models/user_mail.go
+++ b/models/user_mail.go
@@ -33,6 +33,21 @@ type EmailAddress struct {
IsPrimary bool `xorm:"-"`
}
+// ValidateEmail check if email is a allowed address
+func ValidateEmail(email string) error {
+ if len(email) == 0 {
+ return nil
+ }
+
+ if _, err := mail.ParseAddress(email); err != nil {
+ return ErrEmailInvalid{email}
+ }
+
+ // TODO: add an email allow/block list
+
+ return nil
+}
+
// GetEmailAddresses returns all email addresses belongs to given user.
func GetEmailAddresses(uid int64) ([]*EmailAddress, error) {
emails := make([]*EmailAddress, 0, 5)
@@ -144,9 +159,8 @@ func addEmailAddress(e Engine, email *EmailAddress) error {
return ErrEmailAlreadyUsed{email.Email}
}
- _, err = mail.ParseAddress(email.Email)
- if err != nil {
- return ErrEmailInvalid{email.Email}
+ if err = ValidateEmail(email.Email); err != nil {
+ return err
}
_, err = e.Insert(email)
@@ -173,9 +187,8 @@ func AddEmailAddresses(emails []*EmailAddress) error {
} else if used {
return ErrEmailAlreadyUsed{emails[i].Email}
}
- _, err = mail.ParseAddress(emails[i].Email)
- if err != nil {
- return ErrEmailInvalid{emails[i].Email}
+ if err = ValidateEmail(emails[i].Email); err != nil {
+ return err
}
}