Search in sources :

Example 6 with UserDAO

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);
    }
}
Also used : User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO)

Example 7 with UserDAO

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"));
    }
}
Also used : User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO) HashMap(java.util.HashMap) UserSession(net.jforum.entities.UserSession) UserSessionDAO(net.jforum.dao.UserSessionDAO) Date(java.util.Date)

Example 8 with UserDAO

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);
                }
            }
        }
    }
}
Also used : User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO) PostDAO(net.jforum.dao.PostDAO) Post(net.jforum.entities.Post) TopicDAO(net.jforum.dao.TopicDAO) Topic(net.jforum.entities.Topic) AttachmentCommon(net.jforum.view.forum.common.AttachmentCommon)

Example 9 with UserDAO

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()));
}
Also used : UserDAO(net.jforum.dao.UserDAO)

Example 10 with UserDAO

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() }));
}
Also used : TreeGroup(net.jforum.util.TreeGroup) Group(net.jforum.entities.Group) User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO) TreeGroup(net.jforum.util.TreeGroup) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

UserDAO (net.jforum.dao.UserDAO)26 User (net.jforum.entities.User)18 List (java.util.List)12 ArrayList (java.util.ArrayList)7 Iterator (java.util.Iterator)6 Topic (net.jforum.entities.Topic)6 Post (net.jforum.entities.Post)5 HashMap (java.util.HashMap)4 PostDAO (net.jforum.dao.PostDAO)4 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)4 Map (java.util.Map)3 DataAccessDriver (net.jforum.dao.DataAccessDriver)3 Forum (net.jforum.entities.Forum)3 UserSession (net.jforum.entities.UserSession)3 Date (java.util.Date)2 TopicDAO (net.jforum.dao.TopicDAO)2 Group (net.jforum.entities.Group)2 PrivateMessage (net.jforum.entities.PrivateMessage)2 QuotaLimit (net.jforum.entities.QuotaLimit)2 APIException (net.jforum.exceptions.APIException)2