|
|
@@ -14,6 +14,7 @@ import ( |
|
|
|
"net/textproto" |
|
|
|
"strings" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/auth/cloudbrain" |
|
|
|
"code.gitea.io/gitea/modules/auth/ldap" |
|
|
|
"code.gitea.io/gitea/modules/auth/oauth2" |
|
|
|
"code.gitea.io/gitea/modules/auth/pam" |
|
|
@@ -21,6 +22,7 @@ import ( |
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
"code.gitea.io/gitea/modules/timeutil" |
|
|
|
|
|
|
|
gouuid "github.com/satori/go.uuid" |
|
|
|
"github.com/unknwon/com" |
|
|
|
"xorm.io/xorm" |
|
|
|
"xorm.io/xorm/convert" |
|
|
@@ -761,6 +763,16 @@ func UserSignIn(username, password string) (*User, error) { |
|
|
|
} |
|
|
|
|
|
|
|
if hasUser { |
|
|
|
if user.CloudBrainValidated { |
|
|
|
_, _, err := cloudbrain.UserValidate(username, password) |
|
|
|
if err != nil { |
|
|
|
log.Error("cloudbrain.UserValidate(%s) failed: %v", username, err) |
|
|
|
return nil, err |
|
|
|
} else { |
|
|
|
return user, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
switch user.LoginType { |
|
|
|
case LoginNoType, LoginPlain, LoginOAuth2: |
|
|
|
if user.IsPasswordSet() && user.ValidatePassword(password) { |
|
|
@@ -795,6 +807,32 @@ func UserSignIn(username, password string) (*User, error) { |
|
|
|
|
|
|
|
return ExternalUserLogin(user, user.LoginName, password, &source) |
|
|
|
} |
|
|
|
} else { |
|
|
|
email, token, err := cloudbrain.UserValidate(username, password) |
|
|
|
if err == nil { |
|
|
|
if email == "" { |
|
|
|
email = genRandEmail() |
|
|
|
} |
|
|
|
|
|
|
|
log.Info(email) |
|
|
|
u := &User{ |
|
|
|
Name: username, |
|
|
|
Email: email, |
|
|
|
Passwd: password, |
|
|
|
IsActive: true, |
|
|
|
CloudBrainValidated: true, |
|
|
|
Token: token, |
|
|
|
} |
|
|
|
if err := CreateUser(u); err != nil { |
|
|
|
log.Error("CreateUser(%s) failed: %v", username, err) |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
log.Info("Account created: %s", u.Name) |
|
|
|
|
|
|
|
return u, nil |
|
|
|
} |
|
|
|
|
|
|
|
log.Info("cloudbrain.UserValidate(%s) failed: %v", username, err) |
|
|
|
} |
|
|
|
|
|
|
|
sources := make([]*LoginSource, 0, 5) |
|
|
@@ -817,3 +855,7 @@ func UserSignIn(username, password string) (*User, error) { |
|
|
|
|
|
|
|
return nil, ErrUserNotExist{user.ID, user.Name, 0} |
|
|
|
} |
|
|
|
|
|
|
|
func genRandEmail() string{ |
|
|
|
return gouuid.NewV4().String() + "@cloudbrain.com" |
|
|
|
} |