修改密码接口改动
This commit is contained in:
parent
0f31485d8c
commit
77c6ab6f44
@ -213,15 +213,15 @@ func (r *AdminUser) PutUserPassword(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userId := c.GetInt64("UserId")
|
adminUserId := c.GetInt64("UserId")
|
||||||
if userId == 0 {
|
if adminUserId == 0 {
|
||||||
responses.FailWithMessage("用户错误", c)
|
responses.FailWithMessage("用户错误", c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 业务处理
|
// 业务处理
|
||||||
userService := service.AdminUserService{}
|
userService := service.AdminUserService{}
|
||||||
_, err := userService.PutUserPassword(userId, UserRequest.PutUserPassword)
|
_, err := userService.PutUserPassword(adminUserId, UserRequest.PutUserPassword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
responses.FailWithMessage(err.Error(), c)
|
responses.FailWithMessage(err.Error(), c)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -62,4 +62,5 @@ type PutUser struct {
|
|||||||
type PutUserPassword struct {
|
type PutUserPassword struct {
|
||||||
Password string `json:"password" form:"password" validate:"required" label:"原密码"`
|
Password string `json:"password" form:"password" validate:"required" label:"原密码"`
|
||||||
NewPassword string `json:"new_password" form:"new_password" validate:"required" label:"新密码"`
|
NewPassword string `json:"new_password" form:"new_password" validate:"required" label:"新密码"`
|
||||||
|
UserId string `json:"user_id" form:"user_id" validate:"required" label:"用户id"`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -325,11 +325,37 @@ func (r *AdminUserService) PutUser(c *gin.Context, requestUserId int64, putUserR
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PutUserPassword 修改用户密码
|
// PutUserPassword 修改用户密码
|
||||||
func (r *AdminUserService) PutUserPassword(requestUserId int64, putUserPasswordRequest requests.PutUserPassword) (bool, error) {
|
func (r *AdminUserService) PutUserPassword(adminUserId int64, putUserPasswordRequest requests.PutUserPassword) (bool, error) {
|
||||||
adminUserDao := dao.AdminUserDao{}
|
adminUserDao := dao.AdminUserDao{}
|
||||||
|
|
||||||
|
// 将 id 转换为 int64 类型
|
||||||
|
userId, err := strconv.ParseInt(putUserPasswordRequest.UserId, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return false, errors.New("错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取当前登录用户数据
|
||||||
|
adminUser, err := adminUserDao.GetAdminUserFirstById(adminUserId)
|
||||||
|
if err != nil || adminUser == nil {
|
||||||
|
return false, errors.New("用户数据错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取登录用户角色数据
|
||||||
|
adminRoleDao := dao.AdminRoleDao{}
|
||||||
|
adminRole, err := adminRoleDao.GetAdminRoleFirstById(adminUser.RoleID)
|
||||||
|
if err != nil || adminRole == nil {
|
||||||
|
return false, errors.New("角色错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 非超级管理员无法修改其他用户数据
|
||||||
|
if adminRole.IsAdmin != 1 {
|
||||||
|
if adminUserId != userId {
|
||||||
|
return false, errors.New("无法修改他人密码")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 获取需修改用户数据
|
// 获取需修改用户数据
|
||||||
adminUser, err := adminUserDao.GetAdminUserFirstById(requestUserId)
|
adminUser, err = adminUserDao.GetAdminUserFirstById(userId)
|
||||||
if err != nil || adminUser == nil {
|
if err != nil || adminUser == nil {
|
||||||
return false, errors.New("用户数据错误")
|
return false, errors.New("用户数据错误")
|
||||||
}
|
}
|
||||||
@ -387,7 +413,7 @@ func (r *AdminUserService) PutUserPassword(requestUserId int64, putUserPasswordR
|
|||||||
// 修改角色
|
// 修改角色
|
||||||
data := make(map[string]interface{})
|
data := make(map[string]interface{})
|
||||||
data["password"] = newPasswordString
|
data["password"] = newPasswordString
|
||||||
err = adminUserDao.EditAdminUserById(tx, requestUserId, data)
|
err = adminUserDao.EditAdminUserById(tx, userId, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, errors.New("修改失败")
|
return false, errors.New("修改失败")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user