示例#1
0
  /** 获取头部信息 */
  @RequestMapping(value = "/getUname")
  @ResponseBody
  public Object getList() {
    PageData pd = new PageData();
    Map<String, Object> map = new HashMap<String, Object>();
    try {
      pd = this.getPageData();
      List<PageData> pdList = new ArrayList<PageData>();

      // shiro管理的session
      Subject currentUser = SecurityUtils.getSubject();
      Session session = currentUser.getSession();

      PageData pds = new PageData();
      pds = (PageData) session.getAttribute(Const.SESSION_userpds);

      if (null == pds) {
        String USERNAME =
            session.getAttribute(Const.SESSION_USERNAME).toString(); // 获取当前登录者loginname
        pd.put("USERNAME", USERNAME);
        pds = userService.findByUId(pd);
        session.setAttribute(Const.SESSION_userpds, pds);
      }

      pdList.add(pds);
      map.put("list", pdList);
    } catch (Exception e) {
      logger.error(e.toString(), e);
    } finally {
      logAfter(logger);
    }
    return AppUtil.returnObject(pd, map);
  }
示例#2
0
 /**
  * 获取登录用户的IP
  *
  * @throws Exception
  */
 public void getRemortIP(String USERNAME) throws Exception {
   PageData pd = new PageData();
   HttpServletRequest request = this.getRequest();
   String ip = "";
   if (request.getHeader("x-forwarded-for") == null) {
     ip = request.getRemoteAddr();
   } else {
     ip = request.getHeader("x-forwarded-for");
   }
   pd.put("USERNAME", USERNAME);
   pd.put("IP", ip);
   userService.saveIP(pd);
 }
示例#3
0
  /** 获取用户权限 */
  public Map<String, String> getUQX(Session session) {
    PageData pd = new PageData();
    Map<String, String> map = new HashMap<String, String>();
    try {
      String USERNAME = session.getAttribute(Const.SESSION_USERNAME).toString();
      pd.put(Const.SESSION_USERNAME, USERNAME);
      String ROLE_ID = userService.findByUId(pd).get("ROLE_ID").toString();

      pd.put("ROLE_ID", ROLE_ID);

      PageData pd2 = new PageData();
      pd2.put(Const.SESSION_USERNAME, USERNAME);
      pd2.put("ROLE_ID", ROLE_ID);

      pd = roleService.findObjectById(pd);

      pd2 = roleService.findGLbyrid(pd2);
      if (null != pd2) {
        map.put("FX_QX", pd2.get("FX_QX").toString());
        map.put("FW_QX", pd2.get("FW_QX").toString());
        map.put("QX1", pd2.get("QX1").toString());
        map.put("QX2", pd2.get("QX2").toString());
        map.put("QX3", pd2.get("QX3").toString());
        map.put("QX4", pd2.get("QX4").toString());

        pd2.put("ROLE_ID", ROLE_ID);
        pd2 = roleService.findYHbyrid(pd2);
        map.put("C1", pd2.get("C1").toString());
        map.put("C2", pd2.get("C2").toString());
        map.put("C3", pd2.get("C3").toString());
        map.put("C4", pd2.get("C4").toString());
        map.put("Q1", pd2.get("Q1").toString());
        map.put("Q2", pd2.get("Q2").toString());
        map.put("Q3", pd2.get("Q3").toString());
        map.put("Q4", pd2.get("Q4").toString());
      }

      map.put("adds", pd.getString("ADD_QX"));
      map.put("dels", pd.getString("DEL_QX"));
      map.put("edits", pd.getString("EDIT_QX"));
      map.put("chas", pd.getString("CHA_QX"));

      // System.out.println(map);

      this.getRemortIP(USERNAME);
    } catch (Exception e) {
      logger.error(e.toString(), e);
    }
    return map;
  }
示例#4
0
  /** 保存皮肤 */
  @RequestMapping(value = "/setSKIN")
  public void setSKIN(PrintWriter out) {
    PageData pd = new PageData();
    try {
      pd = this.getPageData();

      // shiro管理的session
      Subject currentUser = SecurityUtils.getSubject();
      Session session = currentUser.getSession();

      String USERNAME = session.getAttribute(Const.SESSION_USERNAME).toString(); // 获取当前登录者loginname
      pd.put("USERNAME", USERNAME);
      userService.setSKIN(pd);
      session.removeAttribute(Const.SESSION_userpds);
      session.removeAttribute(Const.SESSION_USERROL);
      out.write("success");
      out.close();
    } catch (Exception e) {
      logger.error(e.toString(), e);
    }
  }
