Add github oauth.

This commit is contained in:
Yang Luo
2021-02-14 00:22:24 +08:00
parent ea09beffe2
commit c81118feff
14 changed files with 419 additions and 8 deletions

View File

@ -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 ""
}

View File

@ -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
}