修改密码后台,对应前面的修改密码前端

首先在修改密码之前需要先验证一下用户输入的原密码是否正确

    /**
     * 验证原密码是否正确
     * @param userId
     * @param oldPassword
     * @return
     */
    @ApiOperation(value = "用户管理-验证原密码", notes = "用户管理-验证原密码")
    @PostMapping("/user/check/password")
    public ResultBody checkPassword( @RequestParam(value = "userId") Long userId,
                                     @RequestParam(value = "oldPassword") String oldPassword)
    {
        QueryWrapper<BaseUser> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().eq(BaseUser::getUserId,userId );
        BaseUser user = baseAccountService.getOne(queryWrapper);
        boolean matches = passwordEncoder.matches(oldPassword,user.getPassword());

        return ResultBody.ok().data(matches);
    }

然后就是最重要的密码修改了

    /**
     * 修改用户密码
     *
     * @param userId
     * @param password
     * @return
     */
    @ApiOperation(value = "用户管理-修改用户密码", notes = "用户管理-修改用户密码")
    @PostMapping("/user/update/password")
    public ResultBody updatePassword(
            @RequestParam(value = "userId") Long userId,
            @RequestParam(value = "password") String password
    ) {
        baseUserService.updatePassword(userId, password);
        return ResultBody.ok();
    }

 

posted on 2022-04-15 17:55  一往无前!  阅读(242)  评论(0编辑  收藏  举报