第三方信息每次登录更新
This commit is contained in:
parent
84231a5fe8
commit
aab8b65f99
14
dao/user.go
14
dao/user.go
|
|
@ -266,3 +266,17 @@ func DeleteThirdPartyLoginByID(id int, userID int) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 更新第三方登录用户信息
|
||||
func UpdateThirdPartyUserInfoByThirdPartyID(thirdPartyID int, thirdPartyPlatform, thirdPartyUserName, thirdPartyUserAvatar, thirdPartyUserUrl string) error {
|
||||
db2 := DB
|
||||
if proto.Config.SERVER_SQL_LOG {
|
||||
db2 = DB.Debug()
|
||||
}
|
||||
|
||||
res := db2.Model(&ThirdPartyUserInfo{}).Where("third_party_id = ? ", thirdPartyID).Updates(ThirdPartyUserInfo{ThirdPartyUserName: thirdPartyUserName, ThirdPartyUserAvatar: thirdPartyUserAvatar, ThirdPartyUserUrl: thirdPartyUserUrl, ThirdPartyPlatform: thirdPartyPlatform})
|
||||
if res.Error != nil {
|
||||
return res.Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -223,6 +223,7 @@ func DoGithubCallBack(state *proto.ThirdPartyLoginState, code string) {
|
|||
return
|
||||
}
|
||||
log.Println("get github user info:", userInfo)
|
||||
|
||||
var thirdPartyLoginStatus proto.ThirdPartyLoginStatus
|
||||
thirdPartyLoginStatus.Type = state.Platform
|
||||
HandleThirdPartyLoginStatus(state, &thirdPartyLoginStatus, &userInfo) //处理第三方登录状态
|
||||
|
|
@ -394,6 +395,11 @@ func HandleThirdPartyLoginStatus(state *proto.ThirdPartyLoginState, thirdPartyLo
|
|||
log.Println("DoGithubCallBack state type error:", state.Type)
|
||||
thirdPartyLoginStatus.Status = proto.ParameterError //参数错误
|
||||
}
|
||||
//更新userInfo到数据库
|
||||
err := dao.UpdateThirdPartyUserInfoByThirdPartyID(userInfo.UserID, state.Platform, userInfo.LoginUserName, userInfo.AvatarUrl, userInfo.Url)
|
||||
if err != nil {
|
||||
log.Println("update third party user info error:", err)
|
||||
}
|
||||
}
|
||||
|
||||
func DoThirdPartyCallBack(state *proto.ThirdPartyLoginState, code string) {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"StuAcaWorksAI/proto"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
|
@ -64,5 +65,11 @@ func GetGitHubUserInfo(accessToken string) (proto.GitHubUserInfo, error) {
|
|||
return resp, err
|
||||
}
|
||||
err = json.Unmarshal(data, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if resp.UserID == 0 {
|
||||
return resp, errors.New("获取用户信息失败,请检查access_token是否正确")
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue