Browse Source

Replace calls to xorm UseBool with Where (#2237)

G 2 years ago
parent
commit
66e8262530
2 changed files with 4 additions and 9 deletions
  1. 1 1
      models/login_source.go
  2. 3 8
      models/oauth2.go

+ 1 - 1
models/login_source.go

@@ -677,7 +677,7 @@ func UserSignIn(username, password string) (*User, error) {
677 677
 	}
678 678
 
679 679
 	sources := make([]*LoginSource, 0, 5)
680
-	if err = x.UseBool().Find(&sources, &LoginSource{IsActived: true}); err != nil {
680
+	if err = x.Where("is_actived = ?", true).Find(&sources); err != nil {
681 681
 		return nil, err
682 682
 	}
683 683
 

+ 3 - 8
models/oauth2.go

@@ -56,7 +56,7 @@ var OAuth2DefaultCustomURLMappings = map[string]*oauth2.CustomURLMapping{
56 56
 // GetActiveOAuth2ProviderLoginSources returns all actived LoginOAuth2 sources
57 57
 func GetActiveOAuth2ProviderLoginSources() ([]*LoginSource, error) {
58 58
 	sources := make([]*LoginSource, 0, 1)
59
-	if err := x.UseBool().Find(&sources, &LoginSource{IsActived: true, Type: LoginOAuth2}); err != nil {
59
+	if err := x.Where("is_actived = ? and type = ?", true, LoginOAuth2).Find(&sources); err != nil {
60 60
 		return nil, err
61 61
 	}
62 62
 	return sources, nil
@@ -64,13 +64,8 @@ func GetActiveOAuth2ProviderLoginSources() ([]*LoginSource, error) {
64 64
 
65 65
 // GetActiveOAuth2LoginSourceByName returns a OAuth2 LoginSource based on the given name
66 66
 func GetActiveOAuth2LoginSourceByName(name string) (*LoginSource, error) {
67
-	loginSource := &LoginSource{
68
-		Name:      name,
69
-		Type:      LoginOAuth2,
70
-		IsActived: true,
71
-	}
72
-
73
-	has, err := x.UseBool().Get(loginSource)
67
+	loginSource := new(LoginSource)
68
+	has, err := x.Where("name = ? and type = ? and is_actived = ?", name, LoginOAuth2, true).Get(loginSource)
74 69
 	if !has || err != nil {
75 70
 		return nil, err
76 71
 	}