Add GoogleIdProvider.

This commit is contained in:
Yang Luo
2021-02-21 23:51:40 +08:00
parent e91fdca5e7
commit dfa77ab25d
7 changed files with 163 additions and 64 deletions

View File

@ -28,16 +28,8 @@ func (user *User) getId() string {
return fmt.Sprintf("%s/%s", user.Owner, user.Name)
}
func HasMail(application *Application, email string) string {
user := GetMail(application.Organization, email)
if user != nil {
return user.getId()
}
return ""
}
func HasGithub(application *Application, github string) string {
user := GetGithub(application.Organization, github)
func GetUserIdByField(application *Application, field string, value string) string {
user := GetUserByField(application.Organization, field, value)
if user != nil {
return user.getId()
}

View File

@ -15,6 +15,8 @@
package object
import (
"fmt"
"github.com/casdoor/casdoor/util"
"xorm.io/core"
)
@ -37,6 +39,7 @@ type User struct {
IsGlobalAdmin bool `json:"isGlobalAdmin"`
Github string `xorm:"varchar(100)" json:"github"`
Google string `xorm:"varchar(100)" json:"google"`
}
func GetGlobalUsers() []*User {
@ -121,23 +124,9 @@ func DeleteUser(user *User) bool {
return affected != 0
}
func GetMail(organizationName string, email string) *User {
user := User{Owner: organizationName, Email: email}
existed, err := adapter.engine.Get(&user)
if err != nil {
panic(err)
}
if existed {
return &user
} else {
return nil
}
}
func GetGithub(organizationName string, github string) *User {
user := User{Owner: organizationName, Github: github}
existed, err := adapter.engine.Get(&user)
func GetUserByField(organizationName string, field string, value string) *User {
user := User{Owner: organizationName}
existed, err := adapter.engine.Where(fmt.Sprintf("%s=?", field), value).Get(&user)
if err != nil {
panic(err)
}