diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-02-25 22:57:06 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-25 22:57:06 +0800 |
commit | 19b3c45ca7bddd43e41d169ef80e680c3c3bc798 (patch) | |
tree | f0b822a53c98f206488aaecb7309ee32c7309f84 /models | |
parent | cd1821a7e292b05e04fcc2a969b42d06ab512849 (diff) | |
download | gitea-19b3c45ca7bddd43e41d169ef80e680c3c3bc798.tar.gz gitea-19b3c45ca7bddd43e41d169ef80e680c3c3bc798.zip |
fix 500 when use a duplicat email instead of giving an error tip (#1040)
Diffstat (limited to 'models')
-rw-r--r-- | models/login_source.go | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/models/login_source.go b/models/login_source.go index 8d5d08dea6..ffae6bfaf2 100644 --- a/models/login_source.go +++ b/models/login_source.go @@ -20,9 +20,9 @@ import ( "github.com/go-xorm/xorm" "code.gitea.io/gitea/modules/auth/ldap" + "code.gitea.io/gitea/modules/auth/oauth2" "code.gitea.io/gitea/modules/auth/pam" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/auth/oauth2" ) // LoginType represents an login type. @@ -31,12 +31,12 @@ type LoginType int // Note: new type must append to the end of list to maintain compatibility. const ( LoginNoType LoginType = iota - LoginPlain // 1 - LoginLDAP // 2 - LoginSMTP // 3 - LoginPAM // 4 - LoginDLDAP // 5 - LoginOAuth2 // 6 + LoginPlain // 1 + LoginLDAP // 2 + LoginSMTP // 3 + LoginPAM // 4 + LoginDLDAP // 5 + LoginOAuth2 // 6 ) // LoginNames contains the name of LoginType values. @@ -498,7 +498,7 @@ func LoginViaSMTP(user *User, login, password string, sourceID int64, cfg *SMTPC idx := strings.Index(login, "@") if idx == -1 { return nil, ErrUserNotExist{0, login, 0} - } else if !com.IsSliceContainsStr(strings.Split(cfg.AllowedDomains, ","), login[idx + 1:]) { + } else if !com.IsSliceContainsStr(strings.Split(cfg.AllowedDomains, ","), login[idx+1:]) { return nil, ErrUserNotExist{0, login, 0} } } @@ -589,16 +589,16 @@ func LoginViaPAM(user *User, login, password string, sourceID int64, cfg *PAMCon // OAuth2Provider describes the display values of a single OAuth2 provider type OAuth2Provider struct { - Name string + Name string DisplayName string - Image string + Image string } // OAuth2Providers contains the map of registered OAuth2 providers in Gitea (based on goth) // key is used to map the OAuth2Provider with the goth provider type (also in LoginSource.OAuth2Config.Provider) // value is used to store display data var OAuth2Providers = map[string]OAuth2Provider{ - "github": {Name: "github", DisplayName:"GitHub", Image: "/img/github.png"}, + "github": {Name: "github", DisplayName: "GitHub", Image: "/img/github.png"}, } // ExternalUserLogin attempts a login using external source types. @@ -624,6 +624,16 @@ func UserSignIn(username, password string) (*User, error) { var user *User if strings.Contains(username, "@") { user = &User{Email: strings.ToLower(strings.TrimSpace(username))} + // check same email + cnt, err := x.Count(user) + if err != nil { + return nil, err + } + if cnt > 1 { + return nil, ErrEmailAlreadyUsed{ + Email: user.Email, + } + } } else { user = &User{LowerName: strings.ToLower(strings.TrimSpace(username))} } |