summaryrefslogtreecommitdiffstats
path: root/services/auth/signin.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-24 17:49:20 +0800
committerGitHub <noreply@github.com>2021-11-24 17:49:20 +0800
commita666829a37be6f9fd98f9e7dd1767c420f7f3b32 (patch)
tree9ab1434b759a8a2cb275a83149903a823851e309 /services/auth/signin.go
parent4e7ca946da2a2642a62f114825129bf5d7ed9196 (diff)
downloadgitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.tar.gz
gitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.zip
Move user related model into models/user (#17781)
* Move user related model into models/user * Fix lint for windows * Fix windows lint * Fix windows lint * Move some tests in models * Merge
Diffstat (limited to 'services/auth/signin.go')
-rw-r--r--services/auth/signin.go37
1 files changed, 18 insertions, 19 deletions
diff --git a/services/auth/signin.go b/services/auth/signin.go
index 504214f9f1..5f75000d98 100644
--- a/services/auth/signin.go
+++ b/services/auth/signin.go
@@ -7,25 +7,24 @@ package auth
import (
"strings"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/login"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
- _ "code.gitea.io/gitea/services/auth/source/db" // register the sources (and below)
- _ "code.gitea.io/gitea/services/auth/source/ldap"
- _ "code.gitea.io/gitea/services/auth/source/oauth2"
- _ "code.gitea.io/gitea/services/auth/source/pam"
- _ "code.gitea.io/gitea/services/auth/source/smtp"
- _ "code.gitea.io/gitea/services/auth/source/sspi"
+ _ "code.gitea.io/gitea/services/auth/source/db" // register the sources (and below)
+ _ "code.gitea.io/gitea/services/auth/source/ldap" // register the ldap source
+ "code.gitea.io/gitea/services/auth/source/oauth2"
+ _ "code.gitea.io/gitea/services/auth/source/pam" // register the pam source
+ "code.gitea.io/gitea/services/auth/source/smtp"
+ _ "code.gitea.io/gitea/services/auth/source/sspi" // register the sspi source
)
// UserSignIn validates user name and password.
-func UserSignIn(username, password string) (*models.User, *login.Source, error) {
- var user *models.User
+func UserSignIn(username, password string) (*user_model.User, *login.Source, error) {
+ var user *user_model.User
if strings.Contains(username, "@") {
- user = &models.User{Email: strings.ToLower(strings.TrimSpace(username))}
+ user = &user_model.User{Email: strings.ToLower(strings.TrimSpace(username))}
// check same email
cnt, err := db.Count(user)
if err != nil {
@@ -39,13 +38,13 @@ func UserSignIn(username, password string) (*models.User, *login.Source, error)
} else {
trimmedUsername := strings.TrimSpace(username)
if len(trimmedUsername) == 0 {
- return nil, nil, models.ErrUserNotExist{Name: username}
+ return nil, nil, user_model.ErrUserNotExist{Name: username}
}
- user = &models.User{LowerName: strings.ToLower(trimmedUsername)}
+ user = &user_model.User{LowerName: strings.ToLower(trimmedUsername)}
}
- hasUser, err := models.GetUser(user)
+ hasUser, err := user_model.GetUser(user)
if err != nil {
return nil, nil, err
}
@@ -57,12 +56,12 @@ func UserSignIn(username, password string) (*models.User, *login.Source, error)
}
if !source.IsActive {
- return nil, nil, models.ErrLoginSourceNotActived
+ return nil, nil, oauth2.ErrLoginSourceNotActived
}
authenticator, ok := source.Cfg.(PasswordAuthenticator)
if !ok {
- return nil, nil, models.ErrUnsupportedLoginType
+ return nil, nil, smtp.ErrUnsupportedLoginType
}
user, err := authenticator.Authenticate(user, username, password)
@@ -73,7 +72,7 @@ func UserSignIn(username, password string) (*models.User, *login.Source, error)
// WARN: DON'T check user.IsActive, that will be checked on reqSign so that
// user could be hint to resend confirm email.
if user.ProhibitLogin {
- return nil, nil, models.ErrUserProhibitLogin{UID: user.ID, Name: user.Name}
+ return nil, nil, user_model.ErrUserProhibitLogin{UID: user.ID, Name: user.Name}
}
return user, source, nil
@@ -101,15 +100,15 @@ func UserSignIn(username, password string) (*models.User, *login.Source, error)
if !authUser.ProhibitLogin {
return authUser, source, nil
}
- err = models.ErrUserProhibitLogin{UID: authUser.ID, Name: authUser.Name}
+ err = user_model.ErrUserProhibitLogin{UID: authUser.ID, Name: authUser.Name}
}
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
log.Debug("Failed to login '%s' via '%s': %v", username, source.Name, err)
} else {
log.Warn("Failed to login '%s' via '%s': %v", username, source.Name, err)
}
}
- return nil, nil, models.ErrUserNotExist{Name: username}
+ return nil, nil, user_model.ErrUserNotExist{Name: username}
}