add config for banned users and post prevention

graphs-n-shit
lza_menace 4 years ago
parent 2d4b503f36
commit e4e0ab53ca

@ -19,3 +19,4 @@ PRAW_USERNAME = 'xxxxxxxx'
PRAW_PASSWORD = 'xxxxxxxx' PRAW_PASSWORD = 'xxxxxxxx'
SERVER_NAME = 'localhost' SERVER_NAME = 'localhost'
DISCORD_URL = 'xxxxxxx' DISCORD_URL = 'xxxxxxx'
BANNED_USERS = {'username': 'reason for the ban'}

@ -4,6 +4,7 @@ from flask import send_from_directory, redirect, url_for, current_app
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
from secrets import token_urlsafe from secrets import token_urlsafe
from suchwow import wownero from suchwow import wownero
from suchwow import config
from suchwow.models import Post, Comment from suchwow.models import Post, Comment
from suchwow.utils.decorators import login_required, profile_required from suchwow.utils.decorators import login_required, profile_required
from suchwow.utils.helpers import allowed_file from suchwow.utils.helpers import allowed_file
@ -54,6 +55,11 @@ def read(id):
@profile_required @profile_required
def create(): def create():
if request.method == "POST": if request.method == "POST":
submitter = session["auth"]["preferred_username"]
if submitter in config.BANNED_USERS:
reason = config.BANNED_USERS[submitter]
flash(f"You can't post for now: {reason}")
return redirect("/")
post_title = request.form.get("title") post_title = request.form.get("title")
# check if the post request has the file part # check if the post request has the file part
if "file" not in request.files: if "file" not in request.files:
@ -84,7 +90,7 @@ def create():
post = Post( post = Post(
title=post_title, title=post_title,
text=request.form.get("text", ""), text=request.form.get("text", ""),
submitter=session["auth"]["preferred_username"], submitter=submitter,
image_name=filename, image_name=filename,
account_index=account_index, account_index=account_index,
address_index=0 address_index=0