Skip to content

Commit 4172861

Browse files
author
piexlmax
committed
后端增加 setSelfInfo 接口防止越权操作
1 parent 22c7157 commit 4172861

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

server/api/v1/system/sys_user.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,26 @@ func (b *BaseApi) SetUserInfo(c *gin.Context) {
286286
}
287287
}
288288

289+
// @Tags SysUser
290+
// @Summary 设置用户信息
291+
// @Security ApiKeyAuth
292+
// @accept application/json
293+
// @Produce application/json
294+
// @Param data body system.SysUser true "ID, 用户名, 昵称, 头像链接"
295+
// @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
296+
// @Router /user/SetSelfInfo [put]
297+
func (b *BaseApi) SetSelfInfo(c *gin.Context) {
298+
var user system.SysUser
299+
_ = c.ShouldBindJSON(&user)
300+
user.ID = utils.GetUserID(c)
301+
if err, ReqUser := userService.SetUserInfo(user); err != nil {
302+
global.GVA_LOG.Error("设置失败!", zap.Error(err))
303+
response.FailWithMessage("设置失败", c)
304+
} else {
305+
response.OkWithDetailed(gin.H{"userInfo": ReqUser}, "设置成功", c)
306+
}
307+
}
308+
289309
// @Tags SysUser
290310
// @Summary 获取用户信息
291311
// @Security ApiKeyAuth

server/router/system/sys_user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func (s *UserRouter) InitUserRouter(Router *gin.RouterGroup) {
1818
userRouter.POST("setUserAuthority", baseApi.SetUserAuthority) // 设置用户权限
1919
userRouter.DELETE("deleteUser", baseApi.DeleteUser) // 删除用户
2020
userRouter.PUT("setUserInfo", baseApi.SetUserInfo) // 设置用户信息
21+
userRouter.PUT("setSelfInfo", baseApi.SetSelfInfo) // 设置自身信息
2122
userRouter.POST("setUserAuthorities", baseApi.SetUserAuthorities) // 设置用户权限组
2223
userRouter.POST("resetPassword", baseApi.ResetPassword) // 设置用户权限组
2324
}

server/source/system/api.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ func (a *api) Initialize() error {
2424
{ApiGroup: "系统用户", Method: "DELETE", Path: "/user/deleteUser", Description: "删除用户"},
2525
{ApiGroup: "系统用户", Method: "POST", Path: "/user/register", Description: "用户注册(必选)"},
2626
{ApiGroup: "系统用户", Method: "POST", Path: "/user/getUserList", Description: "获取用户列表"},
27-
{ApiGroup: "系统用户", Method: "PUT", Path: "/user/setUserInfo", Description: "设置用户信息(必选)"},
27+
{ApiGroup: "系统用户", Method: "PUT", Path: "/user/setUserInfo", Description: "设置用户信息"},
28+
{ApiGroup: "系统用户", Method: "PUT", Path: "/user/setSelfInfo", Description: "设置自身信息(必选)"},
2829
{ApiGroup: "系统用户", Method: "GET", Path: "/user/getUserInfo", Description: "获取自身信息(必选)"},
2930
{ApiGroup: "系统用户", Method: "POST", Path: "/user/setUserAuthorities", Description: "设置权限组"},
3031
{ApiGroup: "系统用户", Method: "POST", Path: "/user/changePassword", Description: "修改密码(建(选择)"},

server/source/system/casbin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func (c *casbin) Initialize() error {
4848

4949
{PType: "p", V0: "888", V1: "/user/getUserInfo", V2: "GET"},
5050
{PType: "p", V0: "888", V1: "/user/setUserInfo", V2: "PUT"},
51+
{PType: "p", V0: "888", V1: "/user/setSelfInfo", V2: "PUT"},
5152
{PType: "p", V0: "888", V1: "/user/getUserList", V2: "POST"},
5253
{PType: "p", V0: "888", V1: "/user/deleteUser", V2: "DELETE"},
5354
{PType: "p", V0: "888", V1: "/user/changePassword", V2: "POST"},

0 commit comments

Comments
 (0)