]> source.dussan.org Git - gitea.git/commitdiff
work on #672
authorUnknwon <joe2010xtmf@163.com>
Fri, 5 Dec 2014 23:08:09 +0000 (18:08 -0500)
committerUnknwon <joe2010xtmf@163.com>
Fri, 5 Dec 2014 23:08:09 +0000 (18:08 -0500)
models/login.go
modules/auth/auth.go

index 87dbbacc76da62c43c68394c9f80035fcac3e594..3986353192bf87f733b9ec52451c554b98c966c8 100644 (file)
@@ -18,6 +18,7 @@ import (
 
        "github.com/gogits/gogs/modules/auth/ldap"
        "github.com/gogits/gogs/modules/log"
+       "github.com/gogits/gogs/modules/uuid"
 )
 
 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
 // Create a local user if success
 // 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) {
        mail, logged := cfg.Ldapsource.SearchEntry(name, passwd)
        if !logged {
-               // user not in LDAP, do nothing
+               // User not in LDAP, do nothing
                return nil, ErrUserNotExist
        }
        if !autoRegister {
                return u, nil
        }
 
-       // fake a local user creation
+       // Fallback.
+       if len(mail) == 0 {
+               mail = uuid.NewV4().String() + "@localhost"
+       }
+
        u = &User{
-               LowerName:   strings.ToLower(name),
-               Name:        strings.ToLower(name),
+               Name:        name,
                LoginType:   LDAP,
                LoginSource: sourceId,
                LoginName:   name,
-               IsActive:    true,
                Passwd:      passwd,
                Email:       mail,
+               IsActive:    true,
        }
-
-       err := CreateUser(u)
-       return u, err
+       return u, CreateUser(u)
 }
 
 type loginAuth struct {
index 5b7276b48a6f54595921cdc56458ab593425bdf7..450cdb37e916055e351bab723bd8414b1396dc45 100644 (file)
@@ -17,6 +17,7 @@ import (
        "github.com/gogits/gogs/modules/base"
        "github.com/gogits/gogs/modules/log"
        "github.com/gogits/gogs/modules/setting"
+       "github.com/gogits/gogs/modules/uuid"
 )
 
 // SignedInId returns the id of signed in user.
@@ -83,7 +84,7 @@ func SignedInUser(req *http.Request, sess session.Store) (*models.User, bool) {
                                        if setting.Service.EnableReverseProxyAutoRegister {
                                                u := &models.User{
                                                        Name:     webAuthUser,
-                                                       Email:    webAuthUser + "@gogs.io",
+                                                       Email:    uuid.NewV4().String() + "@localhost",
                                                        Passwd:   webAuthUser,
                                                        IsActive: true,
                                                }