@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; } }
@Override public int addTeam(Corporation team) { int corpId = organizationDao.addCorporation(team); for (String account : team.getAccountList()) { if (account == null || account.trim().isEmpty()) continue; User u = accountMgr.getUser(account); if (u.getId() == team.getUserId()) { // if the user is creator, there's no need to add again continue; } organizationDao.addUserToCorp(corpId, u.getId(), 3); // 3, normal member } return corpId; }
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; }
public boolean addMember(User user) { // if member added is the creator, ignore if (user.getId() == getUser().getId()) return false; // if member already exists, ignore boolean exist = false; for (User item : getUserList()) { if (item.getId() == user.getId()) { exist = true; } } if (exist) return false; // validation complete, add this user getUserList().add(user); user.getJoinedProjectList().add(this); return true; }
public boolean isUserMember(int userId) { if (getUserId() == userId) return true; for (User u : getUserList()) { if (u.getId() == userId) return true; } return false; }
@Override public boolean addTeamMembers(long curUserId, int corpId, String accountList) { if (!canUserManageCorp(curUserId, corpId)) return false; String[] accs = accountList.split(","); Corporation c = getCorporation(corpId); for (String acc : accs) { User u = accountMgr.getUser(acc); if (u != null) { if (!organizationDao.isUserInCorp(u.getId(), corpId) && u.getId() != c.getUserId()) { organizationDao.addUserToCorp(corpId, u.getId(), 3); } } } return true; }
@Override public List<User> getUserLisOfCorp(int corpId) { List<User> list = organizationDao.getUserLisOfCorp(corpId); Corporation c = getCorporation(corpId); User u = accountMgr.getUser(c.getUserId()); list.add(u); for (User user : list) { int roleId = getUserRoleInCorp(user.getId(), corpId); if (user.isAdmin()) { roleId = 1; // user is the RAP platform admin } else if (user.getId() == c.getUserId()) { roleId = 1; // user is the author } user.setRoleId(roleId); } return list; }
@Override public List<Project> getProjectList(User user, int curPageNum, int pageSize) { List<Project> projectList = projectDao.getProjectList(user, curPageNum, pageSize); for (Project p : projectList) { if (user.isUserInRole("admin") || p.getUser().getId() == user.getId()) p.setIsManagable(true); } return projectList; }
@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; } }
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(); }
@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); }