Exemplo n.º 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;
    }
  }
Exemplo n.º 2
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);
  }