From 725ac7f40ff9fb41d76e05fb8cb9b224d20c04d9 Mon Sep 17 00:00:00 2001 From: Etzelia Date: Sat, 6 Jun 2020 12:05:57 -0500 Subject: [PATCH] Add validation for final question and some minor CSS Signed-off-by: Etzelia --- external/views.py | 16 ++++++++++++---- static/minecraft_manager/css/external.css | 5 +++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/external/views.py b/external/views.py index 7f9385e..5d40f82 100644 --- a/external/views.py +++ b/external/views.py @@ -51,7 +51,11 @@ def rules(): if cfg['rules']['application']['validate']: data.append("The answer to the final question is \"{}\"".format(cfg['rules']['application']['answer'])) - return data + return { + "rules": data, + "validate": cfg['rules']['application']['validate'], + "answer": cfg['rules']['application']['answer'] + } @method_decorator(csrf_exempt, name='dispatch') @@ -60,7 +64,7 @@ class Apply(View): def get(self, request): form = ApplicationForm() return render(request, 'minecraft_manager/external/apply.html', - {'form': form.as_p(), 'rules': rules(), 'valid': False, 'map': config(), + {'form': form.as_p(), 'rules': rules()["rules"], 'valid': False, 'map': config(), 'captcha': getattr(settings, "CAPTCHA_SITE", "")}) def post(self, request): @@ -68,7 +72,9 @@ class Apply(View): valid_username = mcm_utils.validate_username(form.data['username']) captcha = mcm_utils.Captcha(request.POST) valid = form.is_valid() - if valid and valid_username and captcha.success: + r = rules() + valid_answer = not r["validate"] or r["answer"] == form.data['read_rules'] + if valid and valid_username and valid_answer and captcha.success: app = form.save() msg = mcm_utils.build_application(app) mcm_api.discord_mcm(message='New Application!', embed=msg) @@ -78,8 +84,10 @@ class Apply(View): form.add_error(None, error) if not valid_username: form.add_error(None, "That username is not a premium Minecraft account") + if not valid_answer: + form.add_error(None, "Please read the rules again") return render(request, 'minecraft_manager/external/apply.html', - {'form': form.as_p(), 'rules': rules(), 'valid': valid and valid_username and captcha.success, 'map': config(), + {'form': form.as_p(), 'rules': r["rules"], 'valid': valid and valid_username and valid_answer and captcha.success, 'map': config(), 'captcha': getattr(settings, "CAPTCHA_SITE", "")}) diff --git a/static/minecraft_manager/css/external.css b/static/minecraft_manager/css/external.css index 0b2adc0..8f3436b 100644 --- a/static/minecraft_manager/css/external.css +++ b/static/minecraft_manager/css/external.css @@ -67,4 +67,9 @@ .rule { margin-bottom: .5em; +} + +.errorlist { + color: #D8000C; + background-color: #FFD2D2; } \ No newline at end of file