forked from forgejo/forgejo
Fix ldap loginname (#18789)
* Use email_address table to check user's email when login with email adress * Update services/auth/signin.go * Fix test * Fix test * Fix logging in with ldap username != loginname * Fix if user does not exist yet * Make more clear this is loginName * Fix formatting Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
parent
1ab88da0e4
commit
0cc2675c44
4 changed files with 25 additions and 8 deletions
|
@ -24,17 +24,18 @@ import (
|
|||
func UserSignIn(username, password string) (*user_model.User, *auth.Source, error) {
|
||||
var user *user_model.User
|
||||
if strings.Contains(username, "@") {
|
||||
user = &user_model.User{Email: strings.ToLower(strings.TrimSpace(username))}
|
||||
emailAddress := user_model.EmailAddress{LowerEmail: strings.ToLower(strings.TrimSpace(username))}
|
||||
// check same email
|
||||
cnt, err := db.Count(user)
|
||||
has, err := db.GetEngine(db.DefaultContext).Where("is_activated=?", true).Get(&emailAddress)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if cnt > 1 {
|
||||
return nil, nil, user_model.ErrEmailAlreadyUsed{
|
||||
if !has {
|
||||
return nil, nil, user_model.ErrEmailAddressNotExist{
|
||||
Email: user.Email,
|
||||
}
|
||||
}
|
||||
user = &user_model.User{ID: emailAddress.UID}
|
||||
} else {
|
||||
trimmedUsername := strings.TrimSpace(username)
|
||||
if len(trimmedUsername) == 0 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue