获取用户信息功能

This commit is contained in:
junleea 2024-10-06 15:30:38 +08:00
parent 414bf1589a
commit a13bcd437d
2 changed files with 26 additions and 3 deletions

View File

@ -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) {

View File

@ -20,6 +20,7 @@ const (
// 用户名密码相关错误码
UsernameOrPasswordError = 6 // 用户名或密码错误
UsernameExists = 7 // 用户名已存在
PermissionDenied = 8 // 权限不足
// Redis相关错误码
RedisSetError = 8 // 设置redis错误