use of net.jforum.dao.UserDAO 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.dao.UserDAO in project jforum2 by rafaelsteil.
the class PostAction method listByUser.
public void listByUser() {
PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
UserDAO um = DataAccessDriver.getInstance().newUserDAO();
TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO();
User u = um.selectById(this.request.getIntParameter("user_id"));
if (u.getId() == 0) {
this.context.put("message", I18n.getMessage("User.notFound"));
this.setTemplateName(TemplateKeys.USER_NOT_FOUND);
return;
}
int count = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
int start = ViewCommon.getStartPage();
int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
List posts = pm.selectByUserByLimit(u.getId(), start, postsPerPage);
int totalMessages = pm.countUserPosts(u.getId());
// get list of forums
Map topics = new HashMap();
Map forums = new HashMap();
for (Iterator iter = posts.iterator(); iter.hasNext(); ) {
Post p = (Post) iter.next();
if (!topics.containsKey(new Integer(p.getTopicId()))) {
Topic t = TopicRepository.getTopic(new Topic(p.getTopicId()));
if (t == null) {
t = tm.selectRaw(p.getTopicId());
}
this.context.put("attachmentsEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, Integer.toString(t.getForumId())));
this.context.put("am", new AttachmentCommon(this.request, t.getForumId()));
topics.put(new Integer(t.getId()), t);
}
if (!forums.containsKey(new Integer(p.getForumId()))) {
Forum f = ForumRepository.getForum(p.getForumId());
if (f == null) {
// Ok, probably the user does not have permission to see this forum
iter.remove();
totalMessages--;
continue;
}
forums.put(new Integer(f.getId()), f);
}
PostCommon.preparePostForDisplay(p);
}
this.setTemplateName(TemplateKeys.POSTS_USER_POSTS_LIST);
this.context.put("canDownloadAttachments", SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_DOWNLOAD));
this.context.put("rssEnabled", SystemGlobals.getBoolValue(ConfigKeys.RSS_ENABLED));
this.context.put("allCategories", ForumCommon.getAllCategoriesAndForums(false));
this.context.put("posts", posts);
this.context.put("topics", topics);
this.context.put("forums", forums);
this.context.put("u", u);
this.context.put("pageTitle", I18n.getMessage("PostShow.userPosts") + " " + u.getUsername());
this.context.put("karmaMin", new Integer(SystemGlobals.getValue(ConfigKeys.KARMA_MIN_POINTS)));
this.context.put("karmaMax", new Integer(SystemGlobals.getValue(ConfigKeys.KARMA_MAX_POINTS)));
ViewCommon.contextToPagination(start, totalMessages, count);
}
use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.
the class UserAction method profile.
public void profile() {
DataAccessDriver da = DataAccessDriver.getInstance();
UserDAO udao = da.newUserDAO();
User u = udao.selectById(this.request.getIntParameter("user_id"));
if (u.getId() == 0) {
this.userNotFound();
} else {
this.setTemplateName(TemplateKeys.USER_PROFILE);
this.context.put("karmaEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_KARMA_ENABLED));
this.context.put("rank", new RankingRepository());
this.context.put("u", u);
this.context.put("avatarAllowExternalUrl", SystemGlobals.getBoolValue(ConfigKeys.AVATAR_ALLOW_EXTERNAL_URL));
int loggedId = SessionFacade.getUserSession().getUserId();
int count = 0;
List bookmarks = da.newBookmarkDAO().selectByUser(u.getId());
for (Iterator iter = bookmarks.iterator(); iter.hasNext(); ) {
Bookmark b = (Bookmark) iter.next();
if (b.isPublicVisible() || loggedId == u.getId()) {
count++;
}
}
this.context.put("pageTitle", I18n.getMessage("UserProfile.allAbout") + " " + u.getUsername());
this.context.put("nbookmarks", new Integer(count));
this.context.put("ntopics", new Integer(da.newTopicDAO().countUserTopics(u.getId())));
this.context.put("nposts", new Integer(da.newPostDAO().countUserPosts(u.getId())));
}
}
use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.
the class UserAction method activateAccount.
public void activateAccount() {
String hash = this.request.getParameter("hash");
int userId = (new Integer(this.request.getParameter("user_id"))).intValue();
UserDAO um = DataAccessDriver.getInstance().newUserDAO();
User u = um.selectById(userId);
boolean isValid = um.validateActivationKeyHash(userId, hash);
if (isValid) {
// Activate the account
um.writeUserActive(userId);
this.logNewRegisteredUserIn(userId, u);
} else {
this.setTemplateName(TemplateKeys.USER_INVALID_ACTIVATION);
this.context.put("message", I18n.getMessage("User.invalidActivationKey", new Object[] { this.request.getContextPath() + "/user/activateManual" + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION) }));
}
}
use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.
the class PostAction method quote.
public void quote() {
PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
Post p = pm.selectById(this.request.getIntParameter("post_id"));
if (p.getId() == 0) {
this.postNotFound();
return;
}
if (p.isModerationNeeded()) {
this.notModeratedYet();
return;
}
if (!this.anonymousPost(p.getForumId())) {
return;
}
Topic topic = TopicRepository.getTopic(new Topic(p.getTopicId()));
if (topic == null) {
topic = DataAccessDriver.getInstance().newTopicDAO().selectRaw(p.getTopicId());
}
if (!TopicsCommon.isTopicAccessible(topic.getForumId())) {
return;
}
if (topic.getStatus() == Topic.STATUS_LOCKED) {
this.topicLocked();
return;
}
this.setTemplateName(TemplateKeys.POSTS_QUOTE);
this.context.put("forum", ForumRepository.getForum(p.getForumId()));
this.context.put("action", "insertSave");
this.context.put("post", p);
UserDAO um = DataAccessDriver.getInstance().newUserDAO();
User u = um.selectById(p.getUserId());
int userId = SessionFacade.getUserSession().getUserId();
this.context.put("attachmentsEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, Integer.toString(topic.getForumId())));
QuotaLimit ql = new AttachmentCommon(this.request, topic.getForumId()).getQuotaLimit(userId);
this.context.put("maxAttachmentsSize", new Long(ql != null ? ql.getSizeInBytes() : 1));
this.context.put("moderationLoggingEnabled", SystemGlobals.getBoolValue(ConfigKeys.MODERATION_LOGGING_ENABLED));
this.context.put("maxAttachments", SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_MAX_POST));
this.context.put("isNewPost", true);
this.context.put("topic", topic);
this.context.put("quote", "true");
this.context.put("quoteUser", u.getUsername());
this.context.put("setType", false);
this.context.put("htmlAllowed", SecurityRepository.canAccess(SecurityConstants.PERM_HTML_DISABLED, Integer.toString(topic.getForumId())));
this.context.put("start", this.request.getParameter("start"));
this.context.put("user", DataAccessDriver.getInstance().newUserDAO().selectById(userId));
this.context.put("pageTitle", I18n.getMessage("PostForm.reply") + " " + topic.getTitle());
this.context.put("smilies", SmiliesRepository.getSmilies());
boolean needCaptcha = SystemGlobals.getBoolValue(ConfigKeys.CAPTCHA_POSTS);
if (needCaptcha) {
SessionFacade.getUserSession().createNewCaptcha();
}
this.context.put("needCaptcha", needCaptcha);
}
Aggregations