Ejemplo n.º 1
0
 public String getAccordion(String navMenuName, boolean noAuth) throws Exception {
   NavMenu navMenu = this.navMenuService.getOneByName(navMenuName);
   if (navMenu == null) {
     navMenu = this.navMenuService.createDefaultNavMenu(navMenuName);
   }
   return getAccordion(navMenu.getNavMenuId(), noAuth);
 }
Ejemplo n.º 2
0
  public String getAccordion(Long navMenuId, boolean noAuth) throws Exception {
    boolean flag = false;

    if (noAuth) {
      flag = true;
    } else if ((this.permissions != null) && (this.permissions.size() > 0)) {
      for (Long treemenuId : this.permissions) {
        NavMenu navmenu = this.treeMenuService.findNavMenuByTreeMenuId(treemenuId);

        if ((navmenu == null) || (!navMenuId.equals(navmenu.getNavMenuId()))) {
          continue;
        }
        flag = true;
      }
    }

    if (!flag) {
      return "";
    }
    List<TreeMenu> topParent = this.treeMenuService.getTopParent(navMenuId);

    if (topParent == null) {
      return "";
    }
    StringBuilder sb = new StringBuilder();

    for (Iterator<TreeMenu> it = topParent.iterator(); it.hasNext(); ) {
      TreeMenu m = it.next();
      if (m.getTreeMenuId().longValue() == TreeMenuCons.TOP_TREE_MENU_ID()) {
        continue;
      }
      if (noAuth) {
        sb.append(new Accordion(m.getName(), getUlTag(m.getTreeMenuId(), noAuth)).toString());
        continue;
      }

      Long treeMenuId = m.getTreeMenuId();
      List<TreeMenu> children = this.treeMenuService.getChildren(treeMenuId);

      if (((children == null) && (!findPerm(treeMenuId).equals(Long.valueOf(-1L))))
          || (findTreeMenu(children) == null)) {
        continue;
      }
      sb.append(new Accordion(m.getName(), getUlTag(m.getTreeMenuId(), noAuth)).toString());
    }

    return sb.toString();
  }
Ejemplo n.º 3
0
  @Validate({"user.authcode", "user.account", "user.password"})
  public Object doLoginAtPut(Validation val, Map<String, Object> model) {
    if (val.hasErr()) {
      model.put("valError", val.getAllErr());
      return UserCons.LOGIN_ACTION_RESULT();
    }

    List<Long> treeMenuPerms = new ArrayList<Long>();
    List<Long> navMenuPerms = new ArrayList<Long>();
    try {
      String _authCode =
          (String) MVC.ctx().getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
      User loginUser =
          userService.login(_authCode, CommonUtil.getIpAddr(MVC.ctx().getRequest()), user);

      // 登陆成功之后,将用户的权限信息查询出来放到session内存中
      /* 权限控制 */
      List<Role> roles = loginUser.getRoles();
      if (roles == null) roles = new ArrayList<Role>();

      for (Role role : roles) {
        Role _role = roleService.findTreeMenuByRoleId(role.getRoleId());
        /* 角色对应权限集合 */
        List<TreeMenu> tms = _role.getMenus();
        List<NavMenu> nms = _role.getNavMenus();

        if (tms != null) {
          for (TreeMenu tm : tms) treeMenuPerms.add(tm.getTreeMenuId());
        }
        if (nms != null) {
          for (NavMenu nm : nms) navMenuPerms.add(nm.getNavMenuId());
        }
      }

      loginUser.setTreeMenuPerms(treeMenuPerms);
      loginUser.setNavMenuPerms(navMenuPerms);

      MVC.ctx().getSession().setAttribute(UserCons.LOGIN_USER_ATTR_NAME(), loginUser);

    } catch (Exception e) {
      model.put(UserCons.LOGIN_ERR_ATTR_NAME(), e.getMessage());
      return UserCons.LOGIN_ACTION_RESULT();
    }

    return UserCons.LOGIN_SUCCESS_REDIRECT();
  }
Ejemplo n.º 4
0
  public String createTreeMenu(String navMenuName, boolean noAuth) throws Exception {
    NavMenu navMenu = this.navMenuService.getOneByName(navMenuName);
    if (navMenu == null) {
      navMenu = this.navMenuService.createDefaultNavMenu(navMenuName);
    }
    List<LiTag> topLiList = new ArrayList<LiTag>();
    LiTag topLi = new LiTag();
    ATag topA = new ATag();
    topA.setValue("全部菜单");
    topLi.setA(topA);

    List<LiTag> liList = new ArrayList<LiTag>();

    UlTag topUl = new UlTag();
    topUl.setClazz("");
    topUl.setLi(liList);
    topLi.setUl(topUl);

    topLiList.add(topLi);

    List<TreeMenu> parent = this.treeMenuService.getTopParent(navMenu.getNavMenuId());

    for (TreeMenu tm : parent) {
      if (tm.getTreeMenuId().longValue() == TreeMenuCons.TOP_TREE_MENU_ID()) {
        continue;
      }
      ATag a = new ATag();
      a.setValue(tm.getName());
      UlTag chidren = new UlTag("", createTree(tm.getTreeMenuId(), true));
      liList.add(new LiTag(a, chidren));
    }

    UlTag top = new UlTag(this.rootUlStyleClass, topLiList);

    return top.toString();
  }
Ejemplo n.º 5
0
  public String createAllTreeMenu() throws Exception {
    List<NavMenu> navMenus = this.navMenuService.findAllOrderBy("rank", 1);
    if ((navMenus == null) || (navMenus.size() == 0)) {
      return "";
    }
    List<LiTag> topLiList = new ArrayList<LiTag>();
    LiTag topLi = new LiTag();
    ATag topA = new ATag();
    topA.setValue("全部菜单");
    topLi.setA(topA);

    List<LiTag> navLiList = new ArrayList<LiTag>();

    UlTag navUl = new UlTag();
    navUl.setClazz("");
    navUl.setLi(navLiList);
    topLi.setUl(navUl);

    topLiList.add(topLi);

    for (NavMenu navMenu : navMenus) {
      ATag navA = new ATag();
      LiTag navLi = new LiTag();
      navA.setValue(navMenu.getName());
      navLi.setA(navA);

      if ((navMenu.getHref().endsWith(".jsp")) || (navMenu.getHref().endsWith(".html"))) {
        navA.setTname("navMenuIds");
        navA.setTvalue(navMenu.getNavMenuId());
        navLiList.add(navLi);
        continue;
      }

      List<TreeMenu> parent = this.treeMenuService.getTopParent(navMenu.getNavMenuId());

      if ((parent == null) || (parent.size() == 1)) {
        continue;
      }
      List<LiTag> treeLiList = new ArrayList<LiTag>();

      UlTag treeUl = new UlTag();
      treeUl.setClazz("");
      treeUl.setLi(treeLiList);

      navLi.setUl(treeUl);

      for (TreeMenu tm : parent) {
        if (tm.getTreeMenuId().longValue() == TreeMenuCons.TOP_TREE_MENU_ID()) {
          continue;
        }
        ATag a = new ATag();
        a.setValue(tm.getName());

        treeLiList.add(new LiTag(a, new UlTag("", createTree(tm.getTreeMenuId(), true, true))));
      }

      if (treeLiList.size() > 0) {
        navLiList.add(navLi);
      }
    }

    UlTag top = new UlTag(this.rootUlStyleClass, topLiList);

    return top.toString();
  }