예제 #1
0
def test_category_get_all(forum, user):
    category = forum.category

    with current_app.test_request_context():
        # Test with logged in user
        login_user(user)
        assert current_user.is_authenticated
        categories = Category.get_all(current_user)

        # All categories are stored in a list
        assert isinstance(categories, list)
        # The forums for a category are also stored in a list
        assert isinstance(categories[0][1], list)

        assert categories == [(category, [(forum, None)])]

        # Test with logged out user
        logout_user()
        assert not current_user.is_authenticated
        categories = Category.get_all(current_user)

        # All categories are stored in a list
        assert isinstance(categories, list)
        # The forums for a category are also stored in a list
        assert isinstance(categories[0][1], list)

        assert categories == [(category, [(forum, None)])]
예제 #2
0
def test_category_get_all(forum, user):
    category = forum.category

    with current_app.test_request_context():
        # Test with logged in user
        login_user(user)
        assert current_user.is_authenticated
        categories = Category.get_all(current_user)

        # All categories are stored in a list
        assert isinstance(categories, list)
        # The forums for a category are also stored in a list
        assert isinstance(categories[0][1], list)

        assert categories == [(category, [(forum, None)])]

        # Test with logged out user
        logout_user()
        assert not current_user.is_authenticated
        categories = Category.get_all(current_user)

        # All categories are stored in a list
        assert isinstance(categories, list)
        # The forums for a category are also stored in a list
        assert isinstance(categories[0][1], list)

        assert categories == [(category, [(forum, None)])]
예제 #3
0
파일: views.py 프로젝트: centime/xss-paper
def index(payload=''):
    categories = Category.get_all(user=current_user)

    # Fetch a few stats about the forum
    user_count = User.query.count()
    topic_count = Topic.query.count()
    post_count = Post.query.count()
    newest_user = User.query.order_by(User.id.desc()).first()

    # Check if we use redis or not
    if not current_app.config["REDIS_ENABLED"]:
        online_users = User.query.filter(User.lastseen >= time_diff()).count()

        # Because we do not have server side sessions, we cannot check if there
        # are online guests
        online_guests = None
    else:
        online_users = len(get_online_users())
        online_guests = len(get_online_users(guest=True))

    return render_template("forum/index.html",
                           categories=categories,
                           user_count=user_count,
                           topic_count=topic_count,
                           post_count=post_count,
                           newest_user=newest_user,
                           online_users=online_users,
                           online_guests=online_guests,
                           # XSS added for educational purpose
                           payload=payload)
예제 #4
0
파일: views.py 프로젝트: Doster-d/OnyxForum
    def get(self):
        categories = Category.get_all(user=real(current_user))

        # Fetch a few stats about the forum
        user_count = User.query.count()
        topic_count = Topic.query.count()
        post_count = Post.query.count()
        newest_user = User.query.order_by(User.id.desc()).first()

        # Check if we use redis or not
        if not current_app.config["REDIS_ENABLED"]:
            online_users = User.query.filter(
                User.lastseen >= time_diff()).count()

            # Because we do not have server side sessions,
            # we cannot check if there are online guests
            online_guests = None
        else:
            online_users = len(get_online_users())
            online_guests = len(get_online_users(guest=True))

        return render_template("forum/index.html",
                               categories=categories,
                               user_count=user_count,
                               topic_count=topic_count,
                               post_count=post_count,
                               newest_user=newest_user,
                               online_users=online_users,
                               online_guests=online_guests)
예제 #5
0
    def _get_choices(self):
        'Get list of forums to choose from'

        return [
            (category.title, [(forum.id, forum.title) for forum, x in forums])
            for category, forums in Category.get_all(user=real(current_user))
        ]
예제 #6
0
    def get(self):
        categories = Category.get_all(user=real(current_user))

        # Fetch a few stats about the forum
        user_count = User.query.count()
        topic_count = Topic.query.count()
        post_count = Post.query.count()
        newest_user = User.query.order_by(User.id.desc()).first()
        print('newest', newest_user)

        # Check if we use redis or not
        if not current_app.config['REDIS_ENABLED']:
            online_users = len(User.get_active()) + random.randint(-3, 3)
            # Because we do not have server side sessions, we cannot check if there
            # are online guests
            online_guests = None
        else:

            online_users = len(User.get_active()) + random.randint(-3, 3)
            online_guests = len(get_online_users(guest=True))

        return render_template('forum/index.html',
                               categories=categories,
                               user_count=user_count,
                               topic_count=topic_count,
                               post_count=post_count,
                               newest_user=newest_user,
                               online_users=online_users,
                               online_guests=online_guests)
예제 #7
0
def rss(key):
    'Personalized RSS feed'

    settings = SubscriptionSettings.query.filter(
        SubscriptionSettings.rss_key == key).first_or_404()
    user_id = settings.user_id
    user = User.query.get(user_id)
    categories = Category.get_all(user=real(user))
    allowed_forums = []

    for category, forums in categories:
        for forum, forumsread in forums:
            allowed_forums.append(forum.id)

    forums = [r.forum_id for r in Subscription.query.filter(
              (Subscription.user_id == user_id) &
              Subscription.forum_id.in_(allowed_forums)).all()]
    tracked = []

    if settings.tracked_topics:
        tracked = [r.topic_id for r in db.session.query(topictracker).filter(
                   text('topictracker.user_id == ' + str(user_id))).all()]

    url_root = (request.url_root[:-1] if request.url_root[-1] == '/'
                else request.url_root)
    feed = AtomFeed(_('Recent posts'), feed_url=request.url, url=url_root)
    posts = (Post.query.filter(Post.user_id != user_id)
             .join(Topic, Post.topic)
             .filter(Topic.id.in_(tracked) | Topic.forum_id.in_(forums))
             .order_by(Post.date_created.desc())
             .limit(20)
             .all())

    for post in posts:
        feed.add(_('{title} by {user}').format(title=post.topic.title,
                                               user=post.username),
                 markdown.render(post.content), content_type='html',
                 author=post.username, url=url_root + post.url,
                 updated=post.date_modified or post.date_created,
                 published=post.date_created)

    return feed.get_response()