示例#5
0
  /** 发送电子邮件 */
  @RequestMapping(value = "/sendEmail")
  @ResponseBody
  public Object sendEmail() {
    PageData pd = new PageData();
    pd = this.getPageData();
    Map<String, Object> map = new HashMap<String, Object>();
    String msg = "ok"; // 发送状态
    int count = 0; // 统计发送成功条数
    int zcount = 0; // 理论条数

    String strEMAIL = Tools.readTxtFile(Const.EMAIL); // 读取邮件配置

    List<PageData> pdList = new ArrayList<PageData>();

    String toEMAIL = pd.getString("EMAIL"); // 对方邮箱
    String TITLE = pd.getString("TITLE"); // 标题
    String CONTENT = pd.getString("CONTENT"); // 内容
    String TYPE = pd.getString("TYPE"); // 类型
    String isAll = pd.getString("isAll"); // 是否发送给全体成员 yes or no

    String fmsg = pd.getString("fmsg"); // 判断是系统用户还是会员 "appuser"为会员用户

    if (null != strEMAIL && !"".equals(strEMAIL)) {
      String strEM[] = strEMAIL.split(",fh,");
      if (strEM.length == 4) {
        if ("yes".endsWith(isAll)) {
          try {
            List<PageData> userList = new ArrayList<PageData>();

            userList =
                "appuser".equals(fmsg)
                    ? appuserService.listAllUser(pd)
                    : userService.listAllUser(pd);

            zcount = userList.size();
            try {
              for (int i = 0; i < userList.size(); i++) {
                if (Tools.checkEmail(userList.get(i).getString("EMAIL"))) { // 邮箱格式不对就跳过
                  SimpleMailSender.sendEmail(
                      strEM[0],
                      strEM[1],
                      strEM[2],
                      strEM[3],
                      userList.get(i).getString("EMAIL"),
                      TITLE,
                      CONTENT,
                      TYPE); // 调用发送邮件函数
                  count++;
                } else {
                  continue;
                }
              }
              msg = "ok";
            } catch (Exception e) {
              msg = "error";
            }

          } catch (Exception e) {
            msg = "error";
          }
        } else {
          toEMAIL = toEMAIL.replaceAll(";", ";");
          toEMAIL = toEMAIL.replaceAll(" ", "");
          String[] arrTITLE = toEMAIL.split(";");
          zcount = arrTITLE.length;
          try {
            for (int i = 0; i < arrTITLE.length; i++) {
              if (Tools.checkEmail(arrTITLE[i])) { // 邮箱格式不对就跳过
                SimpleMailSender.sendEmail(
                    strEM[0],
                    strEM[1],
                    strEM[2],
                    strEM[3],
                    arrTITLE[i],
                    TITLE,
                    CONTENT,
                    TYPE); // 调用发送邮件函数
                count++;
              } else {
                continue;
              }
            }
            msg = "ok";
          } catch (Exception e) {
            msg = "error";
          }
        }
      } else {
        msg = "error";
      }
    } else {
      msg = "error";
    }
    pd.put("msg", msg);
    pd.put("count", count); // 成功数
    pd.put("ecount", zcount - count); // 失败数
    pdList.add(pd);
    map.put("list", pdList);
    return AppUtil.returnObject(pd, map);
  }
示例#6
0
  /** 发送短信 */
  @RequestMapping(value = "/sendSms")
  @ResponseBody
  public Object sendSms() {
    PageData pd = new PageData();
    pd = this.getPageData();
    Map<String, Object> map = new HashMap<String, Object>();
    String msg = "ok"; // 发送状态
    int count = 0; // 统计发送成功条数
    int zcount = 0; // 理论条数

    List<PageData> pdList = new ArrayList<PageData>();

    String PHONEs = pd.getString("PHONE"); // 对方邮箱
    String CONTENT = pd.getString("CONTENT"); // 内容
    String isAll = pd.getString("isAll"); // 是否发送给全体成员 yes or no
    String TYPE = pd.getString("TYPE"); // 类型 1:短信接口1   2:短信接口2
    String fmsg = pd.getString("fmsg"); // 判断是系统用户还是会员 "appuser"为会员用户

    if ("yes".endsWith(isAll)) {
      try {
        List<PageData> userList = new ArrayList<PageData>();

        userList =
            "appuser".equals(fmsg) ? appuserService.listAllUser(pd) : userService.listAllUser(pd);

        zcount = userList.size();
        try {
          for (int i = 0; i < userList.size(); i++) {
            if (Tools.checkMobileNumber(userList.get(i).getString("PHONE"))) { // 手机号格式不对就跳过
              if ("1".equals(TYPE)) {
                SmsUtil.sendSms1(userList.get(i).getString("PHONE"), CONTENT); // 调用发短信函数1
              } else {
                SmsUtil.sendSms2(userList.get(i).getString("PHONE"), CONTENT); // 调用发短信函数2
              }
              count++;
            } else {
              continue;
            }
          }
          msg = "ok";
        } catch (Exception e) {
          msg = "error";
        }

      } catch (Exception e) {
        msg = "error";
      }
    } else {
      PHONEs = PHONEs.replaceAll(";", ";");
      PHONEs = PHONEs.replaceAll(" ", "");
      String[] arrTITLE = PHONEs.split(";");
      zcount = arrTITLE.length;
      try {
        for (int i = 0; i < arrTITLE.length; i++) {
          if (Tools.checkMobileNumber(arrTITLE[i])) { // 手机号式不对就跳过
            if ("1".equals(TYPE)) {
              SmsUtil.sendSms1(arrTITLE[i], CONTENT); // 调用发短信函数1
            } else {
              SmsUtil.sendSms2(arrTITLE[i], CONTENT); // 调用发短信函数2
            }
            count++;
          } else {
            continue;
          }
        }
        msg = "ok";
      } catch (Exception e) {
        msg = "error";
      }
    }
    pd.put("msg", msg);
    pd.put("count", count); // 成功数
    pd.put("ecount", zcount - count); // 失败数
    pdList.add(pd);
    map.put("list", pdList);
    return AppUtil.returnObject(pd, map);
  }
