コード例 #1
0
  @SuppressWarnings("unused")
  @Override
  public Json resetPWD(YztRegistor registor) {
    Json json = new Json();
    if (!registor.getIsMobile().isEmpty()
        && !registor.getIsVerifyCode().isEmpty()
        && !registor.getIsPassword().isEmpty()) {
      Example example1 = new Example(YztUserinfo.class);
      Example.Criteria criteria1 = example1.createCriteria();
      criteria1.andEqualTo("account", registor.getIsMobile());
      // criteria1.andEqualTo("status",1);//0,非禁用 用户,1-禁用
      List<YztUserinfo> list1 = selectByExample(example1);

      Example example = new Example(YztRegistor.class);
      Example.Criteria criteria = example.createCriteria();
      criteria.andEqualTo("isMobile", registor.getIsMobile());
      // criteria.andEqualTo("isVerifyCode", registor.getIsVerifyCode());
      List<YztRegistor> list = registService.selectByExample(example);
      for (YztUserinfo userinfo : list1) {
        if (userinfo.getStatus() != null && userinfo.getStatus() == 1) {
          json.setSuccess(false);
          json.setMsg(YztConstant.LOGIN_ACCOUNT_BAN);
        } else {
          if (list.size() > 0) { // 已经发送过验证码,对比过期时间,如果过期,重新发送验证码。如果没过期提示查看手机验证码
            for (YztRegistor reg : list) {
              // reg.getOverdueTime();
              if (reg.getStatus() != null && reg.getStatus() == 1) {
                // json.setSuccess(false);
                // json.setMsg(YztConstant.REGIST_SECOND);
                // }else{
                Calendar cal = (GregorianCalendar) Calendar.getInstance();
                cal.setTime(new Date());
                GregorianCalendar endCalendar = (GregorianCalendar) Calendar.getInstance();
                endCalendar.setTime(reg.getOverdueTime());
                // if(cal.compareTo(endCalendar)>0){//时间已过期
                if (1 > 2) {
                  json.setSuccess(false);
                  json.setMsg(YztConstant.MSG_VERFIYCODE_OVERDUE);
                } else { // 注册成功
                  // reg.setRegistTime(new Date());
                  // reg.setStatus(1);
                  // registService.updateAll(reg);

                  // 同时往用户表里插入
                  YztUserinfo user = new YztUserinfo();
                  user.setId(userinfo.getId());
                  // user.setAccount(reg.getIsMobile());
                  user.setPassword(registor.getIsPassword());

                  updateNotNull(user);

                  json.setSuccess(true);
                  json.setMsg(YztConstant.UP_PWD_SUCCESS);
                }
              }
            }

          } else { // 找不到用户,提示验证码错误
            json.setSuccess(false);
            json.setMsg(YztConstant.MSG_MOBILE_VERFIYCODE_NOTEQUALL);
          }
        }
      }

    } else {
      json.setSuccess(false);
      json.setMsg(YztConstant.MSG_MOBILE_VERFIYCODE_NOTNULL);
    }

    return json;
  }
コード例 #2
0
  @Override
  public Json getVerifyCode(YztRegistor registor) {
    // LocalDateTime dateTime = LocalDateTime.now();
    System.out.println("registor.getIsMobile()=" + registor.getIsMobile());
    Json json = new Json();
    if (registor.getIsMobile() != null && !registor.getIsMobile().isEmpty()) {
      if (YztUtil.isMobileNO(registor.getIsMobile())) {

        Example example = new Example(YztRegistor.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("isMobile", registor.getIsMobile());

        Example example1 = new Example(YztUserinfo.class);
        Example.Criteria criteria1 = example1.createCriteria();
        criteria1.andEqualTo("account", registor.getIsMobile());
        criteria1.andEqualTo("status", 1); // 0,非禁用 用户,1-禁用
        List<YztUserinfo> list1 = selectByExample(example1);
        if (list1.size() > 0) {
          json.setSuccess(false);
          json.setMsg(YztConstant.LOGIN_ACCOUNT_BAN);
        } else {
          List<YztRegistor> list = registService.selectByExample(example);
          if (list.size() > 0) { // 已经注册过,对比过期时间,如果过期,重新发送验证码。如果没过期提示查看手机验证码
            // System.out.println("已经注册过");
            for (YztRegistor reg : list) {
              if (reg.getStatus() != null && reg.getStatus() == 1) { // 已经是成功注册的用户,可以发送修改密码的验证
                Calendar cal = (GregorianCalendar) Calendar.getInstance();
                cal.setTime(new Date());
                GregorianCalendar endCalendar = (GregorianCalendar) Calendar.getInstance();
                endCalendar.setTime(reg.getOverdueTime());
                if (cal.compareTo(endCalendar) > 0) { // 时间已过期
                  System.out.println("重新发送");
                  String smscontent = (int) ((Math.random() * 9) * 100000) + "";
                  Calendar c = Calendar.getInstance();
                  try {
                    String sms_result =
                        Demo_Client.sentContentTo(registor.getIsMobile(), smscontent);
                    // String sms_result = "654321";

                    reg.setIsVerifyCode(smscontent);
                    reg.setSmsId(sms_result);
                    reg.setSendTime(c.getTime());
                    // 加一天
                    // c.add(Calendar.DAY_OF_MONTH, 1);
                    c.add(Calendar.MINUTE, 3);
                    reg.setOverdueTime(c.getTime());
                    // reg.setRequestCount(reg.getRequestCount()+1);
                    registService.updateNotNull(reg);
                  } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                  }
                  json.setSuccess(true);
                  json.setMsg(YztConstant.MSG_SUCCESS);
                  json.setObj(reg);
                } else { // 在有效期内
                  // System.out.println(YztConstant.MSG_SECOND);
                  json.setSuccess(false);
                  json.setMsg(YztConstant.MSG_SECOND);
                }

              } else {
                json.setSuccess(false);
                json.setMsg(YztConstant.REGIST_MOBILE_NULL);
              }
            }
            // return "";
          } else {
            json.setSuccess(false);
            json.setMsg(YztConstant.REGIST_MOBILE_NULL);
          }
        }
      } else {
        json.setSuccess(false);
        json.setMsg(YztConstant.MSG_MOBILE_ERR);
      }

    } else {
      json.setSuccess(false);
      json.setMsg(YztConstant.MSG_MOBILE_NULL);
    }
    return json;
  }