Пример #1
0
  public String doRegister() {
    if (!StringUtils.validateName(getName())) {
      setErrMsg(StringUtils.NAME_FORMAT_WARN_MSG);
      return ERROR;
    }

    if (!StringUtils.validateAccount(getAccount())) {
      setErrMsg(StringUtils.ACCOUNT_FORMAT_WARN_MSG);
      return ERROR;
    }

    User user = new User();
    user.setAccount(getAccount());
    user.setPassword(getPassword());
    user.setName(getName());
    user.setEmail(getEmail());

    String validateMsg = getAccountMgr().validatePasswordFormat(getPassword());
    if (validateMsg != null) {
      setErrMsg(validateMsg);
      return ERROR;
    }

    if (getAccountMgr().getUserId(user.getAccount()) > 0) {
      setErrMsg("该用户名" + user.getAccount() + "已经存在咯~~~");
      return ERROR;
    } else if (super.getAccountMgr().addUser(user)) {
      return doLogin();
    } else {
      return ERROR;
    }
  }
Пример #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;
   }
 }
Пример #3
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;
  }
Пример #4
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();
 }
Пример #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;
  }
Пример #6
0
  @Override
  public int updateProject(Project outerProject) {
    Project project = getProject(outerProject.getId());
    project.setName(outerProject.getName());
    project.setIntroduction(outerProject.getIntroduction());
    project.setUpdateTime(new Date());

    if (outerProject.getMemberAccountList() != null) {
      // adding new ones
      for (String account : outerProject.getMemberAccountList()) {
        User user = accountDao.getUser(account);
        if (user != null) {
          boolean addSuccess = project.addMember(user);
          if (addSuccess) {
            Notification o = new Notification();
            o.setTypeId((short) 2);
            o.setTargetUser(outerProject.getUser());
            o.setUser(user);
            o.setParam1(new Integer(outerProject.getId()).toString());
            o.setParam2(outerProject.getName());
            accountMgr.addNotification(o);
          }
        }
      }

      if (project.getUserList() != null) {
        // remove old ones
        List<User> userListToBeRemoved = new ArrayList<User>();
        for (User user : project.getUserList()) {
          if (!outerProject.getMemberAccountList().contains(user.getAccount())) {
            userListToBeRemoved.add(user);
          }
        }

        for (User user : userListToBeRemoved) {
          project.removeMember(user);
        }
      }
    }

    return projectDao.updateProject(project);
  }
Пример #7
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;
    }
  }
Пример #8
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);
  }