Exemplo n.º 1
0
def route_admin_news_compose_post():
    title = request.form.get('title', '')
    content = request.form.get('content', '')
    thread_content = request.form.get('threadContent', '')
    poster_id = request.form.get('poster', 0)
    board_id = request.form.get('board', 0)
    error = False

    if len(title) == 0:
        flash('The news title cannot be empty.', 'error')
        error = True

    if len(content) == 0:
        flash('The news content cannot be empty.', 'error')
        error = True

    if len(thread_content) == 0:
        flash('The thread content cannot be empty.', 'error')
        error = True

    if not error:
        content = content.strip()
        content = ' '.join(content.split())

        timestamp = int(time())

        thread = ForumThread()
        thread.subject = title
        thread.timestamp = timestamp
        thread.board_id = board_id
        thread.locked = 0
        thread.pinned = 0
        thread.lastpost = timestamp
        thread.author_id = poster_id
        thread.content = thread_content

        db.session().add(thread)
        db.session().commit()

        news = News()
        news.timestamp = timestamp
        news.header = title
        news.content = content
        news.author_id = poster_id
        news.thread_id = thread.id

        db.session().add(news)
        db.session().commit()

        author = Player.query.filter(Player.id == poster_id).first()
        author.postcount = author.postcount + 1
        db.session().commit()

        flash('The news has been posted successfully.', 'success')

    return redirect(url_for('route_admin_news_compose'))
Exemplo n.º 2
0
def route_admin_news_compose_post():
	title = request.form.get('title', '')
	content = request.form.get('content', '')
	thread_content = request.form.get('threadContent', '')
	poster_id = request.form.get('poster', 0)
	board_id = request.form.get('board', 0)
	error = False

	if len(title) == 0:
		flash('The news title cannot be empty.', 'error')
		error = True

	if len(content) == 0:
		flash('The news content cannot be empty.', 'error')
		error = True

	if len(thread_content) == 0:
		flash('The thread content cannot be empty.', 'error')
		error = True

	if not error:
		content = content.strip()
		content = ' '.join(content.split())

		timestamp = int(time())

		thread = ForumThread()
		thread.subject = title
		thread.timestamp = timestamp
		thread.board_id = board_id
		thread.locked = 0
		thread.pinned = 0
		thread.lastpost = timestamp
		thread.author_id = poster_id
		thread.content = thread_content

		db.session().add(thread)
		db.session().commit()

		news = News()
		news.timestamp = timestamp
		news.header = title
		news.content = content
		news.author_id = poster_id
		news.thread_id = thread.id

		db.session().add(news)
		db.session().commit()

		author = Player.query.filter(Player.id == poster_id).first()
		author.postcount = author.postcount + 1
		db.session().commit()

		flash('The news has been posted successfully.', 'success')

	return redirect(url_for('route_admin_news_compose'))
