从零到企业级SSM电商项目实战教程(二十)忘记密码中的重置密码功能开发

UserController.java

/*
 * @Description: 忘记密码中的重置密码
 *
 * @auther: Geekerstar(jikewenku.com)
 * @date: 2018/6/22 15:30
 * @param: 
 * @return: 
 */

@RequestMapping(value = "forget_reset_password.do",method = RequestMethod.GET)
@ResponseBody
public ServerResponse forgetRestPassword(String username,String passowrdNew,String forgetToken){
    return iUserService.forgetResetPassword(username,passowrdNew,forgetToken);
}

IUserService.java

ServerResponse forgetResetPassword(String username,String passwordNew,String forgetToken);

UserServiceImpl.java

public ServerResponse forgetResetPassword(String username,String passwordNew,String forgetToken){
    if(StringUtils.isBlank(forgetToken)){
        return ServerResponse.createByErrorMessgae("参数错误,token需要传递");
    }
    ServerResponse validResponse = this.checkValid(username,Const.USERNAME);
    if(validResponse.isSuccess()){
        //用户不存在
        return ServerResponse.createByErrorMessgae("用户不存在");
    }
    String token = TokenCache.getKey(TokenCache.TOKEN_PREFIX+username);
    if(StringUtils.isBlank(token)){
        return ServerResponse.createByErrorMessgae("token无效或者过期");
    }
    if(StringUtils.equals(forgetToken,token)){
        String md5Password = MD5Util.MD5EncodeUtf8(passwordNew);
        int rowCount = userMapper.updatePasswordByUsername(username,passwordNew);

        if(rowCount > 0){
            return ServerResponse.createBySuccessMessage("修改密码成功");
        }
    }else{
        return ServerResponse.createByErrorMessgae("token错误,请重新获取重置密码的token");
    }
    return ServerResponse.createByErrorMessgae("修改密码失败");

}

UserMapper.java

int updatePasswordByUsername(@Param("username") String username,@Param("passwordNew") String passwordNew)

UserMapper.xml


  update mmall_user
  set password = #{passwordNew},update_time = now()
  UPDATE username = #{username}

TockenCache.java

public static final String TOKEN_PREFIX = "token_";
本站所有文章均来自互联网,如有侵权,请联系站长删除。极客文库 » 从零到企业级SSM电商项目实战教程(二十)忘记密码中的重置密码功能开发
分享到:
赞(0)

评论抢沙发

评论前必须登录!