// 编辑器上传图片
  @RequestMapping("/upload")
  @ResponseBody
  public JSONObject upload(
      @RequestParam("imgFile") MultipartFile file, HttpServletRequest request, ModelMap m)
      throws IOException {

    // String filetype =
    // StringUtils.substringAfterLast(file.getOriginalFilename(), ".");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    String ymd = sdf.format(new Date());

    String realRootPath =
        getServletContext().getResource("/").toString() + "upload/choicenesscontent/" + ymd + "/";
    YztUtil.writeFile(file.getInputStream(), realRootPath, file.getOriginalFilename());

    /**/
    String path = request.getContextPath();
    String basePath =
        request.getScheme()
            + "://"
            + request.getServerName()
            + ":"
            + request.getServerPort()
            + path
            + "/";
    // System.out.println("getContextPath==="+
    // basePath+"upload/user/headimg/"+user.getId()+"."+filetype);
    String picurl = basePath + "upload/choicenesscontent/" + ymd + "/" + file.getOriginalFilename();
    // user.setPicurl(picurl);

    JSONObject json = new JSONObject();
    json.put("error", 0);
    json.put("url", picurl);
    return json;
  }
Exemplo n.º 2
0
  @Override
  public Json login(YztUserinfo userinfo) {
    Json json = new Json();
    if (userinfo.getAccount().equals(null)
        || userinfo.getPassword().equals(null)
        || userinfo.getAccount().isEmpty()
        || userinfo.getPassword().isEmpty()) {
      json.setSuccess(false);
      json.setMsg(YztConstant.LOGIN_NOTNULL);
    } else if (YztUtil.isMobileNO(userinfo.getAccount())) {
      Example example = new Example(YztUserinfo.class);
      Example.Criteria criteria = example.createCriteria();
      criteria.andEqualTo("account", userinfo.getAccount());
      List<YztUserinfo> list = selectByExample(example);
      if (list.size() == 1) {
        for (YztUserinfo user : list) {
          if (user.getStatus() != null && user.getStatus() == 1) {
            json.setSuccess(false);
            json.setMsg(YztConstant.LOGIN_ACCOUNT_BAN);
          } else {
            if (user.getPassword().equals(userinfo.getPassword())) {
              json.setSuccess(true);
              json.setMsg(YztConstant.LOGIN_SUCCESS);
              json.setObj(user);
            } else {
              json.setSuccess(false);
              json.setMsg(YztConstant.LOGIN_ERR);
            }
          }
        }

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

    return json;
  }
Exemplo n.º 3
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;
  }