Exemplo n.º 3
0
def route_forum_board_post(id):
	board = ForumBoard.query.filter(ForumBoard.id == id).first()
	if not board:
		flash('The board you are trying to create a thread on does not exist.', 'error')
		return redirect(url_for('route_forum'))

	subject = request.form.get('subject', '', type=str)
	character = request.form.get('character', 0, type=int)
	content = request.form.get('content', '', type=str)
	error = False

	user = current_user()
	found = False
	for player in user.players:
		if player.id == character:
			found = True
			break

	if not found:
		flash('You cannot post from a character that does not belong to you.', 'error')
		error = True

	timestamp = int(time())
	if session.get('access', 0) != ADMIN_ACCOUNT_TYPE:
		if board.locked:
			flash('You cannot create a thread in a locked board.', 'error')
			error = True

		if user.lastpost + POST_COOLDOWN > timestamp:
			flash('You must wait {} seconds before posting again.'.format(POST_COOLDOWN), 'error')
			error = True

		if user.creation + (60 * 60 * 24 * FORUM_ACCOUNT_AGE_REQUIREMENT) > timestamp:
			flash('Your account must be at least {} days old to post on the forum.'.format(FORUM_ACCOUNT_AGE_REQUIREMENT), 'error')
			error = True

		if player.level < FORUM_LEVEL_REQUIREMENT:
			flash('Your character must be at least level {} to post on the forum.'.format(FORUM_LEVEL_REQUIREMENT), 'error')
			error = True

		if len(content) < 15:
			flash('Your thread content must be at least 15 characters long.', 'error')
			error = True

	if len(subject) < 5:
		flash('Your thread subject must be at least 5 characters long', 'error')
		error = True

	if not error:
		if len(content) > FORUM_CHARACTER_LIMIT:
			content = content[:FORUM_CHARACTER_LIMIT]

		content = content.strip()
		content = '\n'.join(content.split('\n'))

		content = escape(content)
		content = str(content).replace('\n', '<br>')

		thread = ForumThread()
		thread.subject = subject
		thread.timestamp = timestamp
		thread.board_id = id
		thread.locked = 0
		thread.pinned = 0
		thread.lastpost = timestamp
		thread.author_id = character
		thread.content = content
		thread.deleted = 0

		user.lastpost = timestamp
		player.postcount = player.postcount + 1

		db.session().add(thread)
		db.session().commit()

		return redirect(url_for('route_forum_thread', thread=thread.id, page=1))

	return redirect(url_for('route_forum_board', board=id, page=1))
Exemplo n.º 4
0
def route_forum_board_post(id):
    board = ForumBoard.query.filter(ForumBoard.id == id).first()
    if not board:
        flash('The board you are trying to create a thread on does not exist.',
              'error')
        return redirect(url_for('route_forum'))

    subject = request.form.get('subject', '', type=str)
    character = request.form.get('character', 0, type=int)
    content = request.form.get('content', '', type=str)
    error = False

    user = current_user()
    found = False
    for player in user.players:
        if player.id == character:
            found = True
            break

    if not found:
        flash('You cannot post from a character that does not belong to you.',
              'error')
        error = True

    timestamp = int(time())
    if session.get('access', 0) != ADMIN_ACCOUNT_TYPE:
        if board.locked:
            flash('You cannot create a thread in a locked board.', 'error')
            error = True

        if user.lastpost + POST_COOLDOWN > timestamp:
            flash(
                'You must wait {} seconds before posting again.'.format(
                    POST_COOLDOWN), 'error')
            error = True

        if user.creation + (60 * 60 * 24 *
                            FORUM_ACCOUNT_AGE_REQUIREMENT) > timestamp:
            flash(
                'Your account must be at least {} days old to post on the forum.'
                .format(FORUM_ACCOUNT_AGE_REQUIREMENT), 'error')
            error = True

        if player.level < FORUM_LEVEL_REQUIREMENT:
            flash(
                'Your character must be at least level {} to post on the forum.'
                .format(FORUM_LEVEL_REQUIREMENT), 'error')
            error = True

        if len(content) < 15:
            flash('Your thread content must be at least 15 characters long.',
                  'error')
            error = True

    if len(subject) < 5:
        flash('Your thread subject must be at least 5 characters long',
              'error')
        error = True

    if not error:
        if len(content) > FORUM_CHARACTER_LIMIT:
            content = content[:FORUM_CHARACTER_LIMIT]

        content = content.strip()
        content = '\n'.join(content.split('\n'))

        content = escape(content)
        content = str(content).replace('\n', '<br>')

        thread = ForumThread()
        thread.subject = subject
        thread.timestamp = timestamp
        thread.board_id = id
        thread.locked = 0
        thread.pinned = 0
        thread.lastpost = timestamp
        thread.author_id = character
        thread.content = content
        thread.deleted = 0

        user.lastpost = timestamp
        player.postcount = player.postcount + 1

        db.session().add(thread)
        db.session().commit()

        return redirect(url_for('route_forum_thread', thread=thread.id,
                                page=1))

    return redirect(url_for('route_forum_board', board=id, page=1))