From a13bcd437d1d0d4ea40803a84a151caf265097f4 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Sun, 6 Oct 2024 15:30:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/user.go | 28 +++++++++++++++++++++++++--- proto/status.go | 1 + 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/handler/user.go b/handler/user.go index bc53b8d..f80d326 100644 --- a/handler/user.go +++ b/handler/user.go @@ -45,13 +45,35 @@ type SearchReq struct { Keyword string `json:"keyword" form:"keyword"` ID int `json:"id" form:"id"` } +type GetUserInfoReq struct { + ID int `json:"id" form:"id"` +} func GetUserInfo(c *gin.Context) { + var req_data GetUserInfoReq id, _ := c.Get("id") user_id := int(id.(float64)) - user := dao.FindUserByID2(user_id) - user.Password = "" //不返回密码 - c.JSON(200, gin.H{"code": proto.SuccessCode, "message": "success", "data": user}) + if err := c.ShouldBind(&req_data); err != nil { + var user dao.User + if req_data.ID == user_id { + user = dao.FindUserByID2(user_id) + user.Password = "" //不返回密码 + } else { + //判断当前用户是否有权限查看 + cur_user := dao.FindUserByID2(user_id) + if cur_user.Role == "admin" { + user = dao.FindUserByID2(req_data.ID) + user.Password = "" //不返回密码 + } else { + c.JSON(200, gin.H{"code": proto.PermissionDenied, "message": "无权查看", "data": "2"}) + return + } + } + c.JSON(200, gin.H{"code": proto.SuccessCode, "message": "success", "data": user}) + } else { + c.JSON(200, gin.H{"code": proto.ParameterError, "message": err, "data": "2"}) + return + } } func GetScanUUID(c *gin.Context) { diff --git a/proto/status.go b/proto/status.go index 6554ee8..ddd36af 100644 --- a/proto/status.go +++ b/proto/status.go @@ -20,6 +20,7 @@ const ( // 用户名密码相关错误码 UsernameOrPasswordError = 6 // 用户名或密码错误 UsernameExists = 7 // 用户名已存在 + PermissionDenied = 8 // 权限不足 // Redis相关错误码 RedisSetError = 8 // 设置redis错误