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);
}
}
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) }));
}
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);
}
}
}
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)));
}
}
}
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();
}
}
Aggregations