Example #1
0
  public String all() {
    if (!isUserLogined()) {
      plsLogin();
      return JSON_ERROR;
    }
    if (id > 0) {
      Corporation c = organizationMgr.getCorporation(id);
      if (c.getAccessType() == Corporation.PUBLIC_ACCESS) {
        id = 0; // public access
      }
    }
    if (id > 0 && !organizationMgr.canUserManageCorp(getCurUserId(), id)) {
      setErrMsg(ACCESS_DENY);
      return JSON_ERROR;
    }
    Gson gson = new Gson();

    List<User> users =
        id > 0 ? super.getAccountMgr().getUserList(id) : super.getAccountMgr().getUserList();
    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
    for (User user : users) {
      Map<String, Object> o = new HashMap<String, Object>();
      o.put("id", user.getId());
      o.put("name", user.getName());
      o.put("role", user.getRoleListStr());
      o.put("account", user.getAccount());
      o.put("realName", user.getRealname());
      o.put("empId", user.getEmpId());
      o.put("namePinyin", Pinyin4jUtil.calculatePinyinArrStr(user.getName()));
      o.put("realNamePinyin", Pinyin4jUtil.calculatePinyinArrStr(user.getRealname()));
      result.add(o);
    }
    setJson("{\"users\":" + gson.toJson(result) + "}");
    return SUCCESS;
  }
Example #2
0
 @SuppressWarnings({"unchecked", "rawtypes"})
 public String doLogin() {
   if (super.getAccountMgr().validate(getAccount(), getPassword())) {
     Map session = ContextManager.currentSession();
     User user = getAccountMgr().getUser(getAccount());
     if (user != null && user.getId() > 0) {
       session.put(ContextManager.KEY_ACCOUNT, user.getAccount());
       session.put(ContextManager.KEY_USER_ID, user.getId());
       session.put(ContextManager.KEY_NAME, user.getName());
       Set<Role> roleList = new HashSet<Role>();
       for (Role role : user.getRoleList()) {
         Role copied = new Role();
         copied.setId(role.getId());
         copied.setName(role.getName());
         roleList.add(copied);
       }
       session.put(ContextManager.KEY_ROLE_LIST, roleList);
     } else {
       setErrMsg("用户不存在或密码错误");
       return ERROR;
     }
     if (getReturnUrl() != null && !getReturnUrl().trim().equals("")) {
       return "redirect";
     }
     return SUCCESS;
   } else {
     setErrMsg("用户不存在或密码错误");
     return ERROR;
   }
 }
Example #3
0
 // added by liweiguang 2016-1-18
 public String getReadonlyMemberAccountListStr() {
   StringBuilder stringBuilder = new StringBuilder();
   for (User user : getReadonlyUserList()) {
     stringBuilder.append(user.getAccount() + "(" + user.getName() + "), ");
   }
   return stringBuilder.toString();
 }
Example #4
0
 public String getUserListStr() {
   StringBuilder stringBuilder = new StringBuilder();
   Iterator<User> iterator = getUserList().iterator();
   while (iterator.hasNext()) {
     User user = iterator.next();
     // remove the creator
     if (user.getId() == getUser().getId()) continue;
     stringBuilder.append(user.getName() + "(" + user.getWorkRole() + ")");
     if (iterator.hasNext()) {
       stringBuilder.append(", ");
     }
   }
   return stringBuilder.toString();
 }
Example #5
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  public String lock() {
    long curUserId = getCurUserId();
    if (curUserId <= 0) {
      setIsOk(false);
      setErrMsg(LOGIN_WARN_MSG);
      return JSON_ERROR;
    }

    boolean isOk = false;
    if (isLocked(getId())) {
      // if the project is locked, find the locker
      User user = getLocker(getId());
      if (!user.getAccount().equals(getCurAccount())) {
        setJson("{\"isOk\":false, \"errMsg\":\"该项目目前正被" + user.getName() + "锁定.\"}");
      } else {
        // user request lock a locked project
        // which is locked by himself, so let him go
        isOk = true;
      }

    } else {
      // else, lock the project, than let him go.
      Map app = ContextManager.getApplication();
      if (app.get(ContextManager.KEY_PROJECT_LOCK_LIST) == null) {
        app.put(ContextManager.KEY_PROJECT_LOCK_LIST, new HashMap());
      }
      Map projectLockList = (Map) app.get(ContextManager.KEY_PROJECT_LOCK_LIST);
      if (projectLockList.get(curUserId) == null) {
        projectLockList.put(curUserId, getId());
        // System.out.println("user[" + curUserId + "] locked project["+
        // getId() + "]");
      }
      isOk = true;
    }
    if (isOk) {
      setJson(
          "{\"isOk\":true, \"projectData\":"
              + projectMgr.getProject(getId()).getProjectData()
              + "}");
    }
    return SUCCESS;
  }
Example #6
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  public String doLogin() {
    // 增加验证码
    Map<String, Object> session = ContextManager.currentSession();
    String kaptchaExpected =
        (String) session.get(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
    if (getKaptcha() == null || !getKaptcha().equals(kaptchaExpected)) {
      setErrMsg("验证码错误");
      return ERROR;
    }

    if (super.getAccountMgr().validate(getAccount(), getPassword())) {
      User user = getAccountMgr().getUser(getAccount());
      if (user != null && user.getId() > 0) {
        session.put(ContextManager.KEY_ACCOUNT, user.getAccount());
        session.put(ContextManager.KEY_USER_ID, user.getId());
        session.put(ContextManager.KEY_NAME, user.getName());
        Set<Role> roleList = new HashSet<Role>();
        for (Role role : user.getRoleList()) {
          Role copied = new Role();
          copied.setId(role.getId());
          copied.setName(role.getName());
          roleList.add(copied);
        }
        session.put(ContextManager.KEY_ROLE_LIST, roleList);
      } else {
        setErrMsg("用户不存在或密码错误");
        return ERROR;
      }
      if (getReturnUrl() != null && !getReturnUrl().trim().equals("")) {
        return "redirect";
      }
      return SUCCESS;
    } else {
      setErrMsg("用户不存在或密码错误");
      return ERROR;
    }
  }
Example #7
0
  @Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {

    String url = null;

    if (request instanceof HttpServletRequest) {
      url = ((HttpServletRequest) request).getRequestURL().toString();
    }
    String domain = URLUtils.getDomain(url);
    if (domain != "") {
      SystemConstant.setDOMAIN_URL(domain);
    }

    // all requests count into realtime charts
    SystemVisitorLog.count();

    if (URLUtils.shouldLog(url)) SystemVisitorLog.count(request.getRemoteAddr());

    if (SystemConstant.DOMAIN_URL.isEmpty()) {
      SystemConstant.DOMAIN_URL = request.getServerName();
      if (request.getServerPort() != 80) {
        SystemConstant.DOMAIN_URL += ":" + request.getServerPort();
      }
    }
    HttpSession session = ((HttpServletRequest) request).getSession();
    Object userAccount = session.getAttribute(ContextManager.KEY_ACCOUNT);
    Object userName = session.getAttribute(ContextManager.KEY_NAME);
    boolean logined = userAccount != null;

    SystemConstant.README_PATH =
        session.getServletContext().getRealPath(File.separator + "README.md");
    SystemConstant.ROOT = session.getServletContext().getRealPath(File.separator);

    if (!logined) {
      BucSSOUser user = SimpleUserUtil.getBucSSOUser((HttpServletRequest) request);
      // System.out.println("user:"******"user.getEmpId:" + user.getEmpId());
        // System.out.println("user.getLastName:" + user.getLastName());
        // System.out.println("user.emailAddr:" + user.getEmailAddr());
        // System.out.println("user.loginName:" + user.getLoginName());

        String emailPrefix =
            user.getEmailAddr().substring(0, user.getEmailAddr().indexOf("@alibaba"));
        // System.out.println("emailPrefix:" + emailPrefix);
        User rapUser = accountMgr.getUser(emailPrefix);
        if (rapUser == null) {
          // proceed register
          User newUser = new User();
          newUser.setAccount(emailPrefix);
          newUser.setPassword("RESERVED");
          String name = user.getNickNameCn();
          if (name == null || name.isEmpty()) {
            name = user.getLastName();
          }
          newUser.setName(name);
          newUser.setEmail(user.getEmailAddr());
          newUser.setRealname(user.getLastName());
          newUser.setEmpId(user.getEmpId());
          getAccountMgr().addUser(newUser);
          rapUser = accountMgr.getUser(emailPrefix);
          if (rapUser == null) {
            try {
              throw new Exception("user register failed!");
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        }
        // proceed login
        String account = rapUser.getAccount();
        long userId = rapUser.getId();
        session.setAttribute(ContextManager.KEY_ACCOUNT, account);
        session.setAttribute(ContextManager.KEY_USER_ID, userId);
        session.setAttribute(ContextManager.KEY_NAME, rapUser.getName());
      }

    } else {
      if (URLUtils.shouldLog(url)) {
        User logUser = new User();
        logUser.setAccount((String) userAccount);
        logUser.setName((String) userName);
        SystemVisitorLog.count(logUser);
      }
    }

    chain.doFilter(request, response);
  }