示例#7
0
  @RequestMapping(value = "/login_login", produces = "application/json;charset=UTF-8")
  @ResponseBody
  public Object tologin(ModelMap model) throws Exception {
    Map<String, String> map = new HashMap<String, String>();
    PageData pd = new PageData();
    pd = this.getPageData();
    String errInfo = "";
    String KEYDATA[] =
        pd.getString("KEYDATA")
            .replaceAll("qq263235040luckyboy", "")
            .replaceAll("*****@*****.**", "")
            .split(",luckyboy,");

    if (null != KEYDATA && KEYDATA.length == 3) {
      // shiro管理的session
      Subject currentUser = SecurityUtils.getSubject();
      Session session = currentUser.getSession();
      String sessionCode =
          (String) session.getAttribute(Const.SESSION_SECURITY_CODE); // 获取session中的验证码

      String code = KEYDATA[2];
      if (null == code || "".equals(code)) {
        errInfo = "nullcode"; // 验证码为空
      } else {
        String USERNAME = KEYDATA[0];
        String PASSWORD = KEYDATA[1];
        pd.put("USERNAME", USERNAME);
        if (Tools.notEmpty(sessionCode) && sessionCode.equalsIgnoreCase(code)) {
          String passwd = new SimpleHash("SHA-1", USERNAME, PASSWORD).toString(); // 密码加密
          pd.put("PASSWORD", passwd);
          pd = userService.getUserByNameAndPwd(pd);
          if (pd != null) {
            pd.put("LAST_LOGIN", DateUtil.getTime().toString());
            userService.updateLastLogin(pd);
            User user = new User();
            user.setUSER_ID(pd.getString("USER_ID"));
            user.setUSERNAME(pd.getString("USERNAME"));
            user.setPASSWORD(pd.getString("PASSWORD"));
            user.setNAME(pd.getString("NAME"));
            user.setRIGHTS(pd.getString("RIGHTS"));
            user.setROLE_ID(pd.getString("ROLE_ID"));
            user.setLAST_LOGIN(pd.getString("LAST_LOGIN"));
            user.setIP(pd.getString("IP"));
            user.setSTATUS(pd.getString("STATUS"));
            session.setAttribute(Const.SESSION_USER, user);
            session.removeAttribute(Const.SESSION_SECURITY_CODE);

            // shiro加入身份验证
            Subject subject = SecurityUtils.getSubject();
            UsernamePasswordToken token = new UsernamePasswordToken(USERNAME, PASSWORD);
            try {
              subject.login(token);
            } catch (AuthenticationException e) {
              errInfo = "身份验证失败!";
            }

          } else {
            errInfo = "usererror"; // 用户名或密码有误
          }
        } else {
          errInfo = "codeerror"; // 验证码输入有误
        }
        if (Tools.isEmpty(errInfo)) {
          errInfo = "success"; // 验证成功
        }
      }
    } else {
      errInfo = "error"; // 缺少参数
    }
    map.put("result", errInfo);
    return AppUtil.returnObject(new PageData(), map);
  }
