Search in sources :

Example 1 with EmailSenderTask

use of net.jforum.util.mail.EmailSenderTask in project jforum2 by rafaelsteil.

the class UserAction method insertSave.

public void insertSave() {
    UserSession userSession = SessionFacade.getUserSession();
    int userId = userSession.getUserId();
    if ((!SystemGlobals.getBoolValue(ConfigKeys.REGISTRATION_ENABLED) && !SecurityRepository.get(userId).canAccess(SecurityConstants.PERM_ADMINISTRATION)) || ConfigKeys.TYPE_SSO.equals(SystemGlobals.getValue(ConfigKeys.AUTHENTICATION_TYPE))) {
        this.registrationDisabled();
        return;
    }
    User u = new User();
    UserDAO dao = DataAccessDriver.getInstance().newUserDAO();
    String username = this.request.getParameter("username");
    String password = this.request.getParameter("password");
    String email = this.request.getParameter("email");
    String captchaResponse = this.request.getParameter("captchaResponse");
    boolean error = false;
    if (username == null || username.trim().equals("") || password == null || password.trim().equals("")) {
        this.context.put("error", I18n.getMessage("UsernamePasswordCannotBeNull"));
        error = true;
    }
    if (username != null) {
        username = username.trim();
    }
    if (!error && username.length() > SystemGlobals.getIntValue(ConfigKeys.USERNAME_MAX_LENGTH)) {
        this.context.put("error", I18n.getMessage("User.usernameTooBig"));
        error = true;
    }
    if (!error && username.indexOf('<') > -1 || username.indexOf('>') > -1) {
        this.context.put("error", I18n.getMessage("User.usernameInvalidChars"));
        error = true;
    }
    if (!error && dao.isUsernameRegistered(username)) {
        this.context.put("error", I18n.getMessage("UsernameExists"));
        error = true;
    }
    if (!error && dao.findByEmail(email) != null) {
        this.context.put("error", I18n.getMessage("User.emailExists", new String[] { email }));
        error = true;
    }
    if (!error && !userSession.validateCaptchaResponse(captchaResponse)) {
        this.context.put("error", I18n.getMessage("CaptchaResponseFails"));
        error = true;
    }
    if (error) {
        this.insert(true);
        return;
    }
    u.setUsername(username);
    u.setPassword(MD5.crypt(password));
    u.setEmail(email);
    boolean requiresMailActivation = SystemGlobals.getBoolValue(ConfigKeys.MAIL_USER_EMAIL_AUTH);
    if (requiresMailActivation) {
        u.setActivationKey(MD5.crypt(username + System.currentTimeMillis()));
    }
    int newUserId = dao.addNew(u);
    if (requiresMailActivation) {
        Executor.execute(new EmailSenderTask(new ActivationKeySpammer(u)));
        this.setTemplateName(TemplateKeys.USER_INSERT_ACTIVATE_MAIL);
        this.context.put("message", I18n.getMessage("User.GoActivateAccountMessage"));
    } else if (SecurityRepository.get(userId).canAccess(SecurityConstants.PERM_ADMINISTRATION)) {
        JForumExecutionContext.setRedirect(this.request.getContextPath() + "/adminUsers/list" + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
    } else {
        this.logNewRegisteredUserIn(newUserId, u);
    }
    if (!requiresMailActivation) {
        dao.writeUserActive(newUserId);
    }
}
Also used : EmailSenderTask(net.jforum.util.mail.EmailSenderTask) ActivationKeySpammer(net.jforum.util.mail.ActivationKeySpammer) User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO) UserSession(net.jforum.entities.UserSession)

Example 2 with EmailSenderTask

use of net.jforum.util.mail.EmailSenderTask in project jforum2 by rafaelsteil.

the class UserAction method lostPasswordSend.

// Send lost password email
public void lostPasswordSend() {
    String email = this.request.getParameter("email");
    String username = this.request.getParameter("username");
    User user = this.prepareLostPassword(username, email);
    if (user == null) {
        // user could not be found
        this.context.put("message", I18n.getMessage("PasswordRecovery.invalidUserEmail"));
        this.lostPassword();
        return;
    }
    Executor.execute(new EmailSenderTask(new LostPasswordSpammer(user, SystemGlobals.getValue(ConfigKeys.MAIL_LOST_PASSWORD_SUBJECT))));
    this.setTemplateName(TemplateKeys.USER_LOSTPASSWORD_SEND);
    this.context.put("message", I18n.getMessage("PasswordRecovery.emailSent", new String[] { this.request.getContextPath() + "/user/login" + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION) }));
}
Also used : EmailSenderTask(net.jforum.util.mail.EmailSenderTask) User(net.jforum.entities.User) LostPasswordSpammer(net.jforum.util.mail.LostPasswordSpammer)

Example 3 with EmailSenderTask

use of net.jforum.util.mail.EmailSenderTask in project jforum2 by rafaelsteil.

the class ForumCommon method notifyUsers.

/**
 * Sends a "new topic" notification message to all users watching the forum.
 *
 * @param f The Forum changed
 * @param t The new topic
 * @param post the newly created message
 */
public static void notifyUsers(Forum f, Topic t, Post post) {
    if (SystemGlobals.getBoolValue(ConfigKeys.MAIL_NOTIFY_ANSWERS)) {
        try {
            ForumDAO dao = DataAccessDriver.getInstance().newForumDAO();
            List usersToNotify = dao.notifyUsers(f);
            // subscribed to the topic
            if (usersToNotify != null && usersToNotify.size() > 0) {
                Executor.execute(new EmailSenderTask(new ForumNewTopicSpammer(f, t, post, usersToNotify)));
            }
        } catch (Exception e) {
            logger.warn("Error while sending notification emails: " + e);
        }
    }
}
Also used : ForumDAO(net.jforum.dao.ForumDAO) ForumNewTopicSpammer(net.jforum.util.mail.ForumNewTopicSpammer) EmailSenderTask(net.jforum.util.mail.EmailSenderTask) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with EmailSenderTask

use of net.jforum.util.mail.EmailSenderTask in project jforum2 by rafaelsteil.

the class TopicsCommon method notifyUsers.

/**
 * Sends a "new post" notification message to all users watching the topic.
 *
 * @param t The changed topic
 * @param p The new message
 */
public static void notifyUsers(Topic t, Post p) {
    if (SystemGlobals.getBoolValue(ConfigKeys.MAIL_NOTIFY_ANSWERS)) {
        TopicDAO dao = DataAccessDriver.getInstance().newTopicDAO();
        List usersToNotify = dao.notifyUsers(t);
        // subscribed to the topic
        if (usersToNotify != null && usersToNotify.size() > 0) {
            Executor.execute(new EmailSenderTask(new TopicReplySpammer(t, p, usersToNotify)));
        }
    }
}
Also used : EmailSenderTask(net.jforum.util.mail.EmailSenderTask) TopicDAO(net.jforum.dao.TopicDAO) ArrayList(java.util.ArrayList) List(java.util.List) TopicReplySpammer(net.jforum.util.mail.TopicReplySpammer)

Example 5 with EmailSenderTask

use of net.jforum.util.mail.EmailSenderTask in project jforum2 by rafaelsteil.

the class PrivateMessageAction method sendSave.

public void sendSave() {
    if (!SessionFacade.isLogged()) {
        this.setTemplateName(ViewCommon.contextToLogin());
        return;
    }
    UserDAO userDao = DataAccessDriver.getInstance().newUserDAO();
    String toUserIdStr = this.request.getParameter("toUserId");
    String toUsername = this.request.getParameter("toUsername");
    int toUserId = -1;
    // inserted the username by hand in the form's field
    if (toUserIdStr == null || "".equals(toUserIdStr.trim())) {
        List l = userDao.findByName(toUsername, true);
        if (l.size() > 0) {
            User u = (User) l.get(0);
            toUserId = u.getId();
        }
    } else {
        toUserId = Integer.parseInt(toUserIdStr);
    }
    // We failed to get the user id?
    if (toUserId == -1) {
        this.setTemplateName(TemplateKeys.PM_SENDSAVE_USER_NOTFOUND);
        this.context.put("message", I18n.getMessage("PrivateMessage.userIdNotFound"));
        return;
    }
    PrivateMessage pm = new PrivateMessage();
    pm.setPost(PostCommon.fillPostFromRequest());
    // Sender
    User fromUser = new User();
    fromUser.setId(SessionFacade.getUserSession().getUserId());
    pm.setFromUser(fromUser);
    // Recipient
    User toUser = userDao.selectById(toUserId);
    pm.setToUser(toUser);
    boolean preview = ("1".equals(this.request.getParameter("preview")));
    if (!preview) {
        DataAccessDriver.getInstance().newPrivateMessageDAO().send(pm);
        this.setTemplateName(TemplateKeys.PM_SENDSAVE);
        this.context.put("message", I18n.getMessage("PrivateMessage.messageSent", new String[] { this.request.getContextPath() + "/pm/inbox" + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION) }));
        // If the target user if in the forum, then increments its
        // private messate count
        String sid = SessionFacade.isUserInSession(toUserId);
        if (sid != null) {
            UserSession us = SessionFacade.getUserSession(sid);
            us.setPrivateMessages(us.getPrivateMessages() + 1);
        }
        if (toUser.getEmail() != null && toUser.getEmail().trim().length() > 0 && SystemGlobals.getBoolValue(ConfigKeys.MAIL_NOTIFY_ANSWERS)) {
            Executor.execute(new EmailSenderTask(new PrivateMessageSpammer(toUser)));
        }
    } else {
        this.context.put("preview", true);
        this.context.put("post", pm.getPost());
        Post postPreview = new Post(pm.getPost());
        this.context.put("postPreview", PostCommon.preparePostForDisplay(postPreview));
        this.context.put("pm", pm);
        this.send();
    }
}
Also used : EmailSenderTask(net.jforum.util.mail.EmailSenderTask) User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO) Post(net.jforum.entities.Post) UserSession(net.jforum.entities.UserSession) List(java.util.List) PrivateMessageSpammer(net.jforum.util.mail.PrivateMessageSpammer) PrivateMessage(net.jforum.entities.PrivateMessage)

Aggregations

EmailSenderTask (net.jforum.util.mail.EmailSenderTask)5 List (java.util.List)3 User (net.jforum.entities.User)3 ArrayList (java.util.ArrayList)2 UserDAO (net.jforum.dao.UserDAO)2 UserSession (net.jforum.entities.UserSession)2 ForumDAO (net.jforum.dao.ForumDAO)1 TopicDAO (net.jforum.dao.TopicDAO)1 Post (net.jforum.entities.Post)1 PrivateMessage (net.jforum.entities.PrivateMessage)1 ActivationKeySpammer (net.jforum.util.mail.ActivationKeySpammer)1 ForumNewTopicSpammer (net.jforum.util.mail.ForumNewTopicSpammer)1 LostPasswordSpammer (net.jforum.util.mail.LostPasswordSpammer)1 PrivateMessageSpammer (net.jforum.util.mail.PrivateMessageSpammer)1 TopicReplySpammer (net.jforum.util.mail.TopicReplySpammer)1