Refactor auth package (#17962)
This commit is contained in:
parent
e61b390d54
commit
de8e3948a5
87 changed files with 2880 additions and 2770 deletions
|
@ -7,8 +7,8 @@ package user
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models/auth"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/login"
|
||||
)
|
||||
|
||||
// UserList is a list of user.
|
||||
|
@ -40,13 +40,13 @@ func (users UserList) GetTwoFaStatus() map[int64]bool {
|
|||
return results
|
||||
}
|
||||
|
||||
func (users UserList) loadTwoFactorStatus(e db.Engine) (map[int64]*login.TwoFactor, error) {
|
||||
func (users UserList) loadTwoFactorStatus(e db.Engine) (map[int64]*auth.TwoFactor, error) {
|
||||
if len(users) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
userIDs := users.GetUserIDs()
|
||||
tokenMaps := make(map[int64]*login.TwoFactor, len(userIDs))
|
||||
tokenMaps := make(map[int64]*auth.TwoFactor, len(userIDs))
|
||||
err := e.
|
||||
In("uid", userIDs).
|
||||
Find(&tokenMaps)
|
||||
|
|
|
@ -19,8 +19,8 @@ import (
|
|||
|
||||
_ "image/jpeg" // Needed for jpeg support
|
||||
|
||||
"code.gitea.io/gitea/models/auth"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/login"
|
||||
"code.gitea.io/gitea/modules/auth/openid"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
|
@ -89,7 +89,7 @@ type User struct {
|
|||
// is to change his/her password after registration.
|
||||
MustChangePassword bool `xorm:"NOT NULL DEFAULT false"`
|
||||
|
||||
LoginType login.Type
|
||||
LoginType auth.Type
|
||||
LoginSource int64 `xorm:"NOT NULL DEFAULT 0"`
|
||||
LoginName string
|
||||
Type UserType
|
||||
|
@ -232,12 +232,12 @@ func GetAllUsers() ([]*User, error) {
|
|||
|
||||
// IsLocal returns true if user login type is LoginPlain.
|
||||
func (u *User) IsLocal() bool {
|
||||
return u.LoginType <= login.Plain
|
||||
return u.LoginType <= auth.Plain
|
||||
}
|
||||
|
||||
// IsOAuth2 returns true if user login type is LoginOAuth2.
|
||||
func (u *User) IsOAuth2() bool {
|
||||
return u.LoginType == login.OAuth2
|
||||
return u.LoginType == auth.OAuth2
|
||||
}
|
||||
|
||||
// MaxCreationLimit returns the number of repositories a user is allowed to create
|
||||
|
@ -1012,7 +1012,7 @@ func GetUserIDsByNames(names []string, ignoreNonExistent bool) ([]int64, error)
|
|||
}
|
||||
|
||||
// GetUsersBySource returns a list of Users for a login source
|
||||
func GetUsersBySource(s *login.Source) ([]*User, error) {
|
||||
func GetUsersBySource(s *auth.Source) ([]*User, error) {
|
||||
var users []*User
|
||||
err := db.GetEngine(db.DefaultContext).Where("login_type = ? AND login_source = ?", s.Type, s.ID).Find(&users)
|
||||
return users, err
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/auth"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/login"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
|
@ -21,7 +21,7 @@ import (
|
|||
|
||||
func TestOAuth2Application_LoadUser(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
app := unittest.AssertExistsAndLoadBean(t, &login.OAuth2Application{ID: 1}).(*login.OAuth2Application)
|
||||
app := unittest.AssertExistsAndLoadBean(t, &auth.OAuth2Application{ID: 1}).(*auth.OAuth2Application)
|
||||
user, err := GetUserByID(app.UID)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, user)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue