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))
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))