diff --git a/models/login/oauth2.go b/models/login/oauth2.go index cbc544cd4ead5..45ab59dd78ca8 100644 --- a/models/login/oauth2.go +++ b/models/login/oauth2.go @@ -52,7 +52,7 @@ func (err ErrOAuthApplicationNotFound) Error() string { // GetActiveOAuth2ProviderLoginSources returns all actived LoginOAuth2 sources func GetActiveOAuth2ProviderLoginSources() ([]*Source, error) { sources := make([]*Source, 0, 1) - if err := db.DefaultContext().Engine().Where("is_active = ? and type = ?", true, OAuth2).Find(&sources); err != nil { + if err := db.GetEngine(db.DefaultContext).Where("is_active = ? and type = ?", true, OAuth2).Find(&sources); err != nil { return nil, err } return sources, nil @@ -61,7 +61,7 @@ func GetActiveOAuth2ProviderLoginSources() ([]*Source, error) { // GetActiveOAuth2LoginSourceByName returns a OAuth2 LoginSource based on the given name func GetActiveOAuth2LoginSourceByName(name string) (*Source, error) { loginSource := new(Source) - has, err := db.DefaultContext().Engine().Where("name = ? and type = ? and is_active = ?", name, OAuth2, true).Get(loginSource) + has, err := db.GetEngine(db.DefaultContext).Where("name = ? and type = ? and is_active = ?", name, OAuth2, true).Get(loginSource) if !has || err != nil { return nil, err } diff --git a/models/oauth2.go b/models/oauth2.go deleted file mode 100644 index 7fdd5309fb92b..0000000000000 --- a/models/oauth2.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2017 The Gitea Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package models - -import "code.gitea.io/gitea/models/db" - -// GetActiveOAuth2ProviderLoginSources returns all actived LoginOAuth2 sources -func GetActiveOAuth2ProviderLoginSources() ([]*LoginSource, error) { - sources := make([]*LoginSource, 0, 1) - if err := db.GetEngine(db.DefaultContext).Where("is_active = ? and type = ?", true, LoginOAuth2).Find(&sources); err != nil { - return nil, err - } - return sources, nil -} - -// GetActiveOAuth2LoginSourceByName returns a OAuth2 LoginSource based on the given name -func GetActiveOAuth2LoginSourceByName(name string) (*LoginSource, error) { - loginSource := new(LoginSource) - has, err := db.GetEngine(db.DefaultContext).Where("name = ? and type = ? and is_active = ?", name, LoginOAuth2, true).Get(loginSource) - if !has || err != nil { - return nil, err - } - - return loginSource, nil -} diff --git a/services/auth/login_source.go b/services/auth/login_source.go index 476690ff76556..723dd2b1a5d0e 100644 --- a/services/auth/login_source.go +++ b/services/auth/login_source.go @@ -12,7 +12,7 @@ import ( // DeleteLoginSource deletes a LoginSource record in DB. func DeleteLoginSource(source *login.Source) error { - count, err := db.DefaultContext().Engine().Count(&models.User{LoginSource: source.ID}) + count, err := db.GetEngine(db.DefaultContext).Count(&models.User{LoginSource: source.ID}) if err != nil { return err } else if count > 0 { @@ -21,7 +21,7 @@ func DeleteLoginSource(source *login.Source) error { } } - count, err = db.DefaultContext().Engine().Count(&models.ExternalLoginUser{LoginSourceID: source.ID}) + count, err = db.GetEngine(db.DefaultContext).Count(&models.ExternalLoginUser{LoginSourceID: source.ID}) if err != nil { return err } else if count > 0 { @@ -36,6 +36,6 @@ func DeleteLoginSource(source *login.Source) error { } } - _, err = db.DefaultContext().Engine().ID(source.ID).Delete(new(login.Source)) + _, err = db.GetEngine(db.DefaultContext).ID(source.ID).Delete(new(login.Source)) return err }