forked from forgejo/forgejo
Move login related structs and functions to models/login (#17093)
* Move login related structs and functions to models/login * Fix test * Fix lint * Fix lint * Fix lint of windows * Fix lint * Fix test * Fix test * Only load necessary fixtures when preparing unit tests envs * Fix lint * Fix test * Fix test * Fix error log * Fix error log * Fix error log * remove unnecessary change * fix error log * merge main branch
This commit is contained in:
parent
4a2655098f
commit
5842a55b31
142 changed files with 1050 additions and 907 deletions
|
@ -5,7 +5,7 @@
|
|||
package oauth2_test
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/login"
|
||||
"code.gitea.io/gitea/services/auth"
|
||||
"code.gitea.io/gitea/services/auth/source/oauth2"
|
||||
)
|
||||
|
@ -14,9 +14,9 @@ import (
|
|||
// It tightly binds the interfaces and implementation without breaking go import cycles
|
||||
|
||||
type sourceInterface interface {
|
||||
models.LoginConfig
|
||||
models.LoginSourceSettable
|
||||
models.RegisterableSource
|
||||
login.Config
|
||||
login.SourceSettable
|
||||
login.RegisterableSource
|
||||
auth.PasswordAuthenticator
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
"net/http"
|
||||
"sync"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/login"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
|
@ -74,7 +74,7 @@ func ResetOAuth2() error {
|
|||
|
||||
// initOAuth2LoginSources is used to load and register all active OAuth2 providers
|
||||
func initOAuth2LoginSources() error {
|
||||
loginSources, _ := models.GetActiveOAuth2ProviderLoginSources()
|
||||
loginSources, _ := login.GetActiveOAuth2ProviderLoginSources()
|
||||
for _, source := range loginSources {
|
||||
oauth2Source, ok := source.Cfg.(*Source)
|
||||
if !ok {
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"sort"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/login"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
|
@ -87,7 +88,7 @@ func GetOAuth2Providers() []Provider {
|
|||
func GetActiveOAuth2Providers() ([]string, map[string]Provider, error) {
|
||||
// Maybe also separate used and unused providers so we can force the registration of only 1 active provider for each type
|
||||
|
||||
loginSources, err := models.GetActiveOAuth2ProviderLoginSources()
|
||||
loginSources, err := login.GetActiveOAuth2ProviderLoginSources()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ package oauth2
|
|||
|
||||
import (
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/login"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
)
|
||||
|
||||
|
@ -27,7 +28,7 @@ type Source struct {
|
|||
SkipLocalTwoFA bool
|
||||
|
||||
// reference to the loginSource
|
||||
loginSource *models.LoginSource
|
||||
loginSource *login.Source
|
||||
}
|
||||
|
||||
// FromDB fills up an OAuth2Config from serialized format.
|
||||
|
@ -41,10 +42,10 @@ func (source *Source) ToDB() ([]byte, error) {
|
|||
}
|
||||
|
||||
// SetLoginSource sets the related LoginSource
|
||||
func (source *Source) SetLoginSource(loginSource *models.LoginSource) {
|
||||
func (source *Source) SetLoginSource(loginSource *login.Source) {
|
||||
source.loginSource = loginSource
|
||||
}
|
||||
|
||||
func init() {
|
||||
models.RegisterLoginTypeConfig(models.LoginOAuth2, &Source{})
|
||||
login.RegisterTypeConfig(login.OAuth2, &Source{})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue