Package ru.org.linux.site

Examples of ru.org.linux.site.Template


    @RequestParam("msgid") int msgid,
    @RequestParam("reason") String reason,
    @RequestParam(value="bonus", defaultValue = "0") int bonus,
    HttpServletRequest request
  ) throws Exception {
    Template tmpl = Template.getTemplate(request);

    if (!tmpl.isSessionAuthorized()) {
      throw new AccessViolationException("Not authorized");
    }

    User user = tmpl.getCurrentUser();

    user.checkAnonymous();

    Topic message = messageDao.getById(msgid);
View Full Code Here


  @RequestMapping(value = "/undelete.jsp", method = RequestMethod.GET)
  public ModelAndView undeleteForm(
    HttpServletRequest request,
    @RequestParam int msgid
  ) throws Exception {
    Template tmpl = Template.getTemplate(request);

    if (!tmpl.isModeratorSession()) {
      throw new AccessViolationException("Not authorized");
    }

    Topic message = messageDao.getById(msgid);

    checkUndeletable(message);

    ModelAndView mv = new ModelAndView("undelete");
    mv.getModel().put("message", message);
    mv.getModel().put("preparedMessage", prepareService.prepareTopic(message, request.isSecure(), tmpl.getCurrentUser()));

    return mv;
  }
View Full Code Here

  @RequestMapping(value="/undelete.jsp", method=RequestMethod.POST)
  public ModelAndView undelete(
    HttpServletRequest request,
    @RequestParam int msgid
  ) throws Exception {
    Template tmpl = Template.getTemplate(request);

    if (!tmpl.isModeratorSession()) {
      throw new AccessViolationException("Not authorized");
    }

    Topic message = messageDao.getById(msgid);

    checkUndeletable(message);

    if(message.isDeleted()) {
      messageDao.undelete(message);
    }

    logger.info("Восстановлено сообщение " + msgid + " пользователем " + tmpl.getNick());

    // Undelete msgs from search index
    searchQueueSender.updateMessage(msgid, true);

    return new ModelAndView("action-done", "message", "Сообщение восстановлено");
View Full Code Here

  public ModelAndView viewAll(
          @RequestParam(value = "section", required = false, defaultValue = "0") int sectionId,
          HttpServletRequest request,
          HttpServletResponse response
  ) {
    Template tmpl = Template.getTemplate(request);

    ModelAndView modelAndView = new ModelAndView("view-all");

    Section section = null;
    if (sectionId != 0) {
      section = sectionService.getSection(sectionId);
      modelAndView.addObject("section", section);
      modelAndView.addObject("addlink", AddTopicController.getAddUrl(section));
    }

    response.setDateHeader("Expires", new Date(System.currentTimeMillis() - 20 * 3600 * 1000).getTime());
    response.setDateHeader("Last-Modified", new Date(System.currentTimeMillis() - 120 * 1000).getTime());

    String title;

    switch (sectionId) {
      case Section.SECTION_NEWS:
        title = "Неподтвержденные новости";
        break;
      case Section.SECTION_POLLS:
        title = "Неподтвержденные опросы";
        break;
      case Section.SECTION_GALLERY:
        title = "Неподтвержденные изображения";
        break;
      case 0:
        title = "Просмотр неподтвержденных сообщений";
        break;
      default:
        title = "Неподтвержденные: "+section.getName();
        break;
    }

    modelAndView.addObject("title", title);

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MONTH, -3);

    List<Topic> messages = topicListService.getAllTopicsFeed(section, calendar.getTime());
    modelAndView.addObject(
            "messages",
            prepareService.prepareMessagesForUser(
                    messages,
                    request.isSecure(),
                    tmpl.getCurrentUser(),
                    tmpl.getProf(),
                    false
            )
    );

    List<TopicListDto.DeletedTopic> deleted = topicListService.getDeletedTopics(sectionId, !tmpl.isModeratorSession());

    modelAndView.addObject("deletedTopics", deleted);
    modelAndView.addObject("sections", sectionService.getSectionList());

    return modelAndView;
View Full Code Here

    HttpServletRequest request,
    @Valid @ModelAttribute("form") RegisterRequest form,
    Errors errors
  ) throws Exception {
    HttpSession session = request.getSession();
    Template tmpl = Template.getTemplate(request);

    if (!errors.hasErrors()) {
      captcha.checkCaptcha(request, errors);

      if (session.getAttribute("register-visited") == null) {
        logger.info("Flood protection (not visited register.jsp) " + request.getRemoteAddr());
        errors.reject(null, "Временная ошибка, попробуйте еще раз");
      }

      ipBlockDao.checkBlockIP(request.getRemoteAddr(), errors, tmpl.getCurrentUser());

      if (userDao.isUserExists(form.getNick())) {
        errors.rejectValue("nick", null, "пользователь " + form.getNick() + " уже существует");
      }
View Full Code Here

  @RequestMapping(value = "/activate.jsp", method = RequestMethod.POST, params = "!action")
  public ModelAndView activate(
    HttpServletRequest request,
    @RequestParam String activation
  ) throws Exception {
    Template tmpl = Template.getTemplate(request);

    if (!tmpl.isSessionAuthorized()) {
      throw new AccessViolationException("Not authorized!");
    }

    User user = tmpl.getCurrentUser();

    String newEmail = userDao.getNewEmail(user);

    if (newEmail == null) {
      throw new AccessViolationException("new_email == null?!");
View Full Code Here

    HttpServletRequest request,
    HttpServletResponse response,
    @RequestParam(value = "filter", defaultValue="all") String filter,
    @RequestParam(value = "offset", defaultValue = "0") int offset
  ) throws Exception {
    Template tmpl = Template.getTemplate(request);
    if (!tmpl.isSessionAuthorized()) {
      throw new AccessViolationException("not authorized");
    }

    Map<String, Object> params = new HashMap<>();
    UserEventFilterEnum eventFilter = UserEventFilterEnum.fromNameOrDefault(filter);
    params.put("filter", eventFilter.getName());

    User currentUser = tmpl.getCurrentUser();
    String nick = currentUser.getNick();

    params.put("nick", nick);
    if (eventFilter != UserEventFilterEnum.ALL) {
      params.put("addition_query", "&filter=" + eventFilter.getName());
    } else {
      params.put("addition_query", "");
    }

    if (offset < 0) {
      offset = 0;
    }

    boolean firstPage = offset == 0;
    int topics = tmpl.getProf().getTopics();

    if (topics > 200) {
      topics = 200;
    }
View Full Code Here

    HttpServletRequest request,
    HttpServletResponse response,
    @RequestParam(value = "nick", required = false) String nick,
    @RequestParam(value = "offset", defaultValue = "0") int offset
  ) throws Exception {
    Template tmpl = Template.getTemplate(request);
    boolean feedRequested = request.getParameterMap().containsKey("output");

    if (nick == null) {
      if (tmpl.isSessionAuthorized()) {
        return new ModelAndView(new RedirectView("/notifications"));
      }
      throw new AccessViolationException("not authorized");
    } else {
      User.checkNick(nick);
      if (!tmpl.isSessionAuthorized() && !feedRequested) {
        throw new AccessViolationException("not authorized");
      }
      if (tmpl.isSessionAuthorized() && nick.equals(tmpl.getCurrentUser().getNick()) && !feedRequested) {
        return new ModelAndView(new RedirectView("/notifications"));
      }
      if (!feedRequested && !tmpl.isModeratorSession()) {
        throw new AccessViolationException("нельзя смотреть чужие уведомления");
      }
    }

    Map<String, Object> params = new HashMap<>();
    params.put("nick", nick);

    if (offset < 0) {
      offset = 0;
    }

    boolean firstPage = offset == 0;
    int topics = tmpl.getProf().getTopics();
    if (feedRequested) {
      topics = 50;
    }

    if (topics > 200) {
      topics = 200;
    }

    params.put("firstPage", firstPage);
    params.put("topics", topics);
    params.put("offset", offset);

    /* define timestamps for caching */
    long time = System.currentTimeMillis();
    int delay = firstPage ? 90 : 60 * 60;
    response.setDateHeader("Expires", time + 1000 * delay);

    User user = userDao.getUser(nick);

    boolean showPrivate = tmpl.isModeratorSession();

    User currentUser = tmpl.getCurrentUser();
    params.put("currentUser", currentUser);

    if (currentUser != null && currentUser.getId() == user.getId()) {
      showPrivate = true;
      params.put("unreadCount", user.getUnreadEvents());
View Full Code Here

    int page,
    String filter,
    String groupName,
    int msgid) throws Exception {
    Topic topic = messageDao.getById(msgid);
    Template tmpl = Template.getTemplate(request);

    Map<String, Object> params = new HashMap<>();

    List<TagRef> tags = topicTagService.getTagRefs(topic);

    MessageText messageText = msgbaseDao.getMessageText(topic.getId());
    String plainText = lorCodeService.extractPlainText(messageText);

    Future<List<List<MoreLikeThisTopic>>> moreLikeThis = moreLikeThisService.search(topic, tags, plainText);

    PreparedTopic preparedMessage = messagePrepareService.prepareTopic(
            topic,
            tags,
            request.isSecure(),
            tmpl.getCurrentUser(),
            messageText
    );

    Group group = preparedMessage.getGroup();

    if (!group.getUrlName().equals(groupName) || group.getSectionId() != section.getId()) {
      return new ModelAndView(new RedirectView(topic.getLink()));
    }

    boolean showDeleted = request.getParameter("deleted") != null;
    if (showDeleted) {
      page = -1;
    }

    if (!tmpl.isModeratorSession()) {
      if (showDeleted && !"POST".equals(request.getMethod())) {
        return new ModelAndView(new RedirectView(topic.getLink()));
      }
    }

    if (page == -1 && !showDeleted) {
      return new ModelAndView(new RedirectView(topic.getLink()));
    }

    int pages = topic.getPageCount(tmpl.getProf().getMessages());

    if (page >= pages && (page > 0 || pages > 0)) {
      if (pages==0) {
        return new ModelAndView(new RedirectView(topic.getLink()));
      } else {
        return new ModelAndView(new RedirectView(topic.getLinkPage(pages - 1)));
      }
    }

    if (showDeleted) {
      if (!tmpl.isSessionAuthorized()) {
        throw new BadInputException("Вы уже вышли из системы");
      }
    }

    params.put("showDeleted", showDeleted);

    User currentUser = AuthUtil.getCurrentUser();

    permissionService.checkView(group, topic, currentUser, showDeleted);

    params.put("message", topic);
    params.put("preparedMessage", preparedMessage);

    if (topic.isExpired()) {
      response.setDateHeader("Expires", System.currentTimeMillis() + 30 * 24 * 60 * 60 * 1000L);
    }

    CommentList comments = commentService.getCommentList(topic, showDeleted);

    if (messageText.isLorcode()) {
      params.put("ogDescription", lorCodeService.trimPlainText(plainText, 250, true));
    }

    params.put("page", page);
    params.put("group", group);
    params.put("showAdsense", !tmpl.isSessionAuthorized() || !tmpl.getProf().isHideAdsense());

    if (!tmpl.isSessionAuthorized()) { // because users have IgnoreList and memories
      String etag = getEtag(topic);
      response.setHeader("Etag", etag);

      if (request.getHeader("If-None-Match") != null) {
        if (etag.equals(request.getHeader("If-None-Match"))) {
          response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
          return null;
        }
      } else if (checkLastModified(webRequest, topic)) {
        return null;
      }
    }

    params.put("messageMenu", messagePrepareService.getTopicMenu(
            preparedMessage,
            currentUser,
            request.isSecure(),
            tmpl.getProf(),
            true
    ));

    Set<Integer> ignoreList;

    if (currentUser != null) {
      ignoreList = ignoreListDao.get(currentUser);
    } else {
      ignoreList = ImmutableSet.of();
    }

    int defaultFilterMode = getDefaultFilter(tmpl.getProf(), ignoreList.isEmpty());
    int filterMode;

    if (filter != null) {
      filterMode = CommentFilter.parseFilterChain(filter);

      if (!ignoreList.isEmpty() && filterMode == CommentFilter.FILTER_ANONYMOUS) {
        filterMode += CommentFilter.FILTER_IGNORED;
      }
    } else {
      filterMode = defaultFilterMode;
    }

    params.put("filterMode", CommentFilter.toString(filterMode));
    params.put("defaultFilterMode", CommentFilter.toString(defaultFilterMode));

    loadTopicScroller(params, topic, currentUser, !ignoreList.isEmpty());

    Set<Integer> hideSet = commentService.makeHideSet(comments, filterMode, ignoreList);

    CommentFilter cv = new CommentFilter(comments);

    boolean reverse = tmpl.getProf().isShowNewFirst();

    List<Comment> commentsFiltred = cv.getCommentsForPage(reverse, page, tmpl.getProf().getMessages(), hideSet);
    List<Comment> commentsFull = cv.getCommentsForPage(reverse, page, tmpl.getProf().getMessages(), ImmutableSet.<Integer>of());

    params.put("unfilteredCount", commentsFull.size());

    List<PreparedComment> commentsPrepared = prepareService.prepareCommentList(
            comments,
            commentsFiltred,
            request.isSecure(),
            tmpl,
            topic
    );

    params.put("commentsPrepared", commentsPrepared);

    IPBlockInfo ipBlockInfo = ipBlockDao.getBlockInfo(request.getRemoteAddr());
    params.put("ipBlockInfo", ipBlockInfo);

    if (pages>1 && !showDeleted) {
      params.put("pages", buildPages(topic, tmpl.getProf().getMessages(), filterMode, defaultFilterMode, page));
    }

    if (moreLikeThis!=null) {
      params.put("moreLikeThis", moreLikeThisService.resultsOrNothing(moreLikeThis));
    }
View Full Code Here

    HttpServletResponse response,
    Integer year,
    Integer month
  ) throws Exception {
    Map<String, Object> params = new HashMap<>();
    Template tmpl = Template.getTemplate(request);

    boolean showDeleted = request.getParameter("deleted") != null;
    params.put("showDeleted", showDeleted);

    Section section = sectionService.getSection(Section.SECTION_FORUM);
    params.put("groupList", groupDao.getGroups(section));

    Group group = groupDao.getGroup(section, groupName);

    if (showDeleted && !"POST".equals(request.getMethod())) {
      return new ModelAndView(new RedirectView(group.getUrl()));
    }

    if (showDeleted && !tmpl.isSessionAuthorized()) {
      throw new AccessViolationException("Вы не авторизованы");
    }

    boolean firstPage;

    if (offset != 0) {
      firstPage = false;

      if (offset < 0) {
        throw new ServletParameterBadValueException("offset", "offset не может быть отрицательным");
      }

      if (year == null && offset>MAX_OFFSET) {
        return new ModelAndView(new RedirectView(group.getUrl()+"archive"));
      }
    } else {
      firstPage = true;
    }

    params.put("firstPage", firstPage);
    params.put("offset", offset);
    params.put("prevPage", offset - tmpl.getProf().getTopics());
    params.put("nextPage", offset + tmpl.getProf().getTopics());
    params.put("lastmod", lastmod);

    boolean showIgnored = false;
    if (request.getParameter("showignored") != null) {
      showIgnored = "t".equals(request.getParameter("showignored"));
    }

    params.put("showIgnored", showIgnored);

    params.put("group", group);

    if(group.getImage() != null) {
      try {
        params.put("groupImagePath", '/' + "tango" + group.getImage());
        ImageInfo info = new ImageInfo(siteConfig.getHTMLPathPrefix() + "tango" + group.getImage());
        params.put("groupImageInfo", info);
      } catch (BadImageException ex) {
        params.put("groupImagePath", null);
        params.put("groupImageInfo", null);
      }
    } else {
      params.put("groupImagePath", null);
      params.put("groupImageInfo", null);
    }

    params.put("section", section);

    params.put("groupInfo", prepareService.prepareGroupInfo(group, request.isSecure()));

    if (year!=null) {
      if (year<1990 || year > 3000) {
        throw new ServletParameterBadValueException("year", "указан некорректный год");
      }

      if (month<1 || month > 12) {
        throw new ServletParameterBadValueException("month", "указан некорректный месяц");
      }

      params.put("year", year);
      params.put("month", month);
      params.put("url", group.getUrl()+year+ '/' +month+ '/');
    } else {
      params.put("url", group.getUrl());
    }

    List<TopicsListItem> mainTopics = getTopics(
            group,
            tmpl.getProf().getMessages(),
            lastmod,
            year,
            month,
            tmpl.getProf().getTopics(),
            offset,
            showDeleted,
            showIgnored,
            tmpl.getCurrentUser()
    );

    if (year==null && offset==0 && !lastmod) {
      List<TopicsListItem> stickyTopics = getStickyTopics(group, tmpl.getProf().getMessages());

      params.put("topicsList",  Lists.newArrayList(Iterables.concat(stickyTopics, mainTopics)));
    } else {
      params.put("topicsList", mainTopics);
    }

    if (year != null) {
      params.put("hasNext", offset + tmpl.getProf().getTopics() < archiveDao.getArchiveCount(group.getId(), year, month));
    } else {
      params.put("hasNext", offset<MAX_OFFSET && mainTopics.size()==tmpl.getProf().getTopics());
    }

    params.put("addable", groupPermissionService.isTopicPostingAllowed(group, tmpl.getCurrentUser()));

    response.setDateHeader("Expires", System.currentTimeMillis() + 90 * 1000);

    return new ModelAndView("group", params);
  }
View Full Code Here

TOP

Related Classes of ru.org.linux.site.Template

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.