use of net.jforum.entities.UserSession in project jforum2 by rafaelsteil.
the class ForumAction method list.
/**
* List all the forums (first page of forum index)?
*/
public void list() {
this.setTemplateName(TemplateKeys.FORUMS_LIST);
this.context.put("allCategories", ForumCommon.getAllCategoriesAndForums(true));
this.context.put("topicsPerPage", new Integer(SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE)));
this.context.put("rssEnabled", SystemGlobals.getBoolValue(ConfigKeys.RSS_ENABLED));
this.context.put("totalMessages", new Integer(ForumRepository.getTotalMessages()));
this.context.put("totalRegisteredUsers", ForumRepository.totalUsers());
this.context.put("lastUser", ForumRepository.lastRegisteredUser());
SimpleDateFormat df = new SimpleDateFormat(SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
GregorianCalendar gc = new GregorianCalendar();
this.context.put("now", df.format(gc.getTime()));
this.context.put("lastVisit", df.format(SessionFacade.getUserSession().getLastVisit()));
this.context.put("forumRepository", new ForumRepository());
// Online Users
this.context.put("totalOnlineUsers", new Integer(SessionFacade.size()));
int aid = SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID);
List onlineUsersList = SessionFacade.getLoggedSessions();
// Check for an optional language parameter
UserSession currentUser = SessionFacade.getUserSession();
if (currentUser.getUserId() == aid) {
String lang = this.request.getParameter("lang");
if (lang != null && I18n.languageExists(lang)) {
currentUser.setLang(lang);
}
}
// show the "guest" username
if (onlineUsersList.size() == 0) {
UserSession us = new UserSession();
us.setUserId(aid);
us.setUsername(I18n.getMessage("Guest"));
onlineUsersList.add(us);
}
int registeredSize = SessionFacade.registeredSize();
int anonymousSize = SessionFacade.anonymousSize();
int totalOnlineUsers = registeredSize + anonymousSize;
this.context.put("userSessions", onlineUsersList);
this.context.put("totalOnlineUsers", new Integer(totalOnlineUsers));
this.context.put("totalRegisteredOnlineUsers", new Integer(registeredSize));
this.context.put("totalAnonymousUsers", new Integer(anonymousSize));
// Most users ever online
MostUsersEverOnline mostUsersEverOnline = ForumRepository.getMostUsersEverOnline();
if (totalOnlineUsers > mostUsersEverOnline.getTotal()) {
mostUsersEverOnline.setTotal(totalOnlineUsers);
mostUsersEverOnline.setTimeInMillis(System.currentTimeMillis());
ForumRepository.updateMostUsersEverOnline(mostUsersEverOnline);
}
this.context.put("mostUsersEverOnline", mostUsersEverOnline);
}
use of net.jforum.entities.UserSession in project jforum2 by rafaelsteil.
the class OnlineUsersTest method createUserSession.
private void createUserSession(int userId, String sessionId) {
UserSession us = new UserSession();
us.setUserId(userId);
us.setSessionId(sessionId);
us.setUsername("blah_" + System.currentTimeMillis());
SessionFacade.add(us, sessionId);
}
use of net.jforum.entities.UserSession in project jforum2 by rafaelsteil.
the class OnlineUsersTest method testAnonymousThenLogged.
/**
* First register as anonymous, then change to logged, and check counting
*/
public void testAnonymousThenLogged() {
// Anonymous
String sessionId = ANONYMOUS + "1_" + System.currentTimeMillis();
this.createUserSession(ANONYMOUS, sessionId);
assertEquals(1, SessionFacade.anonymousSize());
assertEquals(0, SessionFacade.registeredSize());
// Logged
UserSession us = SessionFacade.getUserSession(sessionId);
us.setUserId(2);
SessionFacade.setAttribute("logged", "1");
SessionFacade.remove(sessionId);
SessionFacade.add(us);
assertEquals(0, SessionFacade.anonymousSize());
assertEquals(1, SessionFacade.registeredSize());
}
use of net.jforum.entities.UserSession in project jforum2 by rafaelsteil.
the class ForumCommon method getAllCategoriesAndForums.
/**
* @see #getAllCategoriesAndForums(boolean)
* @return List
*/
public static List getAllCategoriesAndForums() {
UserSession us = SessionFacade.getUserSession();
boolean checkUnread = (us != null && us.getUserId() != SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID));
return getAllCategoriesAndForums(checkUnread);
}
use of net.jforum.entities.UserSession in project jforum2 by rafaelsteil.
the class UserAction method logNewRegisteredUserIn.
private void logNewRegisteredUserIn(int userId, User u) {
SessionFacade.makeLogged();
UserSession userSession = new UserSession();
userSession.setAutoLogin(true);
userSession.setUserId(userId);
userSession.setUsername(u.getUsername());
userSession.setLastVisit(new Date(System.currentTimeMillis()));
userSession.setStartTime(new Date(System.currentTimeMillis()));
SessionFacade.add(userSession);
// Finalizing.. show to user the congrats page
JForumExecutionContext.setRedirect(this.request.getContextPath() + "/user/registrationComplete" + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
}
Aggregations