@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { String thisUsersId = req.getParameter("userId"); if ("true".equals(req.getParameter("pingAlive"))) { updateLastAliveTime(thisUsersId); } else { ObjectMapper mapper = new ObjectMapper(); ArrayNode usersArray = mapper.createArrayNode(); for (Map.Entry<String, User> userEntry : users.entrySet()) { if (!thisUsersId.equals(userEntry.getKey())) { User user = userEntry.getValue(); Date now = new Date(); if ((now.getTime() - user.getLastAliveTime().getTime()) / 1000 <= 10) { ObjectNode userJson = mapper.createObjectNode(); userJson.put("user_id", userEntry.getKey()); userJson.put("user_name", user.getName()); usersArray.add(userJson); } } } ObjectNode usersJson = mapper.createObjectNode(); usersJson.put("opponents", usersArray); resp.setContentType("application/json; charset=UTF-8"); mapper.writeValue(resp.getWriter(), usersJson); } }
private void _buildParentGroupsBreadcrumb( LayoutSet layoutSet, PortletURL portletURL, ThemeDisplay themeDisplay, StringBundler sb) throws Exception { Group group = layoutSet.getGroup(); if (group.isOrganization()) { Organization organization = OrganizationLocalServiceUtil.getOrganization(group.getOrganizationId()); Organization parentOrganization = organization.getParentOrganization(); if (parentOrganization != null) { Group parentGroup = parentOrganization.getGroup(); LayoutSet parentLayoutSet = LayoutSetLocalServiceUtil.getLayoutSet( parentGroup.getGroupId(), layoutSet.isPrivateLayout()); _buildParentGroupsBreadcrumb(parentLayoutSet, portletURL, themeDisplay, sb); } } else if (group.isUser()) { User groupUser = UserLocalServiceUtil.getUser(group.getClassPK()); List<Organization> organizations = OrganizationLocalServiceUtil.getUserOrganizations(groupUser.getUserId(), true); if (!organizations.isEmpty()) { Organization organization = organizations.get(0); Group parentGroup = organization.getGroup(); LayoutSet parentLayoutSet = LayoutSetLocalServiceUtil.getLayoutSet( parentGroup.getGroupId(), layoutSet.isPrivateLayout()); _buildParentGroupsBreadcrumb(parentLayoutSet, portletURL, themeDisplay, sb); } } int layoutsPageCount = 0; if (layoutSet.isPrivateLayout()) { layoutsPageCount = group.getPrivateLayoutsPageCount(); } else { layoutsPageCount = group.getPublicLayoutsPageCount(); } if ((layoutsPageCount > 0) && !group.getName().equals(GroupConstants.GUEST)) { String layoutSetFriendlyURL = PortalUtil.getLayoutSetFriendlyURL(layoutSet, themeDisplay); sb.append("<li><span><a href=\""); sb.append(layoutSetFriendlyURL); sb.append("\">"); sb.append(HtmlUtil.escape(group.getDescriptiveName())); sb.append("</a></span></li>"); } }
private void handleSignupPost(Request request, HttpServletResponse httpServletResponse) throws Exception { String userId = request.getParameter(PARAM_USER_ID); String userName = request.getParameter(PARAM_USER_NAME); String email = request.getParameter(PARAM_EMAIL); String stringPassword = request.getParameter(PARAM_PASSWORD); String stringPasswordConfirm = request.getParameter(PARAM_PASSWORD_CONFIRM); if (!stringPassword.equals(stringPasswordConfirm)) { WebUtils.redirectToError( "Mismatch between password and password confirmation", request, httpServletResponse); return; } SecureRandom secureRandom = new SecureRandom(); String salt = "" + secureRandom.nextLong(); byte[] password = User.computeHashedPassword(stringPassword, salt); User user = userDb.get(userId); if (user != null) { WebUtils.redirectToError( "There already exists a user with the ID " + userId, request, httpServletResponse); return; } user = new User( userId, userName, password, salt, email, new ArrayList<String>(), Config.getConfig().activateAccountsAtCreation, false); // ttt2 add confirmation by email, captcha, ... List<String> fieldErrors = user.checkFields(); if (!fieldErrors.isEmpty()) { StringBuilder bld = new StringBuilder("Invalid values when trying to create user with ID ") .append(userId) .append("<br/>"); for (String s : fieldErrors) { bld.append(s).append("<br/>"); } WebUtils.redirectToError(bld.toString(), request, httpServletResponse); return; } // ttt2 2 clients can add the same userId simultaneously userDb.add(user); httpServletResponse.sendRedirect("/"); }
private void printUserInformation(PrintWriter out, User user) { out.println("<table>"); out.println("<tr><th>username</th>"); out.println("<th>user first name</th>"); out.println("<th>user last name</th>"); out.println("<th>user E-mail</th></tr>"); out.println("<tr><td>" + user.getUserName() + "</td>"); out.println("<td>" + user.getFirstName() + " </td>"); out.println("<td>" + user.getLastName() + "</td>"); out.println("<td>" + user.getEmail() + "</td></tr>"); out.println("</table>"); }
// new version without group ds combunation private void printUserGroupList(PrintWriter out, User user) { Group group = null; String label = null; String groupName = null; String groupType = null; String userName = user.getUserName(); if (user.getGroupList().size() == 0) { out.println("<p>No group is selected.</p>"); } else { out.println("<table >"); out.println("<tr><th> group name </th>"); out.println("<th> group structure</th>"); out.println("<th> user choice</th>"); out.println("<th> admin decision</th>"); out.println("<th> admin decision</th></tr>"); for (int i = 0; i < user.getGroupList().size(); i++) { group = (Group) (user.getGroupList().get(i)); groupName = group.getGroupName(); groupType = group.getGroupType(); if (groupType.equals("5")) { label = " user wants to add this group "; } else if (groupType.equals("0")) { label = " user wants to delete this group "; } out.println("<tr><td>" + groupName + "</td>"); this.printGroupStructureLink(out, group.getGroupName()); out.println("<td>" + label + " </td>"); out.println("<FORM ACTION=/gsn/MyUpdateUserGroupServlet METHOD=POST>"); out.println("<INPUT TYPE=HIDDEN NAME=groupname VALUE=" + groupName + ">"); out.println("<INPUT TYPE=HIDDEN NAME=grouptype VALUE=" + groupType + ">"); out.println("<INPUT TYPE=HIDDEN NAME=username VALUE= " + userName + ">"); out.println("<INPUT TYPE=HIDDEN NAME=update VALUE= yes>"); out.println( "<td><INPUT TYPE=SUBMIT class=creategroupbuttonstyle VALUE=\"agree to update\"></td>"); out.println("</FORM>"); out.println("<FORM ACTION=/gsn/MyUpdateUserGroupServlet METHOD=POST>"); out.println("<INPUT TYPE=HIDDEN NAME=groupname VALUE=" + groupName + ">"); out.println("<INPUT TYPE=HIDDEN NAME=grouptype VALUE=" + groupType + ">"); out.println("<INPUT TYPE=HIDDEN NAME=username VALUE= " + userName + ">"); out.println("<INPUT TYPE=HIDDEN NAME=update VALUE= no>"); out.println( "<td><INPUT TYPE=SUBMIT class=creategroupbuttonstyle VALUE=\"refuse to update\"></td></tr>"); out.println("</FORM>"); } out.println("</table>"); } }
private void printRemainingDataSourcesList(PrintWriter out, User user, ConnectToDB ctdb) throws SQLException { DataSource dataSource = null; String dataSourceName = null; Vector remainingDataSourcesList = ctdb.getDataSourceListsDifference( this.dataSourceVectorForDataSourceNames( ctdb.getValuesVectorForOneColumnUnderOneCondition( new Column("DATASOURCENAME"), new Column("ISCANDIDATE", "no"), "ACDATASOURCE")), user.getDataSourceList()); if (remainingDataSourcesList.size() == 0) { out.println("<table class=transparenttable>"); out.println("<tr><td><FONT COLOR=#000000>No virtaul sensor is available.</td></tr>"); out.println("</table>"); } else { out.println("<table>"); out.println("<tr><th> virtual sensor name </th>"); out.println("<th> access right</th></tr>"); for (int i = 0; i < remainingDataSourcesList.size(); i++) { dataSource = (DataSource) (remainingDataSourcesList.get(i)); dataSourceName = dataSource.getDataSourceName(); if (ctdb.valueExistsForThisColumnUnderTwoConditions( new Column("ISUSERWAITING", "yes"), new Column("USERNAME", user.getUserName()), new Column("DATASOURCENAME", dataSource.getDataSourceName()), "ACUSER_ACDATASOURCE")) { out.println("<tr><td>" + dataSourceName + " </td>"); } else { out.println("<FORM ACTION=/gsn/MyUpdateUserWaitingForDataSourceServlet METHOD=POST>"); out.println("<tr><td>" + dataSourceName + " </td>"); out.println("<td><INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE= 1> read "); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE= 2> write "); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE=3> read/write "); } if (ctdb.valueExistsForThisColumnUnderTwoConditions( new Column("ISUSERWAITING", "yes"), new Column("USERNAME", user.getUserName()), new Column("DATASOURCENAME", dataSource.getDataSourceName()), "ACUSER_ACDATASOURCE")) { out.println("<td>" + "<FONT COLOR=#0000FF>in updates waiting list!</td></tr>"); } else { out.println( "   <INPUT TYPE=SUBMIT TYPE=SUBMIT class= buttonstyle VALUE=\"add\"></td></tr>"); out.println("</FORM>"); } } out.println("</table>"); } }
private void handleChangePasswordPost(Request request, HttpServletResponse httpServletResponse) throws Exception { LoginInfo loginInfo = userHelpers.getLoginInfo(request); if (loginInfo == null) { WebUtils.redirectToError("Couldn't determine the current user", request, httpServletResponse); return; } String userId = loginInfo.userId; String stringCrtPassword = request.getParameter(PARAM_CURRENT_PASSWORD); String stringNewPassword = request.getParameter(PARAM_PASSWORD); String stringNewPasswordConfirm = request.getParameter(PARAM_PASSWORD_CONFIRM); if (!stringNewPassword.equals(stringNewPasswordConfirm)) { showResult( "Mismatch between password and password confirmation", PATH_SETTINGS, request, httpServletResponse); return; } User user = userDb.get( userId); // ttt1 crashes for wrong ID; 2013.07.20 - no longer have an idea what this is // about if (user == null) { WebUtils.redirectToError("Couldn't find the current user", request, httpServletResponse); return; } if (!user.checkPassword(stringCrtPassword)) { showResult("Incorrect current password", PATH_SETTINGS, request, httpServletResponse); return; } SecureRandom secureRandom = new SecureRandom(); String salt = "" + secureRandom.nextLong(); byte[] password = User.computeHashedPassword(stringNewPassword, salt); user.salt = salt; user.password = password; // ttt3 2 clients can change the password simultaneously userDb.add(user); // httpServletResponse.sendRedirect(PATH_SETTINGS); showResult("Password changed", PATH_SETTINGS, request, httpServletResponse); }
/** * ************************************************************************************************* */ public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); ConnectToDB ctdb = null; // Get the session HttpSession session = req.getSession(); User user = (User) session.getAttribute("user"); if (user == null) { this.redirectToLogin(req, res); } else { this.checkSessionScheme(req, res); if (user.isAdmin() == false) { res.sendError(WebConstants.ACCESS_DENIED, "Access denied."); } else { this.printHeader(out); this.printLayoutMastHead(out, user); this.printLayoutContent(out); try { ctdb = new ConnectToDB(); Vector waitingUsers = ctdb.getWaitingUsers(); if (waitingUsers.size() == 0) { out.println("<p><B> There is no entry in the waiting user list !</B> </p>"); } for (int i = 0; i < waitingUsers.size(); i++) { // printForm(out,(User)(waitingUsers.get(i))); this.printNewEntry(out, (User) (waitingUsers.get(i))); } } catch (Exception e) { out.println("<p><B> Can not print the form</B> </p>"); logger.error("ERROR IN DOGET"); logger.error(e.getMessage(), e); } finally { if (ctdb != null) { ctdb.closeStatement(); ctdb.closeConnection(); } } // out.println("</BODY>"); this.printLayoutFooter(out); } } }
protected void create(String[] params, HttpServletRequest request, HttpServletResponse response) { PrintWriter writer; IUser user; ISocialmore sm; Integer count; MultipartMap map; ArrayList<String> attaches = new ArrayList<>(); sm = Socialmore.connect(this); user = User.getSession(request); try { map = new MultipartMap(request, this); writer = response.getWriter(); count = Integer.parseInt(map.getParameter("count")); if (count == null || user == null || sm == null) { writer.write(""); return; } File file; for (int i = 0; i < count; i++) { file = map.getFile("attach" + i); writer.write("/assets/attaches/" + file.getName() + ";"); } } catch (IOException | ServletException e1) { } }
private void printRemainingGroupsList(PrintWriter out, User user, ConnectToDB ctdb) throws SQLException { Vector remainingGroupList = ctdb.getGroupListsDifference(ctdb.getGroupList(), user.getGroupList()); Group group = null; String groupName = null; String userName = user.getUserName(); if (remainingGroupList.size() == 0) { out.println("<table class =transparenttable>"); out.println("<tr><td><FONT COLOR=#000000>No group is available.</td></tr>"); out.println("</table>"); } else { out.println("<table>"); out.println("<tr>"); out.println("<th>group name</th>"); out.println("<th>group structure</th>"); out.println("<th>updates</th>"); out.println("</tr>"); for (int i = 0; i < remainingGroupList.size(); i++) { group = (Group) (remainingGroupList.get(i)); groupName = group.getGroupName(); out.println("<tr>"); out.println("<td>" + groupName + "</td>"); this.printGroupStructureLink(out, groupName); if (ctdb.valueExistsForThisColumnUnderTwoConditions( new Column("ISUSERWAITING", "yes"), new Column("GROUPNAME", groupName), new Column("USERNAME", userName), "ACUSER_ACGROUP") == false) { out.println("<FORM ACTION=/gsn/MyUpdateUserWaitingForGroupServlet METHOD=POST>"); out.println("<INPUT TYPE=HIDDEN NAME=groupname VALUE=" + groupName + ">"); out.println("<INPUT TYPE=HIDDEN NAME=addgroup VALUE=Yes>"); out.println( "<td style=text-align:center><INPUT TYPE=SUBMIT class= buttonstyle VALUE=\"add\"></td>"); out.println("</FORM>"); } else { out.println("<td>" + "<FONT COLOR=#0000FF>in updates waiting list!</td>"); } out.println("</tr>"); } out.println("</table>"); } }
private void printGroupListModulo(PrintWriter out, User user, int index) { Group group = null; String label = null; String groupName = null; String groupType = null; String userName = user.getUserName(); group = (Group) (user.getGroupList().get(index)); groupName = group.getGroupName(); groupType = group.getGroupType(); if (groupType.equals("5")) { label = " user wants to add this group "; } else if (groupType.equals("0")) { label = " user wants to delete this group "; } out.println("<table class=\"transparenttable\">"); out.println("<tr><td><B>groupname: </B>" + groupName + "</td></tr>"); out.println("<tr><td><B>user choice: </B>" + label + " </td></tr>"); out.println("</table>"); out.println("<BR>"); this.printGroupDataSourceList(out, group); out.println("<BR>"); out.println("<FORM ACTION=/gsn/MyUpdateUserGroupServlet METHOD=POST>"); out.println("<INPUT TYPE=HIDDEN NAME=groupname VALUE=" + groupName + ">"); out.println("<INPUT TYPE=HIDDEN NAME=grouptype VALUE=" + groupType + ">"); out.println("<INPUT TYPE=HIDDEN NAME=username VALUE= " + userName + ">"); out.println("<INPUT TYPE=HIDDEN NAME=update VALUE= yes>"); out.println("<table class=\"transparenttable\">"); out.println( "<td><INPUT TYPE=SUBMIT class=creategroupbuttonstyle VALUE=\"agree to update\"></td>"); out.println("</FORM>"); out.println("<FORM ACTION=/gsn/MyUpdateUserGroupServlet METHOD=POST>"); out.println("<INPUT TYPE=HIDDEN NAME=groupname VALUE=" + groupName + ">"); out.println("<INPUT TYPE=HIDDEN NAME=grouptype VALUE=" + groupType + ">"); out.println("<INPUT TYPE=HIDDEN NAME=username VALUE= " + userName + ">"); out.println("<INPUT TYPE=HIDDEN NAME=update VALUE= no>"); out.println( "<td><INPUT TYPE=SUBMIT class=creategroupbuttonstyle VALUE=\"refuse to update\"></td></tr>"); out.println("</FORM>"); out.println("</table>"); }
/** checks database for this user */ private boolean realAuthentication(HttpServletRequest request, ConnectionPool conPool) throws SQLException { // user authentication is required! User user = (User) request.getSession().getAttribute(StringInterface.USERATTR); if (user == null) { return false; } Connection con = conPool.getConnection(); boolean authenticated = false; try { authenticated = userUtils.confirmUserWithEncrypted(user.getID(), user.getEncrypted(), con); } catch (Exception e) { throw new SQLException(e.getMessage()); } finally { conPool.free(con); con = null; } return authenticated; } // end realAuthentication
/** * Creates a notification to a Group coordinator signaling that a user wants to join their group * * <p>- Requires a groupId request parameter for the GET * * @param req The HTTP Request * @param res The HTTP Response */ public void inviteAction(HttpServletRequest req, HttpServletResponse res) { // Ensure there is a cookie for the session user if (AccountController.redirectIfNoCookie(req, res)) return; Map<String, Object> viewData = new HashMap<String, Object>(); int groupId = Integer.parseInt(req.getParameter("groupId")); try { // Get the session user HttpSession session = req.getSession(); Session userSession = (Session) session.getAttribute("userSession"); User user = userSession.getUser(); // Get the coordinator for the group GroupManager groupMan = new GroupManager(); Group group = groupMan.get(groupId); User coordinator = groupMan.getCoordinator(groupId); // Send a notification to the coordinator for them to permit access to the group NotificationManager notificationMan = new NotificationManager(); Notification notification = new Notification( coordinator.getId(), coordinator, groupId, group, user.getFullName() + " wants to join your group " + group.getGroupName(), "/home/notifications?addUserId=" + user.getId() + "&groupId=" + group.getId()); notificationMan.createNotification(notification); redirectToLocal(req, res, "/home/dashboard"); return; } catch (Exception e) { redirectToLocal(req, res, "/home/dashboard"); } }
/** * Creates a GPX-formatted file attachment for the given entry. * * @param user * @param entryId * @param fileName * @param activityId * @param track * @param track */ public void createAttachment( User user, int entryId, String fileName, String title, String activityId, GpsTrack track) throws DataAccessException, IOException { Attachment a = new Attachment(); a.setUserName(user.getUserName()); a.setUserId(user.getUserId()); a.setEntryId(entryId); a.setFileType("map"); a.setFileName(fileName); a.setActivityId(activityId); a.setTitle(title); GpxFormatter formatter = new GpxFormatter(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); List<GpsTrack> tracks = new ArrayList<GpsTrack>(); tracks.add(track); formatter.format(tracks, baos); log.debug(new String(baos.toByteArray())); a.setBytes(baos.toByteArray()); new AttachmentDao().create(a); }
protected void index(HttpServletRequest request, HttpServletResponse response) { ISocialmore sm = Socialmore.connect(this); IUser user = User.getSession(request); if (sm == null || user == null) { forwardTo(request, response, "Sessions/login"); return; } try { ArrayList<IMessage> inbox = (ArrayList<IMessage>) user.getInbox(); request.setAttribute("inbox", inbox); } catch (RemoteException e) { request.setAttribute("flash", "We are sorry! :( Your inbox is temporaly unavailable..."); forwardTo(request, response, "Users/index"); } forwardTo(request, response, "Messages/index"); }
protected void show(String[] params, HttpServletRequest request, HttpServletResponse response) { ISocialmore sm = Socialmore.connect(this); if (sm == null || User.getSession(request) == null) { forwardTo(request, response, "Sessions/login"); return; } IUser dest; try { dest = sm.getUserByID(Integer.parseInt(params[1])); } catch (NumberFormatException | RemoteException e) { forwardTo(request, response, "Users/index"); return; } request.setAttribute("dest", dest); index(request, response); }
protected void update(String[] params, HttpServletRequest request, HttpServletResponse response) { ISocialmore sm; IUser user; IPost post; HttpSession session = request.getSession(); if (session.getAttribute("user") == null) { forwardTo(request, response, "Sessions/login"); return; } sm = Socialmore.connect(this); user = User.getSession(request); int post_id = -1; try { post_id = Integer.parseInt(params[1]); } catch (Exception e) { } String content = request.getParameter("content"); try { post = sm.getPost(post_id); if (post != null && !content.isEmpty()) { System.out.println("Edit: " + user.getID() + " with " + content); post.edit(user.getID(), content); System.out.println("Edited!!! :D"); } } catch (RemoteException e) { System.out.println("Fail!"); } forwardTo(request, response, "Users/index"); }
private void handleLoginPost( Request request, HttpServletResponse httpServletResponse, boolean secured) throws Exception { String userId = request.getParameter(PARAM_USER_ID); String password = request.getParameter(PARAM_PASSWORD); String rememberAccountStr = request.getParameter(PARAM_REMEMBER_ACCOUNT); boolean rememberAccount = Boolean.parseBoolean(rememberAccountStr); LoginInfo.SessionInfo sessionInfo = UserHelpers.getSessionInfo(request); logOut(sessionInfo.browserId); User user = userDb.get(userId); if (user == null) { WebUtils.redirectToError("User " + userId + " not found", request, httpServletResponse); return; } if (!user.checkPassword(password)) { WebUtils.redirectToError("Invalid password", request, httpServletResponse); return; } if (!user.active) { WebUtils.redirectToError( "Account for User " + userId + " needs to be activated", request, httpServletResponse); return; } LOG.info("Logged in user " + userId); sessionInfo.sessionId = null; if (sessionInfo.browserId == null) { sessionInfo.browserId = getRandomId(); } else { for (LoginInfo loginInfo : loginInfoDb.getLoginsForBrowser(sessionInfo.browserId)) { if (userId.equals(loginInfo.userId)) { sessionInfo.sessionId = loginInfo.sessionId; break; } } } long expireOn = System.currentTimeMillis() + Config.getConfig().loginExpireInterval; if (sessionInfo.sessionId == null) { sessionInfo.sessionId = getRandomId(); Config config = Config.getConfig(); loginInfoDb.add( new LoginInfo( sessionInfo.browserId, sessionInfo.sessionId, userId, expireOn, rememberAccount, config.defaultStyle, config.defaultItemsPerPage, config.defaultFeedDateFormat)); LOG.info(String.format("Logging in in a new session. User: %s", user)); } else { loginInfoDb.updateExpireTime(sessionInfo.browserId, sessionInfo.sessionId, expireOn); LOG.info(String.format("Logging in in an existing session. User: %s", user)); } WebUtils.saveCookies( httpServletResponse, secured, sessionInfo.browserId, sessionInfo.sessionId); httpServletResponse.sendRedirect("/"); }
protected void delete(String[] params, HttpServletRequest request, HttpServletResponse response) { IUser user; ISocialmore sm; IPost post; IMessage msg; int msg_id, post_id = -1; HttpSession session = request.getSession(); sm = Socialmore.connect(this); user = User.getSession(request); if (sm == null || user == null) { forwardTo(request, response, "Sessions/login"); return; } if (params[0].equalsIgnoreCase("cancel-message")) { try { ArrayList<IMessage> inbox = (ArrayList<IMessage>) user.getInbox(); request.setAttribute("inbox", inbox); } catch (RemoteException e1) { forwardTo(request, response, "Users/index"); return; } try { msg_id = Integer.parseInt(params[1]); msg = user.getSentMessage(msg_id); if (user.getID() == msg.getSenderID() && msg.getReceiving() == null) { if (user.removeMessage(msg_id)) { request.setAttribute("flash_type", "alert-success"); request.setAttribute("flash", "Your scheduled message was cancelled!"); forwardTo(request, response, "Messages/index"); return; } } } catch (Exception e) { } request.setAttribute("flash_type", "alert-error"); request.setAttribute( "flash", "It was <b>not</b> possible to remove the schedule message specified"); forwardTo(request, response, "Messages/index"); return; } try { post_id = Integer.parseInt(params[1]); } catch (Exception e) { } try { post = sm.getPost(post_id); if (post != null) { post.delete(user.getID()); System.out.println("Delete " + post_id); } } catch (RemoteException e) { } forwardTo(request, response, "Users/index"); }
private void printUserName(PrintWriter out, User user) { // String username=user.getUserName(); out.println("<p id=\"login\">logged in as : " + user.getUserName() + "</p>"); }
protected ModelAndView handleRequestInternal( HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> map = new HashMap<String, Object>(); // String id = request.getParameter("id"); // MediaFile mediaFile = mediaFileService.getMediaFile(path); int listOffset = DEFAULT_LIST_OFFSET; int listSize = DEFAULT_LIST_SIZE; String listType = DEFAULT_LIST_TYPE; User user = securityService.getCurrentUser(request); String username = user.getUsername(); UserSettings userSettings = settingsService.getUserSettings(username); int userGroupId = securityService.getCurrentUserGroupId(request); if (request.getParameter("listOffset") != null) { listOffset = Math.max( 0, Math.min(Integer.parseInt(request.getParameter("listOffset")), MAX_LIST_OFFSET)); } if (request.getParameter("listSize") != null) { listSize = Math.max(0, Math.min(Integer.parseInt(request.getParameter("listSize")), MAX_LIST_SIZE)); } if (request.getParameter("listType") != null) { listType = String.valueOf(request.getParameter("listType")); } List<MediaFile> songs; if ("topplayed".equals(listType)) { songs = mediaFileDao.getTopPlayedCountForUser(listOffset, listSize, username); } else if ("otheruser".equals(listType)) { songs = mediaFileDao.getLastPlayedCountForAllUser(listOffset, listSize, userGroupId); } else if ("overall".equals(listType)) { songs = mediaFileDao.getTopPlayedCountForAllUser(listOffset, listSize, userGroupId); } else if ("lastplayed".equals(listType)) { songs = mediaFileDao.getLastPlayedCountForUser(listOffset, listSize, username); } else { songs = mediaFileDao.getLastPlayedCountForAllUser(0, 1, userGroupId); } mediaFileService.populateStarredDate(songs, username); map.put("user", user); map.put("songs", songs); map.put("partyModeEnabled", userSettings.isPartyModeEnabled()); map.put("player", playerService.getPlayer(request, response)); map.put("listOffset", listOffset); map.put("listSize", listSize); map.put("listType", listType); // map.put("starred", mediaFileService.getMediaFileStarredDate(dir.getId(), username) != null); ModelAndView result = super.handleRequestInternal(request, response); result.addObject("model", map); return result; }
/** * Displays a given Research Group page for a HTTP Get, or creates a new Group for a HTTP Post * * <p>- Requires a cookie for the session user - Requires a groupId request parameter for a GET - * Requires a groupName, description, createdByUserId request parameters for a POST * * @param req The HTTP Request * @param res The HTTP Response */ public void researchgroupAction(HttpServletRequest req, HttpServletResponse res) { // Ensure there is a cookie for the session user if (AccountController.redirectIfNoCookie(req, res)) return; Map<String, Object> viewData = new HashMap<String, Object>(); viewData.put("title", "Research Group"); if (req.getMethod() == HttpMethod.Get) { // Load group data into Map GroupManager gm = new GroupManager(); int groupId = Integer.parseInt(req.getParameter("groupId")); Group group = gm.get(groupId); if (group != null) { // Load Group into map viewData.put("group", group); // Load group members into Map List<String> groupMembers = gm.getGroupMembers(groupId); viewData.put("groupMembers", groupMembers); // Load meetings into map MeetingManager meetMan = new MeetingManager(); List<Meeting> groupMeetings = meetMan.getGroupMeetings(groupId); viewData.put("groupMeetings", groupMeetings); // Load Document Data into Map DocumentManager docMan = new DocumentManager(); List<Document> groupDocuments = docMan.getGroupDocuments(groupId); viewData.put("groupDocuments", groupDocuments); // Load discussion threads DiscussionManager dm = new DiscussionManager(); viewData.put("groupDiscussions", dm.getThreads(groupId)); // Check if the user is a member boolean isMember = false; HttpSession session = req.getSession(); Session userSession = (Session) session.getAttribute("userSession"); User user = userSession.getUser(); for (Group g : gm.getAllGroups(user.getId())) { if (g.getId() == group.getId()) { isMember = true; break; } } viewData.put("notMember", !isMember); // View group page. view(req, res, "/views/group/ResearchGroup.jsp", viewData); } else { httpNotFound(req, res); } } else if (req.getMethod() == HttpMethod.Post) { // Create Group // Get data from parameters String groupName = req.getParameter("groupName"); String description = req.getParameter("description"); int adminId = Integer.parseInt(req.getParameter("createdByUserId")); // Create the Group GroupManager groupMan = new GroupManager(); Group group = new Group(); group.setGroupName(groupName); group.setDescription(description); group.setCoordinatorId(adminId); // Create the mapping groupMan.createGroup(group); int groupId = groupMan.getIdFor(group); groupMan.createMapping(groupId, adminId); group.setId(groupId); // Update the User Session to show new group HttpSession session = req.getSession(); Session userSession = (Session) session.getAttribute("userSession"); User admin = userSession.getUser(); admin.getGroups().add(group); // Show the Group Page viewData.put("groupName", group.getGroupName()); List<String> groupMembers = groupMan.getGroupMembers(groupId); viewData.put("groupMembers", groupMembers); view(req, res, "/views/group/ResearchGroup.jsp", viewData); } }
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { JspFactory _jspxFactory = null; javax.servlet.jsp.PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; try { _jspxFactory = JspFactory.getDefaultFactory(); response.setContentType("text/html;charset=ISO-8859-1"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); User user = null; UserFactory userFactory = UserFactory.getInstance(); String userID = request.getParameter("userID"); try { UserFactory.init(); user = userFactory.getUser(userID); } catch (Exception e) { throw new ServletException("Could not find user " + userID + " in user factory.", e); } out.write("\n"); out.write("<html>\n"); out.write("<head>\n "); out.write("<title>WebTelemetry - | User Management | User Detail"); out.write("</title>\n "); out.write("<base HREF=\""); out.print(org.opennms.web.Util.calculateUrlBase(request)); out.write("\" />\n "); out.write( "<link rel=\"stylesheet\" type=\"text/css\" href=\"/wt-portal/css/default.css\" />\n\t"); out.write("<script type=\"text/javascript\" src=\"/wt-portal/javascript/WTtools.js\">"); out.write("</script>\n"); out.write("</head>\n"); out.write("<body>\n"); String title = " User Management - Detail Summary for: " + userID; out.write("\n"); /* ---- c:if ---- */ org.apache.taglibs.standard.tag.el.core.IfTag _jspx_th_c_if_0 = (org.apache.taglibs.standard.tag.el.core.IfTag) _jspx_tagPool_c_if_test.get(org.apache.taglibs.standard.tag.el.core.IfTag.class); _jspx_th_c_if_0.setPageContext(pageContext); _jspx_th_c_if_0.setParent(null); _jspx_th_c_if_0.setTest("${not param.orgAdminPopup}"); int _jspx_eval_c_if_0 = _jspx_th_c_if_0.doStartTag(); if (_jspx_eval_c_if_0 != javax.servlet.jsp.tagext.Tag.SKIP_BODY) { do { out.write("\n "); JspRuntimeLibrary.include( request, response, "/includes/header.jsp" + "?" + "title=" + java.net.URLEncoder.encode("" + title) + "&" + "help=" + "monitoringadmin%2Fusers%2FWTHelp_User.html", out, false); out.write("\n"); int evalDoAfterBody = _jspx_th_c_if_0.doAfterBody(); if (evalDoAfterBody != javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN) break; } while (true); } if (_jspx_th_c_if_0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) return; _jspx_tagPool_c_if_test.reuse(_jspx_th_c_if_0); out.write("\n"); if (_jspx_meth_c_if_1(pageContext)) return; out.write("\n\n"); out.write("<!-- BEGIN FRAMING TABLE:open tags, keep at 100%-->\n"); out.write("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\t"); out.write("<tr>\n\t\t"); out.write("<td width=\"10\">"); out.write( "<img src=\"/wt-portal/images/spacers/spacer.gif\" height=\"1\" width=\"10\" border=\"0\" alt=\"WebTelemetry\">"); out.write("</td>\n\t\t"); out.write("<td>\n"); out.write("<!-- END FRAMING TABLE:open tags, keep at 100%-->\n"); out.write("<table width=\"98%\"border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n "); out.write("<tr class=\"tableHeader\">\n "); out.write("<td class=\"tableHeader\" colspan=\"2\">User Information"); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowLight\">\n "); out.write("<td class=\"tableText\" width=\"25%\">"); out.write("<b>Full Name:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\" width=\"75%\">"); out.print(user.getFullName()); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowDark\">\n "); out.write("<td class=\"tableText\">"); out.write("<b>Comments:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\">"); out.print(user.getUserComments()); out.write("</td>\n "); out.write("</tr>\n"); out.write("</table>\n"); out.write("<br>\n"); out.write("<table width=\"98%\"border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n "); out.write("<tr class=\"tableHeader\">\n "); out.write("<td class=\"tableHeader\" colspan=\"2\">Notification Information"); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowLight\">\n "); out.write("<td class=\"tableText\" width=\"25%\">"); out.write("<b>Email:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\" width=\"75%\">"); out.print(userFactory.getEmail(userID)); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowDark\">\n "); out.write("<td class=\"tableText\">"); out.write("<b>Pager Email:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\">"); out.print(userFactory.getPagerEmail(userID)); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowLight\">\n "); out.write("<td class=\"tableText\">"); out.write("<b>Numerical Service:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\">"); out.print(userFactory.getNumericPage(userID)); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowDark\">\n "); out.write("<td class=\"tableText\">"); out.write("<b>Numerical Pin:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\">"); out.print(userFactory.getNumericPin(userID)); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowLight\">\n "); out.write("<td class=\"tableText\">"); out.write("<b>Text Service:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\">"); out.print(userFactory.getTextPage(userID)); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowDark\">\n "); out.write("<td class=\"tableText\">"); out.write("<b>Text Pin:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\">"); out.print(userFactory.getTextPin(userID)); out.write("</td>\n "); out.write("</tr>\n"); out.write("</table>\n"); out.write("<br>\n"); out.write("<table width=\"98%\"border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n "); out.write("<tr class=\"tableHeader\">\n "); out.write("<td class=\"tableHeader\" colspan=\"2\">Duty Schedules"); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowLight\">\n "); out.write("<td class=\"tableText\" colspan=\"2\">"); out.write("<br />\n "); out.write("<!-- weekly schedule -->\n "); out.write( "<table width=\"50%\" border=\"1\" bordercolor=\"#999999\" cellspacing=\"0\" cellpadding=\"2\" >\n\t\t\t"); Collection dutySchedules = user.getDutyScheduleCollection(); out.write("\n "); int i = 0; Iterator iter = dutySchedules.iterator(); while (iter.hasNext()) { DutySchedule tmp = new DutySchedule((String) iter.next()); Vector curSched = tmp.getAsVector(); i++; out.write("\n "); out.write("<tr>\n "); ChoiceFormat days = new ChoiceFormat("0#Mo|1#Tu|2#We|3#Th|4#Fr|5#Sa|6#Su"); for (int j = 0; j < 7; j++) { Boolean curDay = (Boolean) curSched.get(j); out.write("\n "); out.write("<td width=\"5%\">\n "); out.print((curDay.booleanValue() ? days.format(j) : "X")); out.write("\n "); out.write("</td>\n "); } out.write("\n "); out.write("<td width=\"5%\">\n "); out.print(curSched.get(7)); out.write("\n "); out.write("</td>\n "); out.write("<td width=\"5%\">\n "); out.print(curSched.get(8)); out.write("\n "); out.write("</td>\n "); out.write("</tr>\n "); } out.write("\n "); out.write("</table>\n "); out.write("<!-- end weekly schedule --> \n "); out.write("</td>\n "); out.write("</tr>\n "); out.write("<tr class=\"tableRowLight\">\n "); out.write("<td class=\"tableText\" colspan=\"2\">"); out.write( "<img src=\"/wt-portal/images/spacers/spacer.gif\" height=\"4\" width=\"10\" border=\"0\" alt=\"WebTelemetry\">"); out.write("</td>\n "); out.write("</tr> \n"); out.write("</table>\n"); out.write("<br>"); out.write("<br>\n"); out.write("<b>Member of the Following Organizations & Groups:"); out.write("</b>\n"); out.write("<!-- BEGIN: NEW ASSIGNED GROUPS TABLE -->\n"); out.write("<table width=\"98%\"border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\n "); // Get the user's orgs WTOrganizationDAO orgDAO = DAOImpl.OrgDAO; WTOrganization[] orgs = orgDAO.getWTOrganization(); if (orgs != null) { // Loop thru orgs for (int idx = 0; idx < orgs.length; idx++) { out.write("\n\n "); out.write("<tr class=\"tableHeader\">\n "); out.write("<td class=\"tableHeader\" colspan=\"2\">Organization Name: "); out.print(orgs[idx].getName()); out.write("</td>\n\t"); out.write("</tr>\n "); out.write("<tr class=\"tableRowLight\">\n "); out.write("<td class=\"tableText\" width=\"25%\">"); out.write("<b>Assigned Groups:"); out.write("</b>"); out.write("</td>\n "); out.write("<td class=\"tableText\" width=\"75%\">\n "); // Get the orgs groups WTGroupManager grpMgr = ManagersImpl.GroupManager; int[] orgids = {orgs[idx].getID()}; List groups = grpMgr.getUserGroups(user.getUserId(), orgids); if (groups != null) { // Loop thru the groups for (Iterator iterGrps = groups.iterator(); iterGrps.hasNext(); ) { WTGroup group = (WTGroup) iterGrps.next(); WTRole role = (group.getRoles() == null ? null : (WTRole) group.getRoles().get(0)); out.write("\n "); out.print(group.getName()); out.write(" ("); out.print((role == null ? "" : role.getName())); out.write(")"); out.write("<br/>\n "); } } out.write("\n\n "); out.write("</td>\n\t"); out.write("</tr>\n\n "); } } out.write("\n\n "); out.write("<tr class=\"tableRowLight\">\n "); out.write("<td class=\"tableText\" colspan=\"2\">"); out.write( "<img src=\"/wt-portal/images/spacers/spacer.gif\" height=\"4\" width=\"10\" border=\"0\" alt=\"WebTelemetry\">"); out.write("</td>\n "); out.write("</tr> \n"); out.write("</table>\n"); out.write("<!-- END: NEW ASSIGNED GROUPS TABLE -->\n\n\n"); out.write("<!-- BEGIN FRAMING TABLE:close tags-->\n\t\t"); out.write("</td>\n\t"); out.write("</tr>\n"); out.write("</table>\n"); out.write("<!-- END FRAMING TABLE:close tags-->\n"); out.write("<br>\n\n"); JspRuntimeLibrary.include(request, response, "/includes/footer.jsp", out, false); out.write("\n"); out.write("</body>\n"); out.write("</html>\n\n"); } catch (Throwable t) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (pageContext != null) pageContext.handlePageException(t); } finally { if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext); } }
private void printUserDataSourceList(PrintWriter out, User user, ConnectToDB ctdb) throws SQLException { DataSource dataSource = null; String dataSourceName = null; String dataSourceType = null; if (user.getDataSourceList().size() == 0) { out.println("<table class =transparenttable>"); out.println("<tr><td><FONT COLOR=#000000>No virtaul sensor is available.</td></tr>"); out.println("</table>"); } else { out.println("<table>"); out.println("<tr><th> virtual sensor name </th>"); out.println("<th> access right</th></tr>"); for (int j = 0; j < user.getDataSourceList().size(); j++) { dataSource = (DataSource) user.getDataSourceList().get(j); dataSourceName = dataSource.getDataSourceName(); dataSourceType = dataSource.getDataSourceType(); if (dataSourceType.equals("4")) { out.println("<tr><td>" + dataSourceName + " </td>"); out.println("<td>own</td></tr>"); } else { if (ctdb.valueExistsForThisColumnUnderTwoConditions( new Column("ISUSERWAITING", "yes"), new Column("USERNAME", user.getUserName()), new Column("DATASOURCENAME", dataSourceName), "ACUSER_ACDATASOURCE")) { out.println("<tr><td>" + dataSourceName + " </td>"); } else { out.println("<FORM ACTION=/gsn/MyUpdateUserWaitingForDataSourceServlet METHOD=POST>"); out.println("<tr><td>" + dataSourceName + " </td>"); if (dataSourceType.charAt(0) == '1') { out.println( "<td><INPUT CHECKED TYPE=RADIO NAME=" + dataSourceName + " VALUE= 1>read"); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE= 2>write "); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE=3>read/write"); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE=0>delete "); } if (dataSourceType.charAt(0) == '2') { out.println("<td><INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE= 1> read "); out.println("<INPUT CHECKED TYPE=RADIO NAME=" + dataSourceName + " VALUE= 2> write "); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE=3> read/write "); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE=0> delete "); } if (dataSourceType.charAt(0) == '3') { out.println("<td><INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE= 1> read "); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE= 2> write "); out.println( "<INPUT CHECKED TYPE=RADIO NAME=" + dataSourceName + " VALUE=3> read/write "); out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE=0> delete "); } } if (ctdb.valueExistsForThisColumnUnderTwoConditions( new Column("ISUSERWAITING", "yes"), new Column("USERNAME", user.getUserName()), new Column("DATASOURCENAME", dataSourceName), "ACUSER_ACDATASOURCE")) { out.println("<td>" + "<FONT COLOR=#0000FF>in updates waiting list!</td></tr>"); } else { out.println( "   <INPUT TYPE=SUBMIT class= buttonstyle VALUE=\"update\"></td></tr>"); out.println("</FORM>"); } } } out.println("</table>"); } }
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { JspFactory _jspxFactory = null; PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { _jspxFactory = JspFactory.getDefaultFactory(); response.setContentType("text/html"); pageContext = _jspxFactory.getPageContext(this, request, response, "error.jsp", true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; out.write("\n\n\n\n\n\n\n\n\n"); out.write('\n'); org.jivesoftware.util.WebManager webManager = null; synchronized (_jspx_page_context) { webManager = (org.jivesoftware.util.WebManager) _jspx_page_context.getAttribute("webManager", PageContext.PAGE_SCOPE); if (webManager == null) { webManager = new org.jivesoftware.util.WebManager(); _jspx_page_context.setAttribute("webManager", webManager, PageContext.PAGE_SCOPE); } } out.write('\n'); webManager.init(request, response, session, application, out); out.write('\n'); out.write('\n'); // Get paramters boolean doTest = request.getParameter("test") != null; boolean cancel = request.getParameter("cancel") != null; boolean sent = ParamUtils.getBooleanParameter(request, "sent"); boolean success = ParamUtils.getBooleanParameter(request, "success"); String from = ParamUtils.getParameter(request, "from"); String to = ParamUtils.getParameter(request, "to"); String subject = ParamUtils.getParameter(request, "subject"); String body = ParamUtils.getParameter(request, "body"); // Cancel if requested if (cancel) { response.sendRedirect("system-email.jsp"); return; } // Variable to hold messaging exception, if one occurs Exception mex = null; // Validate input Map<String, String> errors = new HashMap<String, String>(); if (doTest) { if (from == null) { errors.put("from", ""); } if (to == null) { errors.put("to", ""); } if (subject == null) { errors.put("subject", ""); } if (body == null) { errors.put("body", ""); } EmailService service = EmailService.getInstance(); // Validate host - at a minimum, it needs to be set: String host = service.getHost(); if (host == null) { errors.put("host", ""); } // if no errors, continue if (errors.size() == 0) { // Create a message MimeMessage message = service.createMimeMessage(); // Set the date of the message to be the current date SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", java.util.Locale.US); format.setTimeZone(JiveGlobals.getTimeZone()); message.setHeader("Date", format.format(new Date())); // Set to and from. message.setRecipient(Message.RecipientType.TO, new InternetAddress(to, null)); message.setFrom(new InternetAddress(from, null)); message.setSubject(subject); message.setText(body); // Send the message, wrap in a try/catch: try { service.sendMessagesImmediately(Collections.singletonList(message)); // success, so indicate this: response.sendRedirect("system-emailtest.jsp?sent=true&success=true"); return; } catch (MessagingException me) { me.printStackTrace(); mex = me; } } } // Set var defaults Collection<JID> jids = webManager.getXMPPServer().getAdmins(); User user = null; if (!jids.isEmpty()) { for (JID jid : jids) { if (webManager.getXMPPServer().isLocal(jid)) { user = webManager.getUserManager().getUser(jid.getNode()); if (user.getEmail() != null) { break; } } } } if (from == null) { from = user.getEmail(); } if (to == null) { to = user.getEmail(); } if (subject == null) { subject = "Test email sent via Openfire"; } if (body == null) { body = "This is a test message."; } out.write("\n\n<html>\n <head>\n <title>"); if (_jspx_meth_fmt_message_0(_jspx_page_context)) return; out.write( "</title>\n <meta name=\"pageID\" content=\"system-email\"/>\n </head>\n <body>\n\n<script language=\"JavaScript\" type=\"text/javascript\">\nvar clicked = false;\nfunction checkClick(el) {\n if (!clicked) {\n clicked = true;\n return true;\n }\n return false;\n}\n</script>\n\n<p>\n"); if (_jspx_meth_fmt_message_1(_jspx_page_context)) return; out.write("\n</p>\n\n"); if (JiveGlobals.getProperty("mail.smtp.host") == null) { out.write( "\n\n <div class=\"jive-error\">\n <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tbody>\n <tr>\n \t<td class=\"jive-icon\"><img src=\"images/error-16x16.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"\"></td>\n\t <td class=\"jive-icon-label\">\n\t\t "); if (_jspx_meth_fmt_message_2(_jspx_page_context)) return; out.write("\n\t </td>\n </tr>\n </tbody>\n </table>\n </div>\n\n"); } out.write('\n'); out.write('\n'); if (doTest || sent) { out.write("\n\n "); if (success) { out.write( "\n\n <div class=\"jive-success\">\n <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tbody>\n <tr>\n \t<td class=\"jive-icon\"><img src=\"images/success-16x16.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"\"></td>\n \t<td class=\"jive-icon-label\">"); if (_jspx_meth_fmt_message_3(_jspx_page_context)) return; out.write( "</td>\n </tr>\n </tbody>\n </table>\n </div>\n\n "); } else { out.write( "\n\n <div class=\"jive-error\">\n <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tbody>\n <tr><td class=\"jive-icon\"><img src=\"images/error-16x16.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"\"></td>\n <td class=\"jive-icon-label\">\n "); if (_jspx_meth_fmt_message_4(_jspx_page_context)) return; out.write("\n "); if (mex != null) { out.write("\n "); if (mex instanceof AuthenticationFailedException) { out.write("\n \t"); if (_jspx_meth_fmt_message_5(_jspx_page_context)) return; out.write(" \n "); } else { out.write("\n (Message: "); out.print(mex.getMessage()); out.write(")\n "); } out.write("\n "); } out.write( "\n </td></tr>\n </tbody>\n </table>\n </div>\n\n "); } out.write("\n\n <br>\n\n"); } out.write( "\n\n<form action=\"system-emailtest.jsp\" method=\"post\" name=\"f\" onsubmit=\"return checkClick(this);\">\n\n<table cellpadding=\"3\" cellspacing=\"0\" border=\"0\">\n<tbody>\n <tr>\n <td>\n "); if (_jspx_meth_fmt_message_6(_jspx_page_context)) return; out.write(":\n </td>\n <td>\n "); String host = JiveGlobals.getProperty("mail.smtp.host"); if (host == null) { out.write("\n <i>"); if (_jspx_meth_fmt_message_7(_jspx_page_context)) return; out.write("</i>\n "); } else { out.write("\n "); out.print(host); out.write(':'); out.print(JiveGlobals.getIntProperty("mail.smtp.port", 25)); out.write("\n\n "); if (JiveGlobals.getBooleanProperty("mail.smtp.ssl", false)) { out.write("\n\n ("); if (_jspx_meth_fmt_message_8(_jspx_page_context)) return; out.write(")\n\n "); } out.write("\n "); } out.write("\n </td>\n </tr>\n <tr>\n <td>\n "); if (_jspx_meth_fmt_message_9(_jspx_page_context)) return; out.write( ":\n </td>\n <td>\n <input type=\"hidden\" name=\"from\" value=\""); out.print(from); out.write("\">\n "); out.print(StringUtils.escapeHTMLTags(from)); out.write( "\n <span class=\"jive-description\">\n (<a href=\"user-edit-form.jsp?username="******"\">Update Address</a>)\n </span>\n </td>\n </tr>\n <tr>\n <td>\n "); if (_jspx_meth_fmt_message_10(_jspx_page_context)) return; out.write( ":\n </td>\n <td>\n <input type=\"text\" name=\"to\" value=\""); out.print(((to != null) ? to : "")); out.write( "\"\n size=\"40\" maxlength=\"100\">\n </td>\n </tr>\n <tr>\n <td>\n "); if (_jspx_meth_fmt_message_11(_jspx_page_context)) return; out.write( ":\n </td>\n <td>\n <input type=\"text\" name=\"subject\" value=\""); out.print(((subject != null) ? subject : "")); out.write( "\"\n size=\"40\" maxlength=\"100\">\n </td>\n </tr>\n <tr valign=\"top\">\n <td>\n "); if (_jspx_meth_fmt_message_12(_jspx_page_context)) return; out.write( ":\n </td>\n <td>\n <textarea name=\"body\" cols=\"45\" rows=\"5\" wrap=\"virtual\">"); out.print(body); out.write( "</textarea>\n </td>\n </tr>\n <tr>\n <td colspan=\"2\">\n <br>\n <input type=\"submit\" name=\"test\" value=\""); if (_jspx_meth_fmt_message_13(_jspx_page_context)) return; out.write("\">\n <input type=\"submit\" name=\"cancel\" value=\""); if (_jspx_meth_fmt_message_14(_jspx_page_context)) return; out.write( "\">\n </td>\n </tr>\n</tbody>\n</table>\n\n</form>\n\n </body>\n</html>"); } catch (Throwable t) { if (!(t instanceof SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); } } finally { if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context); } }
/** * Displays a given Meeting page for a HTTP Get, or creates a new Meeting for a HTTP Post * * <p>- Requires a cookie for the session user - Requires a meetingId request parameter for a GET * - Requires description, createdByUserId, datepicker, meetingTime, groupId request parameters * for a POST * * @param req The HTTP Request * @param res The HTTP Response */ public void meetingAction(HttpServletRequest req, HttpServletResponse res) { // Ensure there is a cookie for the session user if (AccountController.redirectIfNoCookie(req, res)) return; Map<String, Object> viewData = new HashMap<String, Object>(); viewData.put("title", "Meeting"); // Initialise Manager connections MeetingManager meetingMan = new MeetingManager(); GroupManager groupMan = new GroupManager(); if (req.getMethod() == HttpMethod.Get) { // Get request parameter int meetingId = Integer.parseInt(req.getParameter("meetingId")); Meeting meeting = meetingMan.get(meetingId); if (meeting != null) { List<User> meetingUsers = groupMan.getGroupUsers(meeting.getGroupId()); viewData.put("meetingUsers", meetingUsers); viewData.put("meeting", meeting); view(req, res, "/views/group/Meeting.jsp", viewData); } else { httpNotFound(req, res); } } else if (req.getMethod() == HttpMethod.Post) { // Get details from request String description = req.getParameter("description"); int createdByUserId = Integer.parseInt(req.getParameter("createdByUserId")); Date dateCreated = new Date(); String meetingDate = req.getParameter("datepicker"); String meetingTime = req.getParameter("meetingTime"); // Parse meeting date time details DateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm"); Date dateDue = new Date(); try { dateDue = format.parse(meetingDate + " " + meetingTime); } catch (ParseException e) { // Unable to parse date. This shouldn't happen since we are // performing javascript validation. } int groupId = Integer.parseInt(req.getParameter("groupId")); // Create a Meeting Meeting meeting = new Meeting(); meeting.setDescription(description); meeting.setCreatedByUserId(createdByUserId); meeting.setDateCreated(dateCreated); meeting.setDateDue(dateDue); meeting.setGroupId(groupId); meetingMan.createMeeting(meeting); int meetingId = meetingMan.getIdFor(meeting); meeting.setId(meetingId); UserManager userMan = new UserManager(); User createdByUser = userMan.get(createdByUserId); // Create a notification for all users in group NotificationManager notificationMan = new NotificationManager(); List<User> users = groupMan.getGroupUsers(groupId); for (User u : users) { Notification notification = new Notification( u.getId(), u, groupId, null, "Meeting " + description + " was created by " + createdByUser.getFullName(), "/group/meeting?meetingId=" + meetingId); notificationMan.createNotification(notification); } // Update the User Session to show new meeting HttpSession session = req.getSession(); Session userSession = (Session) session.getAttribute("userSession"); User admin = userSession.getUser(); admin.getMeetings().add(meeting); // Show meeting page viewData.put("meetingUsers", users); viewData.put("meeting", meeting); view(req, res, "/views/group/Meeting.jsp", viewData); } }
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { UserService userService = UserServiceFactory.getUserService(); String retUrl = req.getParameter("url"); if (retUrl == null) retUrl = "/"; String pathInfo = req.getPathInfo(); if (pathInfo.equals("/current")) { User user = userService.getCurrentUser(); if (user == null) { res.setStatus(401); res.setContentType("text/plain; charset=utf-8"); res.getWriter().write("Not login"); return; } UserBean ub = getByEmail(user.getEmail()); res.setContentType("application/json; charset=utf-8"); res.setHeader("Cache-control", "no-cache"); res.getWriter().write("{\"email\":\"" + user.getEmail() + "\""); if (ub != null) { res.getWriter().write(",\"nickName\":\"" + ub.getNickName() + "\""); res.getWriter().write(",\"isRegister\":true"); } else { String nn = user.getNickname(); if (nn == null) nn = user.getEmail(); res.getWriter().write(",\"nickName\":\"" + nn + "\""); res.getWriter().write(",\"isRegister\":false"); } res.getWriter().write("}"); } else if (pathInfo.equals("/login")) { String url = userService.createLoginURL(retUrl); res.sendRedirect(url); } else if (pathInfo.equals("/logout")) { String url = userService.createLogoutURL(retUrl); res.sendRedirect(url); } else if (pathInfo.equals("/register")) { User user = userService.getCurrentUser(); if (user == null) { res.setStatus(401); res.setContentType("text/plain; charset=utf-8"); res.getWriter().write("Not login"); return; } String nickName = req.getParameter("nickName"); UserBean ub = getByNeckName(nickName); if (ub != null) { res.setStatus(403); res.setContentType("text/plain; charset=utf-8"); res.getWriter().write("ニックネーム(" + nickName + ")は既に使われています。"); return; } ub = new UserBean(); ub.setEmail(user.getEmail()); ub.setNickName(nickName); usbs.put(user.getEmail(), ub); ursbs.put(nickName, ub); FileBean fb = new FileBean(); fb.setParentName(""); fb.setLastName(nickName); fb.setDirectory(true); fb.setLastModified(System.currentTimeMillis()); fb.setOwner(user.getEmail()); fb.setNickName(nickName); sbs.put("/" + nickName, fb); res.sendRedirect(retUrl); } }
/** * Get a populated User object corresponding to a username. * * @param username The username to test * @return The User object corresponding to that username. * @throws NoSuchUserException if that username does not exist. * @throws SQLException if a database error was encountered. */ public static User getUser(String username) throws NoSuchUserException, SQLException { // The User to return User theUser; // Make sure the username isn't null if (username == null) { throw new NoSuchUserException("got null for username in UserUtils.getUser"); } // Get our connection to the database. Connection conn = DBConnectionManager.getConnection("yrc"); PreparedStatement stmt = null; ResultSet rs = null; try { stmt = conn.prepareStatement("SELECT researcherID FROM tblUsers WHERE username = ?"); stmt.setString(1, username); rs = stmt.executeQuery(); // No rows returned. if (!rs.next()) { throw new NoSuchUserException("Username not found."); } theUser = new User(); try { theUser.load(rs.getInt("researcherID")); } catch (InvalidIDException e) { throw new NoSuchUserException( "Somehow, we got an invalid ID (" + rs.getInt("researcherID") + ") after we got the ID from the username... This can't be good."); } rs.close(); rs = null; stmt.close(); stmt = null; conn.close(); conn = null; } finally { // Always make sure result sets and statements are closed, // and the connection is returned to the pool if (rs != null) { try { rs.close(); } catch (SQLException e) {; } rs = null; } if (stmt != null) { try { stmt.close(); } catch (SQLException e) {; } stmt = null; } if (conn != null) { try { conn.close(); } catch (SQLException e) {; } conn = null; } } return theUser; }
private void printUserDataSourceList(PrintWriter out, User user) { String userName = user.getUserName(); DataSource ds = null; String dsname = null; String dstype = null; String ownerDecision = null; String label = null; if (user.getDataSourceList().size() == 0) { out.println("<p>No virtaul sensor is selected.</p>"); out.println("<BR>"); } else { out.println("<table>"); out.println("<tr><th> virtual sensor name </th>"); out.println("<th> access right</th>"); out.println("<th> owner decision</th>"); out.println("<th> admin decision</th>"); out.println("<th> admin decision</th></tr>"); for (int i = 0; i < user.getDataSourceList().size(); i++) { ds = (DataSource) (user.getDataSourceList().get(i)); dsname = ds.getDataSourceName(); dstype = ds.getDataSourceType(); ownerDecision = ds.getOwnerDecision(); if (dstype.charAt(1) == '1') { label = "read"; } else if (dstype.charAt(1) == '2') { label = "write"; } else if (dstype.charAt(1) == '3') { label = "read/write"; } else if (dstype.charAt(1) == '0') { label = "delete"; } if (ownerDecision.equals("notreceived")) { ownerDecision = "not received"; } out.println("<tr><td>" + dsname + "</td>"); out.println("<td>" + label + "</td>"); out.println("<td>" + ownerDecision + "</td>"); out.println("<FORM ACTION=/gsn/MyUpdateUserDataSourceServlet METHOD=POST>"); out.println("<INPUT TYPE=HIDDEN NAME=username VALUE= " + userName + ">"); out.println("<INPUT TYPE=HIDDEN NAME= datasourcename VALUE= " + dsname + "> "); out.println("<INPUT TYPE=HIDDEN NAME= datasourcetype VALUE= " + dstype + "> "); out.println("<INPUT TYPE=HIDDEN NAME=update VALUE= yes>"); out.println( "<td><INPUT TYPE=SUBMIT class=creategroupbuttonstyle VALUE=\"agree to update \"></td>"); out.println("</FORM>"); out.println("<FORM ACTION=/gsn/MyUpdateUserDataSourceServlet METHOD=POST>"); out.println("<INPUT TYPE=HIDDEN NAME=username VALUE= " + userName + ">"); out.println("<INPUT TYPE=HIDDEN NAME= datasourcename VALUE= " + dsname + "> "); out.println("<INPUT TYPE=HIDDEN NAME= datasourcetype VALUE= " + dstype + "> "); out.println("<INPUT TYPE=HIDDEN NAME=update VALUE= no>"); out.println( "<td><INPUT TYPE=SUBMIT class=creategroupbuttonstyle VALUE=\"refuse to update\"></td></tr>"); out.println("</FORM>"); } } out.println("</table>"); }
/** * Displays the Create Discussion page for a HTTP Get, or creates a Discussion Thread for a HTTP * Post * * <p>- Requires a cookie for the session user - Requires a groupId request parameter for a GET - * Requires a groupId and threadName request parameter for a POST - Requires a document request * part for a POST * * @param req The HTTP Request * @param res The HTTP Response */ public void createDiscussionAction(HttpServletRequest req, HttpServletResponse res) { // Ensure there is a cookie for the session user if (AccountController.redirectIfNoCookie(req, res)) return; Map<String, Object> viewData = new HashMap<>(); if (req.getMethod() == HttpMethod.Get) { viewData.put("title", "Create Discussion"); viewData.put("groupId", req.getParameter("groupId")); view(req, res, "/views/group/CreateDiscussion.jsp", viewData); return; } else if (req.getMethod() == HttpMethod.Post) { // save discussion GroupManager groupMan = new GroupManager(); DiscussionThread thread = new DiscussionThread(); int groupId = Integer.parseInt(req.getParameter("groupId")); thread.setGroupId(groupId); thread.setGroup(groupMan.get(groupId)); thread.setThreadName(req.getParameter("threadName")); DiscussionManager dm = new DiscussionManager(); dm.createDiscussion(thread); try { Part documentPart = req.getPart("document"); // if we have a document to upload if (documentPart.getSize() > 0) { String uuid = DocumentController.saveDocument(this.getServletContext(), documentPart); Document doc = new Document(); doc.setDocumentName(getFileName(documentPart)); doc.setDocumentPath(uuid); doc.setVersionNumber(1); doc.setThreadId(thread.getId()); doc.setGroupId(thread.getGroupId()); DocumentManager docMan = new DocumentManager(); docMan.createDocument(doc); // Get uploading User HttpSession session = req.getSession(); Session userSession = (Session) session.getAttribute("userSession"); User uploader = userSession.getUser(); // Create a notification to all in the group NotificationManager notificationMan = new NotificationManager(); groupMan = new GroupManager(); List<User> groupUsers = groupMan.getGroupUsers(groupId); for (User u : groupUsers) { Notification notification = new Notification( u.getId(), u, groupId, null, "User " + uploader.getFullName() + " has uploaded a document", "/document/document?documentId=" + doc.getId()); notificationMan.createNotification(notification); } } } catch (Exception e) { logger.log(Level.SEVERE, "Document save error", e); } redirectToLocal(req, res, "/group/discussion/?threadId=" + thread.getId()); return; } httpNotFound(req, res); }