|
|
@ -18,6 +18,7 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
"github.com/gogits/gogs/modules/auth/ldap" |
|
|
|
"github.com/gogits/gogs/modules/auth/ldap" |
|
|
|
"github.com/gogits/gogs/modules/log" |
|
|
|
"github.com/gogits/gogs/modules/log" |
|
|
|
|
|
|
|
"github.com/gogits/gogs/modules/uuid" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type LoginType int |
|
|
|
type LoginType int |
|
|
@ -228,30 +229,32 @@ func UserSignIn(uname, passwd string) (*User, error) { |
|
|
|
// Query if name/passwd can login against the LDAP direcotry pool
|
|
|
|
// Query if name/passwd can login against the LDAP direcotry pool
|
|
|
|
// Create a local user if success
|
|
|
|
// Create a local user if success
|
|
|
|
// Return the same LoginUserPlain semantic
|
|
|
|
// Return the same LoginUserPlain semantic
|
|
|
|
|
|
|
|
// FIXME: https://github.com/gogits/gogs/issues/672
|
|
|
|
func LoginUserLdapSource(u *User, name, passwd string, sourceId int64, cfg *LDAPConfig, autoRegister bool) (*User, error) { |
|
|
|
func LoginUserLdapSource(u *User, name, passwd string, sourceId int64, cfg *LDAPConfig, autoRegister bool) (*User, error) { |
|
|
|
mail, logged := cfg.Ldapsource.SearchEntry(name, passwd) |
|
|
|
mail, logged := cfg.Ldapsource.SearchEntry(name, passwd) |
|
|
|
if !logged { |
|
|
|
if !logged { |
|
|
|
// user not in LDAP, do nothing
|
|
|
|
// User not in LDAP, do nothing
|
|
|
|
return nil, ErrUserNotExist |
|
|
|
return nil, ErrUserNotExist |
|
|
|
} |
|
|
|
} |
|
|
|
if !autoRegister { |
|
|
|
if !autoRegister { |
|
|
|
return u, nil |
|
|
|
return u, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// fake a local user creation
|
|
|
|
// Fallback.
|
|
|
|
|
|
|
|
if len(mail) == 0 { |
|
|
|
|
|
|
|
mail = uuid.NewV4().String() + "@localhost" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
u = &User{ |
|
|
|
u = &User{ |
|
|
|
LowerName: strings.ToLower(name), |
|
|
|
Name: name, |
|
|
|
Name: strings.ToLower(name), |
|
|
|
|
|
|
|
LoginType: LDAP, |
|
|
|
LoginType: LDAP, |
|
|
|
LoginSource: sourceId, |
|
|
|
LoginSource: sourceId, |
|
|
|
LoginName: name, |
|
|
|
LoginName: name, |
|
|
|
IsActive: true, |
|
|
|
|
|
|
|
Passwd: passwd, |
|
|
|
Passwd: passwd, |
|
|
|
Email: mail, |
|
|
|
Email: mail, |
|
|
|
|
|
|
|
IsActive: true, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return u, CreateUser(u) |
|
|
|
err := CreateUser(u) |
|
|
|
|
|
|
|
return u, err |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type loginAuth struct { |
|
|
|
type loginAuth struct { |
|
|
|