示例#1
0
 private JSONArray getChildrenOfGroup(Integer groupId, String _site) {
   List<Group> groups =
       dao.listByParams(Group.class, "from Group where parentId = ? and _site=?", groupId, _site);
   JSONArray arr = new JSONArray();
   for (Group g : groups) {
     JSONObject jobj = new JSONObject();
     jobj.put("name", g.name);
     jobj.put("id", g.id);
     jobj.put("type", "group");
     jobj.put("key", "group_" + g.id);
     jobj.put("isParent", true);
     JSONArray children = getChildrenOfGroup(g.id, _site);
     if (!children.isEmpty()) {
       jobj.put("children", children);
     }
     arr.add(jobj);
   }
   List<Map> users =
       dao.listAsMap(
           "select u.name as name , u.id as id from User u , UserGroup ug where u.id = ug.uid and ug.gid=? and u._site=?",
           groupId,
           _site);
   for (Map u : users) {
     JSONObject jobj = new JSONObject();
     jobj.put("name", u.get("name"));
     jobj.put("id", u.get("id"));
     jobj.put("key", "user_" + u.get("id"));
     jobj.put("type", "user");
     arr.add(jobj);
   }
   return arr;
 }
示例#2
0
 @WebMethod
 public ModelAndView login(User user, String _site) {
   ModelAndView mv = new ModelAndView();
   String pwd = SecurityHelper.Md5(user.pwd);
   User po =
       dao.getUniqueByParams(
           User.class,
           new String[] {"account", "pwd", "_site"},
           new Object[] {user.account, pwd, _site});
   if (po == null) {
     throw new GException(PlatformExceptionType.BusinessException, "用户名或密码不正确。");
   }
   po.lasttime = new Date();
   dao.saveOrUpdate(po);
   ThreadSession.getHttpSession().setAttribute(MakesiteConstant.Session_Attr_User, po);
   List<Map> result =
       dao.listAsMap(
           "select ra.authId as authId from UserRole ur ,RoleAuth ra where ur.roleId=ra.roleId and ur.uid=?",
           po.id);
   StringBuilder authList = new StringBuilder("");
   for (Map map : result) {
     authList.append(map.get("authId").toString());
   }
   ThreadSession.getHttpSession()
       .setAttribute(MakesiteConstant.Session_Auth_List, authList.toString());
   String serverName = DataHelper.getServerName(ThreadSession.HttpServletRequest.get());
   if (!onlineUserCountMap.containsKey(serverName)) {
     onlineUserCountMap.put(serverName, 1);
   } else {
     onlineUserCountMap.put(serverName, onlineUserCountMap.get(serverName) + 1);
   }
   String text;
   try {
     text =
         FileUtils.readFileToString(
             new File(
                 ThreadSession.HttpServletRequest.get().getServletContext().getRealPath("/")
                     + File.separator
                     + "auths.json"),
             "utf8");
     JSONArray jarr = JSONArray.fromObject(text);
     List<String> urlList = new ArrayList<String>();
     for (int i = 0; i < jarr.size(); i++) {
       JSONObject jobj = jarr.getJSONObject(i);
       if (authList.toString().contains(jobj.getString("id"))) {
         continue;
       }
       String urls = jobj.getString("urls");
       for (String url : urls.split(",")) {
         urlList.add(url);
       }
     }
     ThreadSession.getHttpSession().setAttribute(MakesiteConstant.Session_Auth_Urls, urlList);
   } catch (IOException e) {
     e.printStackTrace();
   }
   return mv;
 }