Ejemplo n.º 1
0
  /**
   * @see #getAllCategoriesAndForums(UserSession, int, Map, boolean)
   * @return List
   * @param checkUnreadPosts boolean
   */
  public static List getAllCategoriesAndForums(boolean checkUnreadPosts) {

    LOG.trace("getAllCategoriesAndForums");
    return getAllCategoriesAndForums(
        SessionFacade.getUserSession(),
        SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID),
        SessionFacade.getTopicsReadTime(),
        checkUnreadPosts);
  }
Ejemplo n.º 2
0
  /**
   * @see #getAllCategoriesAndForums(boolean)
   * @return List
   */
  public static List getAllCategoriesAndForums() {

    LOG.trace("getAllCategoriesAndForums");
    UserSession us = SessionFacade.getUserSession();
    boolean checkUnread =
        (us != null && us.getUserId() != SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID));
    return getAllCategoriesAndForums(checkUnread);
  }
Ejemplo n.º 3
0
  /**
   * Gets the language name for the current request. The method will first look at {@link
   * UserSession#getLang()} and use it if any value is found. Otherwise, the default board language
   * will be used
   *
   * @return String
   */
  public static String getUserLanguage() {
    UserSession us = SessionFacade.getUserSession();

    if (us == null || us.getLang() == null || us.getLang().trim().equals("")) {
      return defaultName;
    }

    return us.getLang();
  }
Ejemplo n.º 4
0
  /**
   * Check if the logged user has access to the role. This method gets user's id from its session.
   *
   * @param roleName The role name to verify
   * @param value The value relacted to the role to verify for access
   * @return <code>true</code> if the user has access to the role, <code>false</code> if access is
   *     denied
   */
  public static boolean canAccess(String roleName, String value) {
    UserSession us = SessionFacade.getUserSession();

    if (us == null) {
      logger.warn(
          "Found null userSession. Going anonymous. Session id #"
              + JForumExecutionContext.getRequest().getSessionContext().getId());
      us = new UserSession();
      us.makeAnonymous();
    }

    return canAccess(us.getUserId(), roleName, value);
  }
Ejemplo n.º 5
0
  /**
   * @see #getMessage(String, String, Object[])
   * @param messageName String
   * @param params Object
   * @return String
   */
  public static String getMessage(String messageName, Object params[]) {
    String lang = "";
    UserSession us = SessionFacade.getUserSession();

    if (us != null && us.getLang() != null) {
      lang = us.getLang();
    }

    if ("".equals(lang)) {
      return getMessage(defaultName, messageName, params);
    }

    return getMessage(lang, messageName, params);
  }
Ejemplo n.º 6
0
  /**
   * @see org.vraptor.VRaptorServlet#service(javax.servlet.http.HttpServletRequest,
   *     javax.servlet.http.HttpServletResponse)
   */
  @Override
  protected void service(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    request.setAttribute("infoq", this.infoqAgregator.getItems());
    request.setAttribute("news", this.newsAgregator.getItems());
    request.setAttribute("forum", this.forumAgregator.getItems());

    boolean isLogged = "1".equals(request.getSession().getAttribute(ConfigKeys.LOGGED));
    request.setAttribute("logged", isLogged);

    if (isLogged) {
      UserSession userSession = SessionFacade.getUserSession(request.getSession().getId());
      request.setAttribute("userSession", userSession);
    }

    super.service(request, response);
  }
Ejemplo n.º 7
0
  /**
   * Is the user online?
   *
   * @return true if user is in Session
   */
  public boolean isOnline() {

    LOG.trace("isOnline");
    return (SessionFacade.isUserInSession(this.id) != null);
  }
Ejemplo n.º 8
0
  /**
   * Updates the user information
   *
   * @param userId int The user id we are saving
   * @return List
   */
  public static List saveUser(int userId) {

    LOG.trace("saveUser");
    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.LOG.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;
  }