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)
|
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 {
|
if userId := cast.ToInt64(req.UserId); userId != 0 {
|
||||||
userinfo, err = dao.NewUser().GetUserId(userId)
|
userinfo, err = dao.NewUser().GetUserId(userId)
|
||||||
if userinfo == nil {
|
if userinfo == nil {
|
||||||
|
|
@ -41,7 +42,7 @@ func (a *User) Update(ctx *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
userService := service.NewUser(userinfo)
|
userService := service.NewUser(userinfo)
|
||||||
userService.Update(req)
|
userService.Update(req, loginUser.ID)
|
||||||
ctx.JSON(http.StatusOK, response.NewRspOk())
|
ctx.JSON(http.StatusOK, response.NewRspOk())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,12 @@ type UserCreate struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserUpdate struct {
|
type UserUpdate struct {
|
||||||
UserId string `json:"id"`
|
UserId string `json:"id"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
Role string `json:"role"`
|
OldPassword string `json:"old_password"`
|
||||||
Status string `json:"status"`
|
Role string `json:"role"`
|
||||||
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserDelete struct {
|
type UserDelete struct {
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ func (a *User) Create(req request.UserCreate) int64 {
|
||||||
return m.ID
|
return m.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *User) Update(req request.UserUpdate) {
|
func (a *User) Update(req request.UserUpdate, operatorID int64) {
|
||||||
var user *model.User
|
var user *model.User
|
||||||
var err error
|
var err error
|
||||||
user, err = dao.NewUser().AccountGet(a.user.Account)
|
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)
|
req.Password = strings.TrimSpace(req.Password)
|
||||||
if req.Password != "" {
|
if req.Password != "" {
|
||||||
checkPassword(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)
|
user.Password = goutil.Md5(req.Password + model.Salt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue