Пример #1
0
  /**
   * 用户注销
   *
   * @param session
   * @return
   */
  @RequestMapping(value = "/logout")
  public ModelAndView logout() {
    ModelAndView mv = this.getModelAndView();
    PageData pd = new PageData();

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

    session.removeAttribute(Const.SESSION_USER);
    session.removeAttribute(Const.SESSION_ROLE_RIGHTS);
    session.removeAttribute(Const.SESSION_allmenuList);
    session.removeAttribute(Const.SESSION_menuList);
    session.removeAttribute(Const.SESSION_QX);
    session.removeAttribute(Const.SESSION_userpds);
    session.removeAttribute(Const.SESSION_USERNAME);
    session.removeAttribute(Const.SESSION_USERROL);
    session.removeAttribute("changeMenu");

    // shiro销毁登录
    Subject subject = SecurityUtils.getSubject();
    subject.logout();

    pd = this.getPageData();
    String msg = pd.getString("msg");
    pd.put("msg", msg);

    pd.put("SYSNAME", Tools.readTxtFile(Const.SYSNAME)); // 读取系统名称
    mv.setViewName("system/admin/login");
    mv.addObject("pd", pd);
    return mv;
  }
Пример #2
0
 @RequestMapping("/login")
 public String login(ModelMap model) {
   PageData pd = new PageData();
   pd = this.getPageData();
   pd.put("SYSNAME", Tools.readTxtFile(Const.SYSNAME)); // 读取系统名称
   model.put("SYSNAME", pd);
   return "system/admin/login";
 }
Пример #3
0
  /** 去系统设置页面 */
  @RequestMapping(value = "/goSystem")
  public ModelAndView goEditEmail() throws Exception {
    ModelAndView mv = this.getModelAndView();
    PageData pd = new PageData();
    pd = this.getPageData();
    pd.put("YSYNAME", Tools.readTxtFile(Const.SYSNAME)); // 读取系统名称
    pd.put("COUNTPAGE", Tools.readTxtFile(Const.PAGE)); // 读取每页条数
    String strEMAIL = Tools.readTxtFile(Const.EMAIL); // 读取邮件配置
    String strSMS1 = Tools.readTxtFile(Const.SMS1); // 读取短信1配置
    String strSMS2 = Tools.readTxtFile(Const.SMS2); // 读取短信2配置
    String strFWATERM = Tools.readTxtFile(Const.FWATERM); // 读取文字水印配置
    String strIWATERM = Tools.readTxtFile(Const.IWATERM); // 读取图片水印配置
    pd.put("Token", Tools.readTxtFile(Const.WEIXIN)); // 读取微信配置

    if (null != strEMAIL && !"".equals(strEMAIL)) {
      String strEM[] = strEMAIL.split(",fh,");
      if (strEM.length == 4) {
        pd.put("SMTP", strEM[0]);
        pd.put("PORT", strEM[1]);
        pd.put("EMAIL", strEM[2]);
        pd.put("PAW", strEM[3]);
      }
    }

    if (null != strSMS1 && !"".equals(strSMS1)) {
      String strS1[] = strSMS1.split(",fh,");
      if (strS1.length == 2) {
        pd.put("SMSU1", strS1[0]);
        pd.put("SMSPAW1", strS1[1]);
      }
    }

    if (null != strSMS2 && !"".equals(strSMS2)) {
      String strS2[] = strSMS2.split(",fh,");
      if (strS2.length == 2) {
        pd.put("SMSU2", strS2[0]);
        pd.put("SMSPAW2", strS2[1]);
      }
    }

    if (null != strFWATERM && !"".equals(strFWATERM)) {
      String strFW[] = strFWATERM.split(",fh,");
      if (strFW.length == 5) {
        pd.put("isCheck1", strFW[0]);
        pd.put("fcontent", strFW[1]);
        pd.put("fontSize", strFW[2]);
        pd.put("fontX", strFW[3]);
        pd.put("fontY", strFW[4]);
      }
    }

    if (null != strIWATERM && !"".equals(strIWATERM)) {
      String strIW[] = strIWATERM.split(",fh,");
      if (strIW.length == 4) {
        pd.put("isCheck2", strIW[0]);
        pd.put("imgUrl", strIW[1]);
        pd.put("imgX", strIW[2]);
        pd.put("imgY", strIW[3]);
      }
    }

    mv.setViewName("system/head/sys_edit");
    mv.addObject("pd", pd);

    return mv;
  }
Пример #4
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);
  }
Пример #5
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;
  }