diff options
Diffstat (limited to 'modules/auth')
-rw-r--r-- | modules/auth/auth.go | 1 | ||||
-rw-r--r-- | modules/auth/ldap/ldap.go | 4 | ||||
-rw-r--r-- | modules/auth/ldap/ldap_test.go | 32 |
3 files changed, 35 insertions, 2 deletions
diff --git a/modules/auth/auth.go b/modules/auth/auth.go index 4587b383..eefb5ed6 100644 --- a/modules/auth/auth.go +++ b/modules/auth/auth.go @@ -27,6 +27,7 @@ type RegisterForm struct { Password string `form:"passwd" binding:"Required;MinSize(6);MaxSize(30)"` RetypePasswd string `form:"retypepasswd"` LoginType string `form:"logintype"` + LoginName string `form:"loginname"` } func (f *RegisterForm) Name(field string) string { diff --git a/modules/auth/ldap/ldap.go b/modules/auth/ldap/ldap.go index 8578e38a..493339cd 100644 --- a/modules/auth/ldap/ldap.go +++ b/modules/auth/ldap/ldap.go @@ -42,7 +42,7 @@ func AddSource(name string, host string, port int, basedn string, attributes str func LoginUser(name, passwd string) (a string, r bool) { r = false for _, ls := range Authensource { - a, r = ls.searchEntry(name, passwd) + a, r = ls.SearchEntry(name, passwd) if r { return } @@ -51,7 +51,7 @@ func LoginUser(name, passwd string) (a string, r bool) { } // searchEntry : search an LDAP source if an entry (name, passwd) is valide and in the specific filter -func (ls Ldapsource) searchEntry(name, passwd string) (string, bool) { +func (ls Ldapsource) SearchEntry(name, passwd string) (string, bool) { l, err := goldap.Dial("tcp", fmt.Sprintf("%s:%d", ls.Host, ls.Port)) if err != nil { log.Debug("LDAP Connect error, disabled source %s", ls.Host) diff --git a/modules/auth/ldap/ldap_test.go b/modules/auth/ldap/ldap_test.go new file mode 100644 index 00000000..80965737 --- /dev/null +++ b/modules/auth/ldap/ldap_test.go @@ -0,0 +1,32 @@ +package ldap + +import ( + "fmt" + "testing" +) + +var ldapServer = "ldap.itd.umich.edu" +var ldapPort = uint16(389) +var baseDN = "dc=umich,dc=edu" +var filter = []string{ + "(cn=cis-fac)", + "(&(objectclass=rfc822mailgroup)(cn=*Computer*))", + "(&(objectclass=rfc822mailgroup)(cn=*Mathematics*))"} +var attributes = []string{ + "cn", + "description"} +var msadsaformat = "" + +func TestLDAP(t *testing.T) { + AddSource("test", ldapServer, ldapPort, + basedn, attributes, filter, + msadsaformat) + user, err := LoginUserLdap("xiaolunwen", "") + if err != nil { + t.Error(err) + return + } + + fmt.Println(user) + +} |