Skip to content

Commit

Permalink
feat(profile): get third party bind status
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxtuneLee committed Jul 28, 2024
1 parent e0f0eee commit b4f7524
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
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
}

0 comments on commit b4f7524

Please sign in to comment.