Login

This commit is contained in:
2024-02-02 00:53:22 +08:00
parent 434773976f
commit 19e1775476
15 changed files with 236 additions and 165 deletions

View File

@ -13,24 +13,26 @@ import (
)
type PassportUserinfo struct {
Sub uint `json:"sub"`
Email string `json:"email"`
Picture string `json:"picture"`
PreferredUsernames string `json:"preferred_usernames"`
Sub string `json:"sub"`
Email string `json:"email"`
Picture string `json:"picture"`
PreferredUsername string `json:"preferred_username"`
}
func LinkAccount(userinfo PassportUserinfo) (models.Account, error) {
id, _ := strconv.Atoi(userinfo.Sub)
var account models.Account
if err := database.C.Where(&models.Account{
ExternalID: userinfo.Sub,
ExternalID: uint(id),
}).First(&account).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
account = models.Account{
Name: userinfo.PreferredUsernames,
Name: userinfo.PreferredUsername,
Avatar: userinfo.Picture,
EmailAddress: userinfo.Email,
PowerLevel: 0,
ExternalID: userinfo.Sub,
ExternalID: uint(id),
}
return account, database.C.Save(&account).Error
}