获取用户信息功能
This commit is contained in:
parent
414bf1589a
commit
a13bcd437d
|
|
@ -45,13 +45,35 @@ type SearchReq struct {
|
||||||
Keyword string `json:"keyword" form:"keyword"`
|
Keyword string `json:"keyword" form:"keyword"`
|
||||||
ID int `json:"id" form:"id"`
|
ID int `json:"id" form:"id"`
|
||||||
}
|
}
|
||||||
|
type GetUserInfoReq struct {
|
||||||
|
ID int `json:"id" form:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
func GetUserInfo(c *gin.Context) {
|
func GetUserInfo(c *gin.Context) {
|
||||||
|
var req_data GetUserInfoReq
|
||||||
id, _ := c.Get("id")
|
id, _ := c.Get("id")
|
||||||
user_id := int(id.(float64))
|
user_id := int(id.(float64))
|
||||||
user := dao.FindUserByID2(user_id)
|
if err := c.ShouldBind(&req_data); err != nil {
|
||||||
user.Password = "" //不返回密码
|
var user dao.User
|
||||||
c.JSON(200, gin.H{"code": proto.SuccessCode, "message": "success", "data": 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) {
|
func GetScanUUID(c *gin.Context) {
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ const (
|
||||||
// 用户名密码相关错误码
|
// 用户名密码相关错误码
|
||||||
UsernameOrPasswordError = 6 // 用户名或密码错误
|
UsernameOrPasswordError = 6 // 用户名或密码错误
|
||||||
UsernameExists = 7 // 用户名已存在
|
UsernameExists = 7 // 用户名已存在
|
||||||
|
PermissionDenied = 8 // 权限不足
|
||||||
|
|
||||||
// Redis相关错误码
|
// Redis相关错误码
|
||||||
RedisSetError = 8 // 设置redis错误
|
RedisSetError = 8 // 设置redis错误
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue