Search in sources :

Example 21 with UserDAO

use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.

the class PrivateMessageAction method sendSave.

public void sendSave() {
    if (!SessionFacade.isLogged()) {
        this.setTemplateName(ViewCommon.contextToLogin());
        return;
    }
    UserDAO userDao = DataAccessDriver.getInstance().newUserDAO();
    String toUserIdStr = this.request.getParameter("toUserId");
    String toUsername = this.request.getParameter("toUsername");
    int toUserId = -1;
    // inserted the username by hand in the form's field
    if (toUserIdStr == null || "".equals(toUserIdStr.trim())) {
        List l = userDao.findByName(toUsername, true);
        if (l.size() > 0) {
            User u = (User) l.get(0);
            toUserId = u.getId();
        }
    } else {
        toUserId = Integer.parseInt(toUserIdStr);
    }
    // We failed to get the user id?
    if (toUserId == -1) {
        this.setTemplateName(TemplateKeys.PM_SENDSAVE_USER_NOTFOUND);
        this.context.put("message", I18n.getMessage("PrivateMessage.userIdNotFound"));
        return;
    }
    PrivateMessage pm = new PrivateMessage();
    pm.setPost(PostCommon.fillPostFromRequest());
    // Sender
    User fromUser = new User();
    fromUser.setId(SessionFacade.getUserSession().getUserId());
    pm.setFromUser(fromUser);
    // Recipient
    User toUser = userDao.selectById(toUserId);
    pm.setToUser(toUser);
    boolean preview = ("1".equals(this.request.getParameter("preview")));
    if (!preview) {
        DataAccessDriver.getInstance().newPrivateMessageDAO().send(pm);
        this.setTemplateName(TemplateKeys.PM_SENDSAVE);
        this.context.put("message", I18n.getMessage("PrivateMessage.messageSent", new String[] { this.request.getContextPath() + "/pm/inbox" + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION) }));
        // If the target user if in the forum, then increments its 
        // private messate count
        String sid = SessionFacade.isUserInSession(toUserId);
        if (sid != null) {
            UserSession us = SessionFacade.getUserSession(sid);
            us.setPrivateMessages(us.getPrivateMessages() + 1);
        }
        if (toUser.getEmail() != null && toUser.getEmail().trim().length() > 0 && SystemGlobals.getBoolValue(ConfigKeys.MAIL_NOTIFY_ANSWERS)) {
            Executor.execute(new EmailSenderTask(new PrivateMessageSpammer(toUser)));
        }
    } else {
        this.context.put("preview", true);
        this.context.put("post", pm.getPost());
        Post postPreview = new Post(pm.getPost());
        this.context.put("postPreview", PostCommon.preparePostForDisplay(postPreview));
        this.context.put("pm", pm);
        this.send();
    }
}
Also used : EmailSenderTask(net.jforum.util.mail.EmailSenderTask) User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO) Post(net.jforum.entities.Post) UserSession(net.jforum.entities.UserSession) List(java.util.List) PrivateMessageSpammer(net.jforum.util.mail.PrivateMessageSpammer) PrivateMessage(net.jforum.entities.PrivateMessage)

Example 22 with UserDAO

use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.

the class UserAction method activateAccount.

public void activateAccount() {
    String[] ids = this.request.getParameterValues("user_id");
    if (ids != null) {
        UserDAO dao = DataAccessDriver.getInstance().newUserDAO();
        for (int i = 0; i < ids.length; i++) {
            int userId = Integer.parseInt(ids[i]);
            dao.writeUserActive(userId);
        }
    }
    this.pendingActivations();
}
Also used : UserDAO(net.jforum.dao.UserDAO)

Example 23 with UserDAO

use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.

the class UserAction method delete.

// Delete
public void delete() {
    String[] ids = this.request.getParameterValues("user_id");
    UserDAO um = DataAccessDriver.getInstance().newUserDAO();
    if (ids != null) {
        for (int i = 0; i < ids.length; i++) {
            int user = Integer.parseInt(ids[i]);
            if (um.isDeleted(user)) {
                um.undelete(user);
            } else {
                String sessionId = SessionFacade.isUserInSession(user);
                if (sessionId != null) {
                    SessionFacade.remove(sessionId);
                }
                um.delete(user);
            }
        }
    }
    this.list();
}
Also used : UserDAO(net.jforum.dao.UserDAO)

Example 24 with UserDAO

use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.

the class UserAction method edit.

public void edit() {
    int userId = this.request.getIntParameter("id");
    UserDAO um = DataAccessDriver.getInstance().newUserDAO();
    User u = um.selectById(userId);
    this.setTemplateName(TemplateKeys.USER_ADMIN_EDIT);
    this.context.put("u", u);
    this.context.put("action", "editSave");
    this.context.put("specialRanks", DataAccessDriver.getInstance().newRankingDAO().selectSpecials());
    this.context.put("avatarAllowExternalUrl", SystemGlobals.getBoolValue(ConfigKeys.AVATAR_ALLOW_EXTERNAL_URL));
    this.context.put("admin", true);
}
Also used : User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO)

Example 25 with UserDAO

use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.

the class UserAction method pendingActivations.

public void pendingActivations() {
    UserDAO dao = DataAccessDriver.getInstance().newUserDAO();
    List users = dao.pendingActivations();
    this.setTemplateName(TemplateKeys.USER_ADMIN_PENDING_ACTIVATIONS);
    this.context.put("users", users);
}
Also used : UserDAO(net.jforum.dao.UserDAO) 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