Search in sources :

Example 1 with RequestContext

use of net.jforum.context.RequestContext in project jforum2 by rafaelsteil.

the class POPPostAction method insertMessages.

public void insertMessages(POPParser parser) {
    long ms = System.currentTimeMillis();
    int counter = 0;
    try {
        JForumExecutionContext ex = JForumExecutionContext.get();
        RequestContext request = new StandardRequestContext();
        ex.setForumContext(new JForumContext("/", "", request, null));
        JForumExecutionContext.set(ex);
        SessionFacade.setAttribute(ConfigKeys.TOPICS_READ_TIME, new HashMap());
        for (Iterator iter = parser.getMessages().iterator(); iter.hasNext(); ) {
            POPMessage m = (POPMessage) iter.next();
            String sessionId = ms + m.getSender() + counter++;
            request.getSessionContext().setAttribute(StandardSessionContext.SESSION_ID, sessionId);
            User user = this.findUser(m.getSender());
            if (user == null) {
                logger.warn("Could not find user with email " + m.getSender() + ". Ignoring his message.");
                continue;
            }
            try {
                UserSession us = new UserSession();
                us.setUserId(user.getId());
                us.setUsername(us.getUsername());
                us.setSessionId(sessionId);
                SessionFacade.add(us, sessionId);
                SessionFacade.setAttribute(ConfigKeys.LOGGED, "1");
                SessionFacade.removeAttribute(ConfigKeys.LAST_POST_TIME);
                SessionFacade.setAttribute(ConfigKeys.REQUEST_IGNORE_CAPTCHA, "1");
                this.insertMessage(m, user);
            } finally {
                SessionFacade.remove(sessionId);
            }
        }
    } finally {
        JForumExecutionContext.finish();
    }
}
Also used : User(net.jforum.entities.User) JForumExecutionContext(net.jforum.JForumExecutionContext) HashMap(java.util.HashMap) UserSession(net.jforum.entities.UserSession) Iterator(java.util.Iterator) RequestContext(net.jforum.context.RequestContext) StandardRequestContext(net.jforum.context.standard.StandardRequestContext) StandardRequestContext(net.jforum.context.standard.StandardRequestContext) JForumContext(net.jforum.context.JForumContext)

Example 2 with RequestContext

use of net.jforum.context.RequestContext in project jforum2 by rafaelsteil.

the class ModerationHelper method moveTopicsSave.

public int moveTopicsSave(String successUrl) {
    int status = SUCCESS;
    if (!SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_TOPIC_MOVE)) {
        status = FAILURE;
    } else {
        RequestContext request = JForumExecutionContext.getRequest();
        String topics = request.getParameter("topics");
        if (topics != null) {
            int fromForumId = Integer.parseInt(request.getParameter("forum_id"));
            int toForumId = Integer.parseInt(request.getParameter("to_forum"));
            String[] topicList = topics.split(",");
            DataAccessDriver.getInstance().newForumDAO().moveTopics(topicList, fromForumId, toForumId);
            ModerationLog log = this.buildModerationLogFromRequest();
            for (int i = 0; i < topicList.length; i++) {
                int topicId = Integer.parseInt(topicList[i]);
                log.setTopicId(topicId);
                this.saveModerationLog(log);
            }
            ForumRepository.reloadForum(fromForumId);
            ForumRepository.reloadForum(toForumId);
            TopicRepository.clearCache(fromForumId);
            TopicRepository.clearCache(toForumId);
            TopicRepository.loadMostRecentTopics();
            TopicRepository.loadHottestTopics();
        }
    }
    if (status == FAILURE) {
        this.denied();
    } else {
        this.moderationDone(successUrl);
    }
    return status;
}
Also used : ModerationLog(net.jforum.entities.ModerationLog) RequestContext(net.jforum.context.RequestContext)

Example 3 with RequestContext

use of net.jforum.context.RequestContext in project jforum2 by rafaelsteil.

the class ModerationHelper method doModeration.

public int doModeration(String returnUrl) {
    int status = FAILURE;
    if (SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION)) {
        // Deleting topics
        RequestContext request = JForumExecutionContext.getRequest();
        if (request.getParameter("topicRemove") != null) {
            if (SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_POST_REMOVE)) {
                this.removeTopics();
                status = SUCCESS;
            }
        } else if (request.getParameter("topicMove") != null) {
            if (SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_TOPIC_MOVE)) {
                this.moveTopics();
                status = IGNORE;
            }
        } else if (request.getParameter("topicLock") != null) {
            if (SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_TOPIC_LOCK_UNLOCK)) {
                this.lockUnlockTopics(Topic.STATUS_LOCKED);
                status = SUCCESS;
            }
        } else if (request.getParameter("topicUnlock") != null) {
            if (SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_TOPIC_LOCK_UNLOCK)) {
                this.lockUnlockTopics(Topic.STATUS_UNLOCKED);
                status = SUCCESS;
            }
        }
    }
    if (status == ModerationHelper.FAILURE) {
        this.denied();
    } else if (status == ModerationHelper.SUCCESS && returnUrl != null) {
        JForumExecutionContext.setRedirect(returnUrl);
    }
    return status;
}
Also used : RequestContext(net.jforum.context.RequestContext)

Example 4 with RequestContext

use of net.jforum.context.RequestContext in project jforum2 by rafaelsteil.

the class OnlineUsersTest method setUp.

protected void setUp() throws Exception {
    new SessionFacade().setCacheEngine(new DefaultCacheEngine());
    RequestContext requestContext = new WebRequestContext(new FakeHttpRequest());
    ResponseContext responseContext = new WebResponseContext(new FakeHttpResponse());
    ForumContext forumContext = new JForumContext(requestContext.getContextPath(), SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION), requestContext, responseContext, false);
    JForumExecutionContext ex = JForumExecutionContext.get();
    ex.setForumContext(forumContext);
    JForumExecutionContext.set(ex);
    SystemGlobals.setValue(ConfigKeys.ANONYMOUS_USER_ID, Integer.toString(ANONYMOUS));
}
Also used : WebResponseContext(net.jforum.context.web.WebResponseContext) WebRequestContext(net.jforum.context.web.WebRequestContext) FakeHttpResponse(net.jforum.http.FakeHttpResponse) ResponseContext(net.jforum.context.ResponseContext) WebResponseContext(net.jforum.context.web.WebResponseContext) DefaultCacheEngine(net.jforum.cache.DefaultCacheEngine) JForumContext(net.jforum.context.JForumContext) ForumContext(net.jforum.context.ForumContext) RequestContext(net.jforum.context.RequestContext) WebRequestContext(net.jforum.context.web.WebRequestContext) FakeHttpRequest(net.jforum.http.FakeHttpRequest) JForumContext(net.jforum.context.JForumContext)

Example 5 with RequestContext

use of net.jforum.context.RequestContext in project jforum2 by rafaelsteil.

the class PollCommon method fillPollFromRequest.

public static Poll fillPollFromRequest() {
    RequestContext request = JForumExecutionContext.getRequest();
    String label = request.getParameter("poll_label");
    if (label == null || label.length() == 0) {
        return null;
    }
    Poll poll = new Poll();
    poll.setStartTime(new Date());
    poll.setLabel(label);
    int count = request.getIntParameter("poll_option_count");
    for (int i = 0; i <= count; i++) {
        String option = request.getParameter("poll_option_" + i);
        if (option == null) {
            continue;
        }
        option = option.trim();
        if (option.length() > 0) {
            PollOption po = new PollOption();
            po.setId(i);
            po.setText(option);
            poll.addOption(po);
        }
    }
    String pollLength = request.getParameter("poll_length");
    if (pollLength != null && pollLength.length() > 0) {
        poll.setLength(Integer.parseInt(pollLength));
    }
    return poll;
}
Also used : Poll(net.jforum.entities.Poll) PollOption(net.jforum.entities.PollOption) RequestContext(net.jforum.context.RequestContext) Date(java.util.Date)

Aggregations

RequestContext (net.jforum.context.RequestContext)15 JForumContext (net.jforum.context.JForumContext)4 ResponseContext (net.jforum.context.ResponseContext)3 WebRequestContext (net.jforum.context.web.WebRequestContext)3 WebResponseContext (net.jforum.context.web.WebResponseContext)3 User (net.jforum.entities.User)3 SimpleHash (freemarker.template.SimpleHash)2 BufferedWriter (java.io.BufferedWriter)2 IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ServletException (javax.servlet.ServletException)2 ForumContext (net.jforum.context.ForumContext)2 StandardRequestContext (net.jforum.context.standard.StandardRequestContext)2 ModerationLog (net.jforum.entities.ModerationLog)2 UserSession (net.jforum.entities.UserSession)2 ExceptionWriter (net.jforum.exceptions.ExceptionWriter)2 SafeHtml (net.jforum.util.SafeHtml)2 Template (freemarker.template.Template)1