use of net.jforum.context.RequestContext in project jforum2 by rafaelsteil.
the class PostCommon method fillPostFromRequest.
public static Post fillPostFromRequest(Post p, boolean isEdit) {
RequestContext request = JForumExecutionContext.getRequest();
p.setSubject(request.getParameter("subject"));
p.setBbCodeEnabled(request.getParameter("disable_bbcode") == null);
p.setSmiliesEnabled(request.getParameter("disable_smilies") == null);
p.setSignatureEnabled(request.getParameter("attach_sig") != null);
if (!isEdit) {
p.setUserIp(request.getRemoteAddr());
p.setUserId(SessionFacade.getUserSession().getUserId());
}
boolean htmlEnabled = SecurityRepository.canAccess(SecurityConstants.PERM_HTML_DISABLED, request.getParameter("forum_id"));
p.setHtmlEnabled(htmlEnabled && request.getParameter("disable_html") == null);
if (p.isHtmlEnabled()) {
p.setText(new SafeHtml().makeSafe(request.getParameter("message")));
} else {
p.setText(request.getParameter("message"));
}
return p;
}
use of net.jforum.context.RequestContext in project jforum2 by rafaelsteil.
the class POPPostAction method addDataToRequest.
/**
* Extracts information from a mail message and adds it to the request context
* @param m the mail message
* @param user the user who's sending the message
*/
private void addDataToRequest(POPMessage m, User user) {
RequestContext request = JForumExecutionContext.getRequest();
request.addParameter("forum_id", Integer.toString(this.discoverForumId(m.getListEmail())));
request.addParameter("topic_type", Integer.toString(Topic.TYPE_NORMAL));
request.addParameter("quick", "1");
request.addParameter("subject", m.getSubject());
request.addParameter("message", m.getMessage());
int topicId = this.discoverTopicId(m);
if (topicId > 0) {
request.addParameter("topic_id", Integer.toString(topicId));
}
if (!user.isBbCodeEnabled()) {
request.addParameter("disable_bbcode", "on");
}
if (!user.isSmiliesEnabled()) {
request.addParameter("disable_smilies", "on");
}
if (!user.isHtmlEnabled()) {
request.addParameter("disable_html", "on");
}
}
use of net.jforum.context.RequestContext in project jforum2 by rafaelsteil.
the class UserCommon method saveUser.
/**
* Updates the user information
*
* @param userId int The user id we are saving
* @return List
*/
public static List saveUser(int userId) {
List errors = new ArrayList();
UserDAO um = DataAccessDriver.getInstance().newUserDAO();
User u = um.selectById(userId);
RequestContext request = JForumExecutionContext.getRequest();
boolean isAdmin = SessionFacade.getUserSession().isAdmin();
if (isAdmin) {
String username = request.getParameter("username");
if (username != null) {
u.setUsername(username.trim());
}
if (request.getParameter("rank_special") != null) {
u.setRankId(request.getIntParameter("rank_special"));
}
}
SafeHtml safeHtml = new SafeHtml();
u.setId(userId);
u.setIcq(safeHtml.makeSafe(request.getParameter("icq")));
u.setAim(safeHtml.makeSafe(request.getParameter("aim")));
u.setMsnm(safeHtml.makeSafe(request.getParameter("msn")));
u.setYim(safeHtml.makeSafe(request.getParameter("yim")));
u.setFrom(safeHtml.makeSafe(request.getParameter("location")));
u.setOccupation(safeHtml.makeSafe(request.getParameter("occupation")));
u.setInterests(safeHtml.makeSafe(request.getParameter("interests")));
u.setBiography(safeHtml.makeSafe(request.getParameter("biography")));
u.setSignature(safeHtml.makeSafe(request.getParameter("signature")));
u.setViewEmailEnabled(request.getParameter("viewemail").equals("1"));
u.setViewOnlineEnabled(request.getParameter("hideonline").equals("0"));
u.setNotifyPrivateMessagesEnabled(request.getParameter("notifypm").equals("1"));
u.setNotifyOnMessagesEnabled(request.getParameter("notifyreply").equals("1"));
u.setAttachSignatureEnabled(request.getParameter("attachsig").equals("1"));
u.setHtmlEnabled(request.getParameter("allowhtml").equals("1"));
u.setLang(request.getParameter("language"));
u.setBbCodeEnabled("1".equals(request.getParameter("allowbbcode")));
u.setSmiliesEnabled("1".equals(request.getParameter("allowsmilies")));
u.setNotifyAlways("1".equals(request.getParameter("notify_always")));
u.setNotifyText("1".equals(request.getParameter("notify_text")));
String website = safeHtml.makeSafe(request.getParameter("website"));
if (!StringUtils.isEmpty(website) && !website.toLowerCase().startsWith("http://")) {
website = "http://" + website;
}
u.setWebSite(website);
String currentPassword = request.getParameter("current_password");
boolean isCurrentPasswordEmpty = currentPassword == null || "".equals(currentPassword.trim());
if (isAdmin || !isCurrentPasswordEmpty) {
if (!isCurrentPasswordEmpty) {
currentPassword = MD5.crypt(currentPassword);
}
if (isAdmin || u.getPassword().equals(currentPassword)) {
u.setEmail(safeHtml.makeSafe(request.getParameter("email")));
String newPassword = request.getParameter("new_password");
if (newPassword != null && newPassword.length() > 0) {
u.setPassword(MD5.crypt(newPassword));
}
} else {
errors.add(I18n.getMessage("User.currentPasswordInvalid"));
}
}
if (request.getParameter("avatardel") != null) {
File avatarFile = new File(u.getAvatar());
File fileToDelete = new File(SystemGlobals.getApplicationPath() + "/images/avatar/" + avatarFile.getName());
if (fileToDelete.exists()) {
fileToDelete.delete();
}
u.setAvatar(null);
}
if (request.getObjectParameter("avatar") != null) {
try {
UserCommon.handleAvatar(u);
} catch (Exception e) {
UserCommon.logger.warn("Problems while uploading the avatar: " + e);
errors.add(I18n.getMessage("User.avatarUploadError"));
}
} else if (SystemGlobals.getBoolValue(ConfigKeys.AVATAR_ALLOW_EXTERNAL_URL)) {
String avatarUrl = request.getParameter("avatarUrl");
if (!StringUtils.isEmpty(avatarUrl)) {
if (avatarUrl.toLowerCase().startsWith("http://")) {
try {
Image image = ImageIO.read(new URL(avatarUrl));
if (image != null) {
if (image.getWidth(null) > SystemGlobals.getIntValue(ConfigKeys.AVATAR_MAX_WIDTH) || image.getHeight(null) > SystemGlobals.getIntValue(ConfigKeys.AVATAR_MAX_HEIGHT)) {
errors.add(I18n.getMessage("User.avatarTooBig"));
} else {
u.setAvatar(avatarUrl);
}
}
} catch (Exception e) {
errors.add(I18n.getMessage("User.avatarUploadError"));
}
} else {
errors.add(I18n.getMessage("User.avatarUrlShouldHaveHttp"));
}
}
}
if (errors.size() == 0) {
um.update(u);
if (SessionFacade.getUserSession().getUserId() == userId) {
SessionFacade.getUserSession().setLang(u.getLang());
}
}
return errors;
}
use of net.jforum.context.RequestContext in project jforum2 by rafaelsteil.
the class ModerationHelper method buildModerationLogFromRequest.
public ModerationLog buildModerationLogFromRequest() {
RequestContext request = JForumExecutionContext.getRequest();
ModerationLog log = new ModerationLog();
User user = new User();
user.setId(SessionFacade.getUserSession().getUserId());
log.setUser(user);
log.setDescription(request.getParameter("log_description"));
log.setOriginalMessage(request.getParameter("log_original_message"));
log.setType(request.getIntParameter("log_type"));
if (request.getParameter("post_id") != null) {
log.setPostId(request.getIntParameter("post_id"));
}
String[] values = request.getParameterValues("topic_id");
if (values != null && values.length == 1) {
log.setTopicId(request.getIntParameter("topic_id"));
}
return log;
}
use of net.jforum.context.RequestContext in project jforum2 by rafaelsteil.
the class PermissionProcessHelper method processData.
public void processData() {
RequestContext request = JForumExecutionContext.getRequest();
Enumeration e = request.getParameterNames();
while (e.hasMoreElements()) {
String paramName = (String) e.nextElement();
if (paramName.startsWith("perm_")) {
if (paramName.endsWith("$single")) {
String paramValue = request.getParameter(paramName);
if (paramValue.equals("deny")) {
continue;
}
paramName = paramName.substring(0, paramName.indexOf('$'));
Role role = new Role();
role.setName(paramName);
this.pc.addRole(this.groupId, role);
} else {
String[] paramValues = request.getParameterValues(paramName);
RoleValueCollection roleValues = new RoleValueCollection();
if ("all".equals(paramValues[0])) {
this.addRoleValues(roleValues, this.getSplitedValues("all" + paramName));
} else {
List allowList = new ArrayList(Arrays.asList(this.getSplitedValues("all" + paramName)));
allowList.removeAll(Arrays.asList(paramValues));
this.addRoleValues(roleValues, allowList.toArray());
}
Role role = new Role();
role.setName(paramName);
this.pc.addRole(this.groupId, role, roleValues);
}
}
}
}
Aggregations