From 5aa47993c00301f2819574dbf37c03bf64eeb80f Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Sun, 27 Apr 2025 11:26:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E4=BF=A1=E6=81=AF=E6=9F=A5=E8=AF=A2=E4=B8=8E?= =?UTF-8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/user.go | 8 ++++++++ handler/user.go | 36 ++++++++++++++++++++++++++++++++++++ proto/user_req.go | 4 ++++ 3 files changed, 48 insertions(+) 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 +}