use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.
the class UserAction method edit.
public void edit() {
if (this.canEdit()) {
int userId = this.request.getIntParameter("user_id");
UserDAO um = DataAccessDriver.getInstance().newUserDAO();
User u = um.selectById(userId);
this.context.put("u", u);
this.context.put("action", "editSave");
this.context.put("pageTitle", I18n.getMessage("UserProfile.profileFor") + " " + u.getUsername());
this.context.put("avatarAllowExternalUrl", SystemGlobals.getBoolValue(ConfigKeys.AVATAR_ALLOW_EXTERNAL_URL));
this.setTemplateName(TemplateKeys.USER_EDIT);
}
}
use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.
the class UserAction method validateLogin.
public void validateLogin() {
String password;
String username;
if (parseBasicAuthentication()) {
username = (String) this.request.getAttribute("username");
password = (String) this.request.getAttribute("password");
} else {
username = this.request.getParameter("username");
password = this.request.getParameter("password");
}
boolean validInfo = false;
if (password.length() > 0) {
User user = this.validateLogin(username, password);
if (user != null) {
// Note: here we only want to set the redirect location if it hasn't already been
// set. This will give the LoginAuthenticator a chance to set the redirect location.
this.buildSucessfulLoginRedirect();
SessionFacade.makeLogged();
String sessionId = SessionFacade.isUserInSession(user.getId());
UserSession userSession = new UserSession(SessionFacade.getUserSession());
// Remove the "guest" session
SessionFacade.remove(userSession.getSessionId());
userSession.dataToUser(user);
UserSession currentUs = SessionFacade.getUserSession(sessionId);
// Check if the user is returning to the system
// before its last session has expired ( hypothesis )
UserSession tmpUs;
if (sessionId != null && currentUs != null) {
// Write its old session data
SessionFacade.storeSessionData(sessionId, JForumExecutionContext.getConnection());
tmpUs = new UserSession(currentUs);
SessionFacade.remove(sessionId);
} else {
UserSessionDAO sm = DataAccessDriver.getInstance().newUserSessionDAO();
tmpUs = sm.selectById(userSession, JForumExecutionContext.getConnection());
}
I18n.load(user.getLang());
// Autologin
if (this.request.getParameter("autologin") != null && SystemGlobals.getBoolValue(ConfigKeys.AUTO_LOGIN_ENABLED)) {
userSession.setAutoLogin(true);
// Generate the user-specific hash
String systemHash = MD5.crypt(SystemGlobals.getValue(ConfigKeys.USER_HASH_SEQUENCE) + user.getId());
String userHash = MD5.crypt(System.currentTimeMillis() + systemHash);
// Persist the user hash
UserDAO dao = DataAccessDriver.getInstance().newUserDAO();
dao.saveUserAuthHash(user.getId(), userHash);
systemHash = MD5.crypt(userHash);
ControllerUtils.addCookie(SystemGlobals.getValue(ConfigKeys.COOKIE_AUTO_LOGIN), "1");
ControllerUtils.addCookie(SystemGlobals.getValue(ConfigKeys.COOKIE_USER_HASH), systemHash);
} else {
// Remove cookies for safety
ControllerUtils.addCookie(SystemGlobals.getValue(ConfigKeys.COOKIE_USER_HASH), null);
ControllerUtils.addCookie(SystemGlobals.getValue(ConfigKeys.COOKIE_AUTO_LOGIN), null);
}
if (tmpUs == null) {
userSession.setLastVisit(new Date(System.currentTimeMillis()));
} else {
// Update last visit and session start time
userSession.setLastVisit(new Date(tmpUs.getStartTime().getTime() + tmpUs.getSessionTime()));
}
SessionFacade.add(userSession);
SessionFacade.setAttribute(ConfigKeys.TOPICS_READ_TIME, new HashMap());
ControllerUtils.addCookie(SystemGlobals.getValue(ConfigKeys.COOKIE_NAME_DATA), Integer.toString(user.getId()));
SecurityRepository.load(user.getId(), true);
validInfo = true;
}
}
// Invalid login
if (!validInfo) {
this.context.put("invalidLogin", "1");
this.setTemplateName(TemplateKeys.USER_VALIDATE_LOGIN);
if (this.request.getParameter("returnPath") != null) {
this.context.put("returnPath", this.request.getParameter("returnPath"));
}
} else if (this.request.getParameter("returnPath") != null) {
JForumExecutionContext.setRedirect(this.request.getParameter("returnPath"));
}
}
use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.
the class ModerationAction method doSave.
public void doSave() {
String[] posts = this.request.getParameterValues("post_id");
if (posts != null) {
TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
for (int i = 0; i < posts.length; i++) {
int postId = Integer.parseInt(posts[i]);
String status = this.request.getParameter("status_" + postId);
if ("defer".startsWith(status)) {
continue;
}
if ("aprove".startsWith(status)) {
Post p = DataAccessDriver.getInstance().newPostDAO().selectById(postId);
// Check is the post is in fact waiting for moderation
if (!p.isModerationNeeded()) {
continue;
}
UserDAO userDao = DataAccessDriver.getInstance().newUserDAO();
User u = userDao.selectById(p.getUserId());
boolean first = false;
Topic t = TopicRepository.getTopic(new Topic(p.getTopicId()));
if (t == null) {
t = topicDao.selectById(p.getTopicId());
if (t.getId() == 0) {
first = true;
t = topicDao.selectRaw(p.getTopicId());
}
}
DataAccessDriver.getInstance().newModerationDAO().aprovePost(postId);
boolean firstPost = (t.getFirstPostId() == postId);
if (!firstPost) {
t.setTotalReplies(t.getTotalReplies() + 1);
}
t.setLastPostId(postId);
t.setLastPostBy(u);
t.setLastPostDate(p.getTime());
t.setLastPostTime(p.getFormatedTime());
topicDao.update(t);
if (first) {
t = topicDao.selectById(t.getId());
}
TopicsCommon.updateBoardStatus(t, postId, firstPost, topicDao, DataAccessDriver.getInstance().newForumDAO());
ForumRepository.updateForumStats(t, u, p);
TopicsCommon.notifyUsers(t, p);
userDao.incrementPosts(p.getUserId());
if (SystemGlobals.getBoolValue(ConfigKeys.POSTS_CACHE_ENABLED)) {
PostRepository.append(p.getTopicId(), PostCommon.preparePostForDisplay(p));
}
} else {
PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
Post post = pm.selectById(postId);
if (post == null || !post.isModerationNeeded()) {
continue;
}
pm.delete(post);
new AttachmentCommon(this.request, post.getForumId()).deleteAttachments(postId, post.getForumId());
int totalPosts = topicDao.getTotalPosts(post.getTopicId());
if (totalPosts == 0) {
TopicsCommon.deleteTopic(post.getTopicId(), post.getForumId(), true);
}
}
}
}
}
use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.
the class ForumRepository method loadUsersInfo.
private void loadUsersInfo() {
UserDAO udao = DataAccessDriver.getInstance().newUserDAO();
cache.add(FQN, LAST_USER, udao.getLastUserInfo());
cache.add(FQN, TOTAL_USERS, new Integer(udao.getTotalUsers()));
}
use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.
the class UserAction method groups.
// Groups
public void groups() {
int userId = this.request.getIntParameter("id");
UserDAO um = DataAccessDriver.getInstance().newUserDAO();
User u = um.selectById(userId);
List selectedList = new ArrayList();
for (Iterator iter = u.getGroupsList().iterator(); iter.hasNext(); ) {
selectedList.add(new Integer(((Group) iter.next()).getId()));
}
this.context.put("selectedList", selectedList);
this.context.put("groups", new TreeGroup().getNodes());
this.context.put("user", u);
this.context.put("userId", new Integer(userId));
this.setTemplateName(TemplateKeys.USER_ADMIN_GROUPS);
this.context.put("groupFor", I18n.getMessage("User.GroupsFor", new String[] { u.getUsername() }));
}
Aggregations