Example #1
0
  static void load(String localeName, String mergeWith, boolean force) {
    if (!force
        && (localeName == null || localeName.trim().equals("") || I18n.contains(localeName))) {
      return;
    }

    if (localeNames.size() == 0) {
      loadLocales();
    }

    Properties p = new Properties();

    if (mergeWith != null) {
      if (!I18n.contains(mergeWith)) {
        load(mergeWith, null);
      }

      p.putAll((Properties) messagesMap.get(mergeWith));
    }

    FileInputStream fis = null;

    try {
      String filename = baseDir + localeNames.getProperty(localeName);

      // If the requested locale does not exist, use the default
      if (!new File(filename).exists()) {
        filename =
            baseDir
                + localeNames.getProperty(SystemGlobals.getValue(ConfigKeys.I18N_DEFAULT_ADMIN));
      }

      fis = new FileInputStream(filename);
      p.load(fis);
    } catch (IOException e) {
      throw new ForumException(e);
    } finally {
      if (fis != null) {
        try {
          fis.close();
        } catch (Exception e) {
        }
      }
    }

    messagesMap.put(localeName, p);

    watchForChanges(localeName);
  }
  /**
   * Setup optios and values for the user's session if authentication was ok.
   *
   * @param userSession The UserSession instance of the user
   * @param user The User instance of the authenticated user
   */
  protected void configureUserSession(UserSession userSession, User user) {

    LOG.trace("configureUserSession");
    userSession.dataToUser(user);

    // As an user may come back to the forum before its
    // last visit's session expires, we should check for
    // existent user information and then, if found, store
    // it to the database before getting his information back.
    String sessionId = SessionFacade.isUserInSession(user.getId());

    UserSession tmpUs;
    if (sessionId != null) {
      SessionFacade.storeSessionData(sessionId, JForumExecutionContext.getConnection());
      tmpUs = SessionFacade.getUserSession(sessionId);
      SessionFacade.remove(sessionId);
    } else {
      UserSessionDAO sm = DataAccessDriver.getInstance().newUserSessionDAO();
      tmpUs = sm.selectById(userSession, JForumExecutionContext.getConnection());
    }

    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()));
    }

    // If the execution point gets here, then the user
    // has chosen "autoLogin"
    userSession.setAutoLogin(true);
    SessionFacade.makeLogged();

    I18n.load(user.getLang());
  }
  /**
   * Setup common variables used by almost all templates.
   *
   * @param context SimpleHash The context to use
   * @param jforumContext JForumContext
   */
  public void prepareTemplateContext(SimpleHash context, ForumContext jforumContext) {
    RequestContext request = JForumExecutionContext.getRequest();

    context.put("karmaEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_KARMA_ENABLED));
    context.put("dateTimeFormat", SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
    context.put("autoLoginEnabled", SystemGlobals.getBoolValue(ConfigKeys.AUTO_LOGIN_ENABLED));
    context.put(
        "sso", ConfigKeys.TYPE_SSO.equals(SystemGlobals.getValue(ConfigKeys.AUTHENTICATION_TYPE)));
    context.put("contextPath", request.getContextPath());
    context.put("serverName", request.getServerName());
    context.put("templateName", SystemGlobals.getValue(ConfigKeys.TEMPLATE_DIR));
    context.put("extension", SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
    context.put("serverPort", Integer.toString(request.getServerPort()));
    context.put("I18n", I18n.getInstance());
    context.put("version", SystemGlobals.getValue(ConfigKeys.VERSION));
    context.put("forumTitle", SystemGlobals.getValue(ConfigKeys.FORUM_PAGE_TITLE));
    context.put("pageTitle", SystemGlobals.getValue(ConfigKeys.FORUM_PAGE_TITLE));
    context.put("metaKeywords", SystemGlobals.getValue(ConfigKeys.FORUM_PAGE_METATAG_KEYWORDS));
    context.put(
        "metaDescription", SystemGlobals.getValue(ConfigKeys.FORUM_PAGE_METATAG_DESCRIPTION));
    context.put("forumLink", SystemGlobals.getValue(ConfigKeys.FORUM_LINK));
    context.put("homepageLink", SystemGlobals.getValue(ConfigKeys.HOMEPAGE_LINK));
    context.put("encoding", SystemGlobals.getValue(ConfigKeys.ENCODING));
    context.put(
        "bookmarksEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_BOOKMARKS_ENABLED));
    context.put(
        "canAccessModerationLog",
        SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_LOG));
    context.put("JForumContext", jforumContext);
    context.put("timestamp", new Long(System.currentTimeMillis()));
  }
Example #4
0
  protected void loadConfigStuff() {
    ConfigLoader.loadUrlPatterns();
    I18n.load();
    Tpl.load(SystemGlobals.getValue(ConfigKeys.TEMPLATES_MAPPING));

    // BB Code
    BBCodeRepository.setBBCollection(new BBCodeHandler().parse());
  }
Example #5
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;
  }