Skip to content

Commit bdad3b2

Browse files
Berk Demirkırlunny
Berk Demirkır
authored andcommitted
Check primary email address fields on CreateUser (#556)
* Check primary email address fields on CreateUser As this check wasn't available, uid=1 (and possibly guests too, if registration is open) is able to register new users with existing email addresses. This leads to numerous 500 errors. * Update user.go * Lower the email first. Then check
1 parent 1207bda commit bdad3b2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

models/user.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,15 @@ func CreateUser(u *User) (err error) {
600600
}
601601

602602
u.Email = strings.ToLower(u.Email)
603+
has, err := x.
604+
Where("email=?", u.Email).
605+
Get(new(User))
606+
if err != nil {
607+
return err
608+
} else if has {
609+
return ErrEmailAlreadyUsed{u.Email}
610+
}
611+
603612
isExist, err = IsEmailUsed(u.Email)
604613
if err != nil {
605614
return err

0 commit comments

Comments
 (0)