diff --git a/dao/user.go b/dao/user.go index c1e77fa..5530e4a 100644 --- a/dao/user.go +++ b/dao/user.go @@ -258,3 +258,11 @@ func DeleteThirdPartyUserInfoByID(id int) int { } return id } + +func DeleteThirdPartyLoginByID(id int, userID int) error { + res := DB.Where("id = ? and user_id = ?", id, userID).Delete(&ThirdPartyUserInfo{}) + if res.Error != nil { + return res.Error + } + return nil +} diff --git a/handler/user.go b/handler/user.go index 1ded230..acaae34 100644 --- a/handler/user.go +++ b/handler/user.go @@ -32,6 +32,8 @@ func SetUpUserGroup(router *gin.Engine) { userGroup.GET("/oAuth", LoginOAuth) //第三方登录 userGroup.GET("/oAuth_uuid", GetOAuthUUID) userGroup.POST("/statistic", GetUserStatistic) + userGroup.POST("/third_party_login_list", GetThirdPartyLoginList) //获取绑定的第三方登录账号 + userGroup.DELETE("/delete_third_party_login", DeleteThirdPartyLogin) //删除绑定的第三方登录账号 } type RLReq struct { @@ -586,3 +588,37 @@ func GetOAuthUUID(c *gin.Context) { resp.Data = uuid c.JSON(200, resp) } + +func GetThirdPartyLoginList(c *gin.Context) { + var resp proto.GenerateResp + //获取用户信息 + id, _ := c.Get("id") + userId := int(id.(float64)) + thirdPartyLoginList := dao.FindThirdPartyUserInfoByUserID(userId) + resp.Code = proto.SuccessCode + resp.Message = "success" + resp.Data = thirdPartyLoginList + c.JSON(200, resp) +} + +func DeleteThirdPartyLogin(c *gin.Context) { + var resp proto.GenerateResp + //获取用户信息 + id, _ := c.Get("id") + userId := int(id.(float64)) + var req proto.DeleteThirdPartyLoginReq + if err := c.ShouldBind(&req); err == nil { + err2 := dao.DeleteThirdPartyLoginByID(req.ID, userId) + if err2 != nil { + resp.Code = proto.OperationFailed + resp.Message = "删除失败!请检查是否属于或者已被删除" + } else { + resp.Code = proto.SuccessCode + resp.Message = "success" + } + } else { + resp.Code = proto.ParameterError + resp.Message = "error" + } + c.JSON(200, resp) +} diff --git a/proto/user_req.go b/proto/user_req.go index bcad560..2a39b8b 100644 --- a/proto/user_req.go +++ b/proto/user_req.go @@ -118,3 +118,7 @@ type ResponseOAuth struct { Email string `json:"email" form:"email"` Token string `json:"token" form:"token"` } + +type DeleteThirdPartyLoginReq struct { + ID int `json:"id" form:"id"` //用户第三方登录信息表ID +}