示例#8
0
  /** 访问系统首页 */
  @RequestMapping(value = "/main/{changeMenu}")
  public ModelAndView login_index(@PathVariable("changeMenu") String changeMenu, ModelMap model) {
    ModelAndView mv = this.getModelAndView();
    PageData pd = new PageData();
    pd = this.getPageData();
    try {

      // shiro管理的session
      Subject currentUser = SecurityUtils.getSubject();
      Session session = currentUser.getSession();

      User user = (User) session.getAttribute(Const.SESSION_USER);
      if (user != null) {

        User userr = (User) session.getAttribute(Const.SESSION_USERROL);
        if (null == userr) {
          user = userService.getUserAndRoleById(user.getUSER_ID());
          session.setAttribute(Const.SESSION_USERROL, user);
        } else {
          user = userr;
        }
        Role role = user.getRole();
        String roleRights = role != null ? role.getRIGHTS() : "";
        // 避免每次拦截用户操作时查询数据库,以下将用户所属角色权限、用户权限限都存入session
        session.setAttribute(Const.SESSION_ROLE_RIGHTS, roleRights); // 将角色权限存入session
        session.setAttribute(Const.SESSION_USERNAME, user.getUSERNAME()); // 放入用户名

        List<Menu> allmenuList = new ArrayList<Menu>();

        if (null == session.getAttribute(Const.SESSION_allmenuList)) {
          allmenuList = menuService.listAllMenu();
          if (Tools.notEmpty(roleRights)) {
            for (Menu menu : allmenuList) {
              menu.setHasMenu(RightsHelper.testRights(roleRights, menu.getMENU_ID()));
              if (menu.isHasMenu()) {
                List<Menu> subMenuList = menu.getSubMenu();
                for (Menu sub : subMenuList) {
                  sub.setHasMenu(RightsHelper.testRights(roleRights, sub.getMENU_ID()));
                }
              }
            }
          }
          session.setAttribute(Const.SESSION_allmenuList, allmenuList); // 菜单权限放入session中
        } else {
          allmenuList = (List<Menu>) session.getAttribute(Const.SESSION_allmenuList);
        }

        // 切换菜单=====
        List<Menu> menuList = new ArrayList<Menu>();
        // if(null == session.getAttribute(Const.SESSION_menuList) ||
        // ("yes".equals(pd.getString("changeMenu")))){
        if (null == session.getAttribute(Const.SESSION_menuList) || ("yes".equals(changeMenu))) {
          List<Menu> menuList1 = new ArrayList<Menu>();
          List<Menu> menuList2 = new ArrayList<Menu>();

          // 拆分菜单
          for (int i = 0; i < allmenuList.size(); i++) {
            Menu menu = allmenuList.get(i);
            if ("1".equals(menu.getMENU_TYPE())) {
              menuList1.add(menu);
            } else {
              menuList2.add(menu);
            }
          }

          session.removeAttribute(Const.SESSION_menuList);
          if ("2".equals(session.getAttribute("changeMenu"))) {
            session.setAttribute(Const.SESSION_menuList, menuList1);
            session.removeAttribute("changeMenu");
            session.setAttribute("changeMenu", "1");
            menuList = menuList1;
          } else {
            session.setAttribute(Const.SESSION_menuList, menuList2);
            session.removeAttribute("changeMenu");
            session.setAttribute("changeMenu", "2");
            menuList = menuList2;
          }
        } else {
          menuList = (List<Menu>) session.getAttribute(Const.SESSION_menuList);
        }
        // 切换菜单=====

        if (null == session.getAttribute(Const.SESSION_QX)) {
          session.setAttribute(Const.SESSION_QX, this.getUQX(session)); // 按钮权限放到session中
        }

        // FusionCharts 报表
        String strXML =
            "<graph caption='前12个月订单销量柱状图' xAxisName='月份' yAxisName='值' decimalPrecision='0' formatNumberScale='0'><set name='2013-05' value='4' color='AFD8F8'/><set name='2013-04' value='0' color='AFD8F8'/><set name='2013-03' value='0' color='AFD8F8'/><set name='2013-02' value='0' color='AFD8F8'/><set name='2013-01' value='0' color='AFD8F8'/><set name='2012-01' value='0' color='AFD8F8'/><set name='2012-11' value='0' color='AFD8F8'/><set name='2012-10' value='0' color='AFD8F8'/><set name='2012-09' value='0' color='AFD8F8'/><set name='2012-08' value='0' color='AFD8F8'/><set name='2012-07' value='0' color='AFD8F8'/><set name='2012-06' value='0' color='AFD8F8'/></graph>";
        mv.addObject("strXML", strXML);
        // FusionCharts 报表
        mv.setViewName("system/admin/index");
        mv.addObject("user", user);
        mv.addObject("menuList", menuList);
      } else {
        mv.setViewName("system/admin/login"); // session失效后跳转登录页面
      }

    } catch (Exception e) {
      mv.setViewName("system/admin/login");
      logger.error(e.getMessage(), e);
    }
    pd.put("SYSNAME", Tools.readTxtFile(Const.SYSNAME)); // 读取系统名称
    mv.addObject("pd", pd);
    return mv;
  }