summaryrefslogtreecommitdiffstats
path: root/models/user.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-06-08 11:52:51 +0800
committerGitHub <noreply@github.com>2021-06-08 11:52:51 +0800
commitb9d611e917d9bd10e0d8be8fc61e057d5936993c (patch)
treef70159ff5731da4b34312acfff8443dc3be61337 /models/user.go
parent21cde5c439676d4aaa15dfc79505f364cc849ec0 (diff)
downloadgitea-b9d611e917d9bd10e0d8be8fc61e057d5936993c.tar.gz
gitea-b9d611e917d9bd10e0d8be8fc61e057d5936993c.zip
Always store primary email address into email_address table and also the state (#15956)
* Always store primary email address into email_address table and also the state * Add lower_email to not convert email to lower as what's added * Fix fixture * Fix tests * Use BeforeInsert to save lower email * Fix v180 migration * fix tests * Fix test * Remove wrong submited codes * Fix test * Fix test * Fix test * Add test for v181 migration * remove change user's email to lower * Revert change on user's email column * Fix lower email * Fix test * Fix test
Diffstat (limited to 'models/user.go')
-rw-r--r--models/user.go23
1 files changed, 11 insertions, 12 deletions
diff --git a/models/user.go b/models/user.go
index c7b44bdb73..002c050651 100644
--- a/models/user.go
+++ b/models/user.go
@@ -74,9 +74,6 @@ const (
)
var (
- // ErrEmailNotExist e-mail does not exist error
- ErrEmailNotExist = errors.New("E-mail does not exist")
-
// ErrEmailNotActivated e-mail address has not been activated error
ErrEmailNotActivated = errors.New("E-mail address has not been activated")
@@ -876,15 +873,6 @@ func CreateUser(u *User) (err error) {
}
u.Email = strings.ToLower(u.Email)
- isExist, err = sess.
- Where("email=?", u.Email).
- Get(new(User))
- if err != nil {
- return err
- } else if isExist {
- return ErrEmailAlreadyUsed{u.Email}
- }
-
if err = ValidateEmail(u.Email); err != nil {
return err
}
@@ -915,6 +903,17 @@ func CreateUser(u *User) (err error) {
return err
}
+ // insert email address
+ if _, err := sess.Insert(&EmailAddress{
+ UID: u.ID,
+ Email: u.Email,
+ LowerEmail: strings.ToLower(u.Email),
+ IsActivated: u.IsActive,
+ IsPrimary: true,
+ }); err != nil {
+ return err
+ }
+
return sess.Commit()
}