Esempio n. 1
0
  /**
   * 找回密时,根据 手机号和 验证码 核查phonenumber的验证码是否正确 是否匹配 需要验证生成验证码的时间是否超时
   *
   * @param phonenumber captchacode
   * @return {@value} url: /api/v1/phoneCollect/checkPhonenumberInFindPasswd
   *     <p>找回密时,核实手机和验证码是否匹配 url :
   *     http://localhost/lr/api/v1/phoneCollect/checkPhonenumberInFindPasswd?phonenumber=13662127862&captchacode=3361
   *     <p>0 验证码超时: 需要重新获取验证码 调用这个
   *     http://localhost/lr/api/v1/phoneCollect/genCaptchacodeByPhoneInFindPasswd?phonenumber={phonemum}
   *     http://localhost/lr/api/v1/phoneCollect/genCaptchacodeByPhoneInFindPasswd?phonenumber=13662127862
   *     即本类下的 genCaptchacodeByPhoneInFindPasswd()方法
   */
  @RequestMapping(value = "/checkPhonenumberInFindPasswd", method = RequestMethod.GET)
  @ResponseBody
  public GeneralResponse checkPhonenumberInFindPasswd(
      @RequestParam("phonenumber") String phonenum,
      @RequestParam("captchacode") String captchacode) {
    GeneralResponse gp = new GeneralResponse();
    int returncode = 0;
    int errcode = -1;
    String errmsg = "比对不成功";
    int successcode = 1;
    String successmsg = "比对OK_";
    int overtimecode = 0;
    String overtimemsg = "验证码超时,需要重新获取验证码";
    int err2code = -2;
    String err2msg = "未知错误";
    int err3code = -3;
    String err3msg = "错误:没有找到手机号对应的用户";

    returncode = userPhoneTools.checkPhoneInFindPasswd(phonenum, captchacode);

    if (returncode == errcode) {
      gp.setRetCode(errcode);
      gp.setRetInfo(errmsg);
    } else if (returncode == successcode) {
      /** 1.生成临时验证码, 2.找到手机号对应的User, 存储入临时验证码 3.返回临时验证码,临时验证码存在RetInfo 中,显示。 */
      String uuid = UUID.randomUUID().toString();
      String tempToken =
          uuid.substring(0, 8)
              + uuid.substring(9, 13)
              + uuid.substring(14, 18)
              + uuid.substring(19, 23)
              + uuid.substring(24);
      User u = accountService.findUserByPhonenumber(phonenum);
      if (u == null) {
        gp.setRetCode(err3code);
        gp.setRetInfo(err3msg);
      } else {
        u.setTempToken(tempToken);
        u.setTempTokenDate(new Date());
        accountService.updateUser(u);
        successmsg = successmsg + "令牌是:" + tempToken;
        gp.setRetCode(successcode);
        gp.setRetInfo(successmsg);
      }
    } else if (returncode == overtimecode) {
      gp.setRetCode(overtimecode);
      gp.setRetInfo(overtimemsg);
    } else {
      gp.setRetCode(err2code);
      gp.setRetInfo(err2msg);
    }

    return gp;
  }
Esempio n. 2
0
  /**
   * 短信登录时,根据 手机号和 验证码 核查phonenumber的验证码是否正确 是否匹配 需要验证生成验证码的时间是否超时 生成新的登录凭证,更新之前的登录凭证
   *
   * @param phonenumber captchacode
   * @return {@value} url: /api/v1/phoneCollect/checkPhonenumberInSmsLogin
   *     <p>短信登录时,核实手机和验证码是否匹配 url :
   *     http://localhost/lr/api/v1/phoneCollect/checkPhonenumberInSmsLogin?phonenumber=13662127862&captchacode=3361
   *     <p>0 验证码超时: 需要重新获取验证码 调用这个
   *     http://localhost/lr/api/v1/phoneCollect/genCaptchacodeByPhoneInSmsLogin?phonenumber={phonemum}
   *     http://localhost/lr/api/v1/phoneCollect/genCaptchacodeByPhoneInSmsLogin?phonenumber=13662127862
   *     即本类下的 genCaptchacodeByPhoneInSmsLogin()方法
   */
  @RequestMapping(value = "/checkPhonenumberInSmsLogin", method = RequestMethod.GET)
  @ResponseBody
  public GeneralResponse checkPhonenumberInSmsLogin(
      @RequestParam("phonenumber") String phonenum,
      @RequestParam("captchacode") String captchacode) {
    GeneralResponse gp = new GeneralResponse();
    int returncode = 0;
    int errcode = -1;
    String errmsg = "比对不成功";
    int successcode = 1;
    // String successmsg = "比对OK_";
    int overtimecode = 0;
    String overtimemsg = "验证码超时,需要重新获取验证码";
    int err2code = -2;
    String err2msg = "未知错误";
    int err3code = -3;
    String err3msg = "错误:没有找到手机号对应的用户";

    returncode = userPhoneTools.checkPhoneInFindPasswd(phonenum, captchacode);

    if (returncode == errcode) {
      gp.setRetCode(errcode);
      gp.setRetInfo(errmsg);
    } else if (returncode == successcode) {
      /** 1.生成短信登录令牌 2.找到手机号对应的User, 存储入短信登录令牌 3.返回短信登录令牌,临时验证码存在RetInfo中,显示。 */
      String uuid = UUID.randomUUID().toString();
      String smsToken1 =
          uuid.substring(0, 8)
              + uuid.substring(9, 13)
              + uuid.substring(14, 18)
              + uuid.substring(19, 23)
              + uuid.substring(24);
      String uuid2 = UUID.randomUUID().toString();
      String smsToken2 =
          uuid2.substring(0, 8)
              + uuid2.substring(9, 13)
              + uuid2.substring(14, 18)
              + uuid2.substring(19, 23)
              + uuid2.substring(24);
      String smsToken = smsToken1 + smsToken2;
      User u = accountService.findUserByPhonenumber(phonenum);
      if (u == null) {
        // 未找到用户
        gp.setRetCode(err3code);
        gp.setRetInfo(err3msg);
      } else {
        // u.setTempToken(tempToken);
        // u.setTempTokenDate(new Date());
        u.setSmstoken(smsToken);
        u.setSmsTokenDate(new Date());
        Integer tokenshowtimes = u.getSmstokenshowtimes();
        accountService.updateUser(u);
        // successmsg =smsToken;
        gp.setRetCode(successcode);
        gp.setRetInfo(smsToken); // 返回消息放置单一令牌
      }
    } else if (returncode == overtimecode) {
      gp.setRetCode(overtimecode);
      gp.setRetInfo(overtimemsg);
    } else {
      gp.setRetCode(err2code);
      gp.setRetInfo(err2msg);
    }

    return gp;
  }