use of net.jforum.entities.UserSession in project jforum2 by rafaelsteil.
the class PrivateMessageAction method read.
public void read() {
if (!SessionFacade.isLogged()) {
this.setTemplateName(ViewCommon.contextToLogin());
return;
}
int id = this.request.getIntParameter("id");
PrivateMessage pm = new PrivateMessage();
pm.setId(id);
pm = DataAccessDriver.getInstance().newPrivateMessageDAO().selectById(pm);
// Don't allow the read of messages that don't belongs
// to the current user
UserSession us = SessionFacade.getUserSession();
int userId = us.getUserId();
if (pm.getToUser().getId() == userId || pm.getFromUser().getId() == userId) {
pm.getPost().setText(PostCommon.preparePostForDisplay(pm.getPost()).getText());
// Update the message status, if needed
if (pm.getType() == PrivateMessageType.NEW) {
pm.setType(PrivateMessageType.READ);
DataAccessDriver.getInstance().newPrivateMessageDAO().updateType(pm);
int totalMessages = us.getPrivateMessages();
if (totalMessages > 0) {
us.setPrivateMessages(totalMessages - 1);
}
}
User u = pm.getFromUser();
ViewCommon.prepareUserSignature(u);
this.context.put("pm", pm);
this.setTemplateName(TemplateKeys.PM_READ);
} else {
this.setTemplateName(TemplateKeys.PM_READ_DENIED);
this.context.put("message", I18n.getMessage("PrivateMessage.readDenied"));
}
}
use of net.jforum.entities.UserSession in project jforum2 by rafaelsteil.
the class PrivateMessageAction method delete.
public void delete() {
if (!SessionFacade.isLogged()) {
this.setTemplateName(ViewCommon.contextToLogin());
return;
}
String[] ids = this.request.getParameterValues("id");
if (ids != null && ids.length > 0) {
PrivateMessage[] deleteList = new PrivateMessage[ids.length];
int unreadCount = 0;
PrivateMessageDAO dao = DataAccessDriver.getInstance().newPrivateMessageDAO();
for (int i = 0; i < ids.length; i++) {
PrivateMessage pm = dao.selectById(new PrivateMessage(Integer.parseInt(ids[i])));
if (pm.getType() == PrivateMessageType.NEW) {
unreadCount++;
}
deleteList[i] = pm;
}
UserSession userSession = SessionFacade.getUserSession();
dao.delete(deleteList, userSession.getUserId());
// Subtracts the number of delete messages
int total = userSession.getPrivateMessages() - unreadCount;
if (total < 0) {
total = 0;
}
userSession.setPrivateMessages(total);
}
this.setTemplateName(TemplateKeys.PM_DELETE);
this.context.put("message", I18n.getMessage("PrivateMessage.deleteDone", new String[] { this.request.getContextPath() + "/pm/inbox" + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION) }));
}
use of net.jforum.entities.UserSession in project jforum2 by rafaelsteil.
the class InstallAction method checkLanguage.
private void checkLanguage() {
String lang = this.request.getParameter("l");
if (lang == null) {
Locale locale = this.request.getLocale();
lang = locale.getLanguage() + "_" + locale.getCountry();
}
if (!I18n.languageExists(lang)) {
return;
}
I18n.load(lang);
UserSession us = new UserSession();
us.setLang(lang);
SessionFacade.add(us);
this.addToSessionAndContext("language", lang);
}
use of net.jforum.entities.UserSession 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.entities.UserSession in project jforum2 by rafaelsteil.
the class UserAction method logout.
public void logout() {
JForumExecutionContext.setRedirect(this.request.getContextPath() + "/forums/list" + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
UserSession userSession = SessionFacade.getUserSession();
SessionFacade.storeSessionData(userSession.getSessionId(), JForumExecutionContext.getConnection());
SessionFacade.makeUnlogged();
SessionFacade.remove(userSession.getSessionId());
// Disable auto login
userSession.setAutoLogin(false);
userSession.makeAnonymous();
SessionFacade.add(userSession);
}
Aggregations