从零到企业级SSM电商项目实战教程(二十一)登录状态下重置密码功能开发

UserController.java

/*
 * @Description: 登录状态的重置密码
 *
 * @auther: Geekerstar(jikewenku.com)
 * @date: 2018/6/22 15:40
 * @param: 
 * @return: 
 */
@RequestMapping(value = "reset_password.do",method = RequestMethod.GET)
@ResponseBody
public ServerResponse resetPassword(HttpSession session,String passwordOld,String passwordNew){
    User user = (User)session.getAttribute(Const.CURRENT_USER);
    if(user == null){
        return ServerResponse.createByErrorMessgae("用户未登录");
    }
    return iUserService.resetPassword(passwordOld,passwordNew,user);
}

IUserService.java

ServerResponse resetPassword(String passwordOld,String passwordNew,User user);

UserServiceImpl.java

public ServerResponse resetPassword(String passwordOld,String passwordNew,User user){
    //防止横向越权,要检验一下这个用户的旧密码,一定要指定是这个用户,因我们会查询一个count(1),如果不指定id,那么结构就是true那count>0;
    int resultCount = userMapper.checkPassword(MD5Util.MD5EncodeUtf8(passwordOld),user.getId());
    if(resultCount == 0){
        return ServerResponse.createByErrorMessgae("旧密码错误");
    }

    user.setPassword(MD5Util.MD5EncodeUtf8(passwordNew));
    int updateCount = userMapper.updateByPrimaryKeySelective(user);
    if(updateCount > 0){
        return ServerResponse.createBySuccessMessage("密码更新成功");
    }
    return ServerResponse.createByErrorMessgae("密码更新失败");
}

UserMapper.java

int checkPassword(@Param(value = "password") String password,@Param("userId") Integer userId);

UserMapper.xml


本站所有文章均来自互联网,如有侵权,请联系站长删除。极客文库 » 从零到企业级SSM电商项目实战教程(二十一)登录状态下重置密码功能开发
分享到:
赞(0)

评论抢沙发

评论前必须登录!