From e4e0ab53ca31bbf8972219408e9e5c46dcc6fccf Mon Sep 17 00:00:00 2001 From: lza_menace Date: Sun, 22 Nov 2020 12:39:21 -0800 Subject: [PATCH] add config for banned users and post prevention --- suchwow/config.example.py | 1 + suchwow/routes/post.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/suchwow/config.example.py b/suchwow/config.example.py index d36fed4..a35c03d 100644 --- a/suchwow/config.example.py +++ b/suchwow/config.example.py @@ -19,3 +19,4 @@ PRAW_USERNAME = 'xxxxxxxx' PRAW_PASSWORD = 'xxxxxxxx' SERVER_NAME = 'localhost' DISCORD_URL = 'xxxxxxx' +BANNED_USERS = {'username': 'reason for the ban'} diff --git a/suchwow/routes/post.py b/suchwow/routes/post.py index 7a387f9..e41ecfa 100644 --- a/suchwow/routes/post.py +++ b/suchwow/routes/post.py @@ -4,6 +4,7 @@ from flask import send_from_directory, redirect, url_for, current_app from werkzeug.utils import secure_filename from secrets import token_urlsafe from suchwow import wownero +from suchwow import config from suchwow.models import Post, Comment from suchwow.utils.decorators import login_required, profile_required from suchwow.utils.helpers import allowed_file @@ -54,6 +55,11 @@ def read(id): @profile_required def create(): 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") # check if the post request has the file part if "file" not in request.files: @@ -84,7 +90,7 @@ def create(): post = Post( title=post_title, text=request.form.get("text", ""), - submitter=session["auth"]["preferred_username"], + submitter=submitter, image_name=filename, account_index=account_index, address_index=0