mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 19:40:19 +08:00
Add github oauth.
This commit is contained in:
@ -21,3 +21,19 @@ func CheckUserLogin(userId string, password string) string {
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func HasMail(email string) string {
|
||||
user := GetMail(email)
|
||||
if user != nil {
|
||||
return user.Email
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func HasGithub(github string) string {
|
||||
user := GetGithub(github)
|
||||
if user != nil {
|
||||
return user.Github
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ type User struct {
|
||||
Avatar string `xorm:"varchar(100)" json:"avatar"`
|
||||
Email string `xorm:"varchar(100)" json:"email"`
|
||||
Phone string `xorm:"varchar(100)" json:"phone"`
|
||||
|
||||
Github string `xorm:"varchar(100)" json:"github"`
|
||||
}
|
||||
|
||||
func GetGlobalUsers() []*User {
|
||||
@ -114,3 +116,40 @@ func DeleteUser(user *User) bool {
|
||||
|
||||
return affected != 0
|
||||
}
|
||||
|
||||
func GetMail(email string) *User {
|
||||
user := User{Email: email}
|
||||
existed, err := adapter.engine.Get(&user)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if existed {
|
||||
return &user
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetGithub(github string) *User {
|
||||
user := User{Github: github}
|
||||
existed, err := adapter.engine.Get(&user)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if existed {
|
||||
return &user
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func LinkUserAccount(user, field, value string) bool {
|
||||
affected, err := adapter.engine.Table(new(User)).ID(user).Update(map[string]interface{}{field: value})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return affected != 0
|
||||
}
|
||||
|
Reference in New Issue
Block a user