|
|
@ -15,6 +15,7 @@ import ( |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/Unknwon/com" |
|
|
|
"github.com/Unknwon/com" |
|
|
|
|
|
|
|
"github.com/go-macaron/binding" |
|
|
|
"github.com/go-xorm/core" |
|
|
|
"github.com/go-xorm/core" |
|
|
|
"github.com/go-xorm/xorm" |
|
|
|
"github.com/go-xorm/xorm" |
|
|
|
|
|
|
|
|
|
|
@ -280,7 +281,7 @@ func DeleteSource(source *LoginSource) error { |
|
|
|
func LoginUserLDAPSource(u *User, loginName, passwd string, source *LoginSource, autoRegister bool) (*User, error) { |
|
|
|
func LoginUserLDAPSource(u *User, loginName, passwd string, source *LoginSource, autoRegister bool) (*User, error) { |
|
|
|
cfg := source.Cfg.(*LDAPConfig) |
|
|
|
cfg := source.Cfg.(*LDAPConfig) |
|
|
|
directBind := (source.Type == LOGIN_DLDAP) |
|
|
|
directBind := (source.Type == LOGIN_DLDAP) |
|
|
|
name, fn, sn, mail, admin, logged := cfg.SearchEntry(loginName, passwd, directBind) |
|
|
|
username, fn, sn, mail, isAdmin, logged := cfg.SearchEntry(loginName, passwd, directBind) |
|
|
|
if !logged { |
|
|
|
if !logged { |
|
|
|
// User not in LDAP, do nothing
|
|
|
|
// User not in LDAP, do nothing
|
|
|
|
return nil, ErrUserNotExist{0, loginName} |
|
|
|
return nil, ErrUserNotExist{0, loginName} |
|
|
@ -291,37 +292,42 @@ func LoginUserLDAPSource(u *User, loginName, passwd string, source *LoginSource, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Fallback.
|
|
|
|
// Fallback.
|
|
|
|
if len(name) == 0 { |
|
|
|
if len(username) == 0 { |
|
|
|
name = loginName |
|
|
|
username = loginName |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Validate username make sure it satisfies requirement.
|
|
|
|
|
|
|
|
if !binding.AlphaDashDotPattern.MatchString(username) { |
|
|
|
|
|
|
|
return nil, fmt.Errorf("Invalid pattern for attribute 'username' [%s]: must be valid alpha or numeric or dash(-_) or dot characters", username) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if len(mail) == 0 { |
|
|
|
if len(mail) == 0 { |
|
|
|
mail = fmt.Sprintf("%s@localhost", name) |
|
|
|
mail = fmt.Sprintf("%s@localhost", username) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
u = &User{ |
|
|
|
u = &User{ |
|
|
|
LowerName: strings.ToLower(name), |
|
|
|
LowerName: strings.ToLower(username), |
|
|
|
Name: name, |
|
|
|
Name: username, |
|
|
|
FullName: composeFullName(fn, sn, name), |
|
|
|
FullName: composeFullName(fn, sn, username), |
|
|
|
LoginType: source.Type, |
|
|
|
LoginType: source.Type, |
|
|
|
LoginSource: source.ID, |
|
|
|
LoginSource: source.ID, |
|
|
|
LoginName: loginName, |
|
|
|
LoginName: loginName, |
|
|
|
Email: mail, |
|
|
|
Email: mail, |
|
|
|
IsAdmin: admin, |
|
|
|
IsAdmin: isAdmin, |
|
|
|
IsActive: true, |
|
|
|
IsActive: true, |
|
|
|
} |
|
|
|
} |
|
|
|
return u, CreateUser(u) |
|
|
|
return u, CreateUser(u) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func composeFullName(firstName, surename, userName string) string { |
|
|
|
func composeFullName(firstname, surname, username string) string { |
|
|
|
switch { |
|
|
|
switch { |
|
|
|
case len(firstName) == 0 && len(surename) == 0: |
|
|
|
case len(firstname) == 0 && len(surname) == 0: |
|
|
|
return userName |
|
|
|
return username |
|
|
|
case len(firstName) == 0: |
|
|
|
case len(firstname) == 0: |
|
|
|
return surename |
|
|
|
return surname |
|
|
|
case len(surename) == 0: |
|
|
|
case len(surname) == 0: |
|
|
|
return firstName |
|
|
|
return firstname |
|
|
|
default: |
|
|
|
default: |
|
|
|
return firstName + " " + surename |
|
|
|
return firstname + " " + surname |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|