Search in sources :

Example 21 with UserSession

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);
}
Also used : ForumRepository(net.jforum.repository.ForumRepository) MostUsersEverOnline(net.jforum.entities.MostUsersEverOnline) UserSession(net.jforum.entities.UserSession) GregorianCalendar(java.util.GregorianCalendar) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat)

Example 22 with UserSession

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);
}
Also used : UserSession(net.jforum.entities.UserSession)

Example 23 with UserSession

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());
}
Also used : UserSession(net.jforum.entities.UserSession)

Example 24 with UserSession

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);
}
Also used : UserSession(net.jforum.entities.UserSession)

Example 25 with UserSession

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));
}
Also used : UserSession(net.jforum.entities.UserSession) Date(java.util.Date)

Aggregations

UserSession (net.jforum.entities.UserSession)27 User (net.jforum.entities.User)6 List (java.util.List)5 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Iterator (java.util.Iterator)4 Topic (net.jforum.entities.Topic)4 Map (java.util.Map)3 PollDAO (net.jforum.dao.PollDAO)3 UserDAO (net.jforum.dao.UserDAO)3 Forum (net.jforum.entities.Forum)3 PrivateMessage (net.jforum.entities.PrivateMessage)3 PermissionControl (net.jforum.security.PermissionControl)3 SimpleDateFormat (java.text.SimpleDateFormat)2 RequestContext (net.jforum.context.RequestContext)2 ForumDAO (net.jforum.dao.ForumDAO)2 PostDAO (net.jforum.dao.PostDAO)2 TopicDAO (net.jforum.dao.TopicDAO)2 UserSessionDAO (net.jforum.dao.UserSessionDAO)2 Poll (net.jforum.entities.Poll)2