From b9527cd1bfabcce3be62b43f0c199b1418519549 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Wed, 5 Aug 2015 17:36:22 +0800 Subject: [PATCH] #1299 force downcase e-mail --- models/user.go | 22 +++++++++++++++------- public/js/app.js | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/models/user.go b/models/user.go index c5d4b9d9143..4b6517d7b15 100644 --- a/models/user.go +++ b/models/user.go @@ -258,6 +258,8 @@ func IsEmailUsed(email string) (bool, error) { if len(email) == 0 { return false, nil } + + email = strings.ToLower(email) if has, err := x.Get(&EmailAddress{Email: email}); has || err != nil { return has, err } @@ -405,6 +407,7 @@ func ChangeUserName(u *User, newUserName string) (err error) { // UpdateUser updates user's information. func UpdateUser(u *User) error { + u.Email = strings.ToLower(u.Email) has, err := x.Where("id!=?", u.Id).And("type=?", u.Type).And("email=?", u.Email).Get(new(User)) if err != nil { return err @@ -641,6 +644,7 @@ func GetEmailAddresses(uid int64) ([]*EmailAddress, error) { } func AddEmailAddress(email *EmailAddress) error { + email.Email = strings.ToLower(email.Email) used, err := IsEmailUsed(email.Email) if err != nil { return err @@ -674,7 +678,7 @@ func DeleteEmailAddress(email *EmailAddress) error { return ErrEmailNotExist } - if _, err = x.Delete(email); err != nil { + if _, err = x.Id(email.Id).Delete(email); err != nil { return err } @@ -736,13 +740,15 @@ func ValidateCommitWithEmail(c *git.Commit) *User { // ValidateCommitsWithEmails checks if authors' e-mails of commits are corresponding to users. func ValidateCommitsWithEmails(oldCommits *list.List) *list.List { - emails := map[string]*User{} - newCommits := list.New() - e := oldCommits.Front() + var ( + u *User + emails = map[string]*User{} + newCommits = list.New() + e = oldCommits.Front() + ) for e != nil { c := e.Value.(*git.Commit) - var u *User if v, ok := emails[c.Author.Email]; !ok { u, _ = GetUserByEmail(c.Author.Email) emails[c.Author.Email] = u @@ -764,8 +770,10 @@ func GetUserByEmail(email string) (*User, error) { if len(email) == 0 { return nil, ErrUserNotExist{0, "email"} } + + email = strings.ToLower(email) // First try to find the user by primary email - user := &User{Email: strings.ToLower(email)} + user := &User{Email: email} has, err := x.Get(user) if err != nil { return nil, err @@ -775,7 +783,7 @@ func GetUserByEmail(email string) (*User, error) { } // Otherwise, check in alternative list for activated email addresses - emailAddress := &EmailAddress{Email: strings.ToLower(email), IsActivated: true} + emailAddress := &EmailAddress{Email: email, IsActivated: true} has, err = x.Get(emailAddress) if err != nil { return nil, err diff --git a/public/js/app.js b/public/js/app.js index 3dbf29c144b..8eb19a0aa5a 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -297,7 +297,7 @@ var Gogits = {}; } else { $(selector).zclip({ - path: Gogs.AppSubUrl + "/js/ZeroClipboard.swf", + path: Gogits.AppSubUrl + "/js/ZeroClipboard.swf", copy: function () { var t = $(this).data("copy-val"); var to = $($(this).data("copy-from"));