summaryrefslogtreecommitdiffstats
path: root/models/login.go
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2014-07-26 00:24:27 -0400
committerUnknwon <joe2010xtmf@163.com>2014-07-26 00:24:27 -0400
commit8dd07c0ddd99ae626a1ec8c06f75f27fed51269f (patch)
tree261d3c9911dabc58c1ac54e4e36b3dee24d2032b /models/login.go
parent0a739cf9ac901f54484c34bba8322418dedb09b0 (diff)
downloadgitea-8dd07c0ddd99ae626a1ec8c06f75f27fed51269f.tar.gz
gitea-8dd07c0ddd99ae626a1ec8c06f75f27fed51269f.zip
New UI merge in progress
Diffstat (limited to 'models/login.go')
-rw-r--r--models/login.go27
1 files changed, 14 insertions, 13 deletions
diff --git a/models/login.go b/models/login.go
index e99b61e779..da7722f294 100644
--- a/models/login.go
+++ b/models/login.go
@@ -164,15 +164,14 @@ func UserSignIn(uname, passwd string) (*User, error) {
if u.LoginType == NOTYPE {
if has {
u.LoginType = PLAIN
+ } else {
+ return nil, ErrUserNotExist
}
}
- // for plain login, user must have existed.
+ // For plain login, user must exist to reach this line.
+ // Now verify password.
if u.LoginType == PLAIN {
- if !has {
- return nil, ErrUserNotExist
- }
-
newUser := &User{Passwd: passwd, Salt: u.Salt}
newUser.EncodePasswd()
if u.Passwd != newUser.Passwd {
@@ -233,18 +232,18 @@ 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
-func LoginUserLdapSource(user *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)
if !logged {
// user not in LDAP, do nothing
return nil, ErrUserNotExist
}
if !autoRegister {
- return user, nil
+ return u, nil
}
// fake a local user creation
- user = &User{
+ u = &User{
LowerName: strings.ToLower(name),
Name: strings.ToLower(name),
LoginType: LDAP,
@@ -255,7 +254,8 @@ func LoginUserLdapSource(user *User, name, passwd string, sourceId int64, cfg *L
Email: mail,
}
- return CreateUser(user)
+ err := CreateUser(u)
+ return u, err
}
type loginAuth struct {
@@ -322,7 +322,7 @@ func SmtpAuth(host string, port int, a smtp.Auth, useTls bool) error {
// Query if name/passwd can login against the LDAP direcotry pool
// Create a local user if success
// Return the same LoginUserPlain semantic
-func LoginUserSMTPSource(user *User, name, passwd string, sourceId int64, cfg *SMTPConfig, autoRegister bool) (*User, error) {
+func LoginUserSMTPSource(u *User, name, passwd string, sourceId int64, cfg *SMTPConfig, autoRegister bool) (*User, error) {
var auth smtp.Auth
if cfg.Auth == SMTP_PLAIN {
auth = smtp.PlainAuth("", name, passwd, cfg.Host)
@@ -340,7 +340,7 @@ func LoginUserSMTPSource(user *User, name, passwd string, sourceId int64, cfg *S
}
if !autoRegister {
- return user, nil
+ return u, nil
}
var loginName = name
@@ -349,7 +349,7 @@ func LoginUserSMTPSource(user *User, name, passwd string, sourceId int64, cfg *S
loginName = name[:idx]
}
// fake a local user creation
- user = &User{
+ u = &User{
LowerName: strings.ToLower(loginName),
Name: strings.ToLower(loginName),
LoginType: SMTP,
@@ -359,5 +359,6 @@ func LoginUserSMTPSource(user *User, name, passwd string, sourceId int64, cfg *S
Passwd: passwd,
Email: name,
}
- return CreateUser(user)
+ err := CreateUser(u)
+ return u, err
}