feat: modify password verify old password 2
This commit is contained in:
parent
a18fa887cf
commit
b550a66ecf
|
|
@ -32,7 +32,8 @@ func (a *User) Update(ctx *gin.Context) {
|
|||
err2.ParamErr("<user update>", err)
|
||||
}
|
||||
// 获取当前登录用户的账号
|
||||
userinfo := service.NewToken().UserInfo(ctx.GetHeader("token"))
|
||||
loginUser := service.NewToken().UserInfo(ctx.GetHeader("token"))
|
||||
userinfo := loginUser
|
||||
if userId := cast.ToInt64(req.UserId); userId != 0 {
|
||||
userinfo, err = dao.NewUser().GetUserId(userId)
|
||||
if userinfo == nil {
|
||||
|
|
@ -41,7 +42,7 @@ func (a *User) Update(ctx *gin.Context) {
|
|||
}
|
||||
|
||||
userService := service.NewUser(userinfo)
|
||||
userService.Update(req)
|
||||
userService.Update(req, loginUser.ID)
|
||||
ctx.JSON(http.StatusOK, response.NewRspOk())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ type UserUpdate struct {
|
|||
UserId string `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
OldPassword string `json:"old_password"`
|
||||
Role string `json:"role"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ func (a *User) Create(req request.UserCreate) int64 {
|
|||
return m.ID
|
||||
}
|
||||
|
||||
func (a *User) Update(req request.UserUpdate) {
|
||||
func (a *User) Update(req request.UserUpdate, operatorID int64) {
|
||||
var user *model.User
|
||||
var err error
|
||||
user, err = dao.NewUser().AccountGet(a.user.Account)
|
||||
|
|
@ -119,6 +119,12 @@ func (a *User) Update(req request.UserUpdate) {
|
|||
req.Password = strings.TrimSpace(req.Password)
|
||||
if req.Password != "" {
|
||||
checkPassword(req.Password)
|
||||
if user.ID == operatorID {
|
||||
oldPassword := strings.TrimSpace(req.OldPassword)
|
||||
if user.Password != goutil.Md5(oldPassword+model.Salt) {
|
||||
err2.ParamErr("旧密码错误")
|
||||
}
|
||||
}
|
||||
user.Password = goutil.Md5(req.Password + model.Salt)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue