Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(profile): get third party bind status #99

Merged
merged 1 commit into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/api/v1/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,25 @@ func DealCensorRes(ctx *gin.Context) {
}
ctx.JSON(http.StatusOK, result.Success(nil))
}

// BindStatus : get third party login bind status
func BindStatus(ctx *gin.Context) {
token := ctx.GetHeader("TOKEN")
if token == "" {
ctx.JSON(http.StatusBadRequest, result.Failed(result.RequestParamError))
return
}
uid, err := util.IdentityFromToken(token, model.LOGIN_TOKEN_SUB)
if uid == "" || err != nil {
controllerLogger.Errorln("Can`t get username by token", err)
ctx.JSON(http.StatusOK, result.Failed(result.TokenError))
return
}
bindList, serErr := service.GetBindList(uid)
if serErr != nil {
controllerLogger.Errorln("GetBindStatus service wrong", serErr)
ctx.JSON(http.StatusOK, result.Failed(result.HandleError(serErr)))
return
}
ctx.JSON(http.StatusOK, result.Success(bindList))
}
11 changes: 11 additions & 0 deletions src/model/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,14 @@ func UpsetOauthInfo(oauthInfo OAuth2Info) {

Db.Exec(stmt, oauthInfo.Client, oauthInfo.Info, oauthInfo.OauthID, oauthInfo.UserID)
}

// GetOauthBindStatusByUID get oauth bind status by uid
func GetOauthBindStatusByUID(uid string) ([]string, error) {
var oauthBindStatus []string
err := Db.Table("oauth2_info").Where("user_id = ?", uid).Pluck("client", &oauthBindStatus).Error
if err != nil {
log.Errorf("model.getOauthBindStatusByUID ::: %s", err.Error())
return nil, result.InternalErr
}
return oauthBindStatus, nil
}
1 change: 1 addition & 0 deletions src/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func InitRouter() *gin.Engine {
profile := apiV1.Group("/profile")
{
profile.GET("/getProfile", v1.GetProfile)
profile.GET("/bindStatus", v1.BindStatus)
profile.POST("/changeProfile", v1.ChangeProfile)
profile.POST("/uploadAvatar", v1.UploadAvatar)
profile.POST("/changeEmail", v1.ChangeEmail)
Expand Down
10 changes: 10 additions & 0 deletions src/service/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,13 @@ func DealWithFrozenImage(ctx *gin.Context, checkRes *model.CheckRes) error {
}
return nil
}

// GetBindList get bind list by uid
func GetBindList(uid string) ([]string, error) {
binds, err := model.GetOauthBindStatusByUID(uid)
if err != nil {
serviceLogger.Errorln("GetBindList Err,ErrMsg:", err)
return nil, err
}
return binds, nil
}
Loading