Add validation for final question and some minor CSS

Signed-off-by: Etzelia <etzelia@hotmail.com>
captcha
Etzelia 2020-06-06 12:05:57 -05:00
parent a31f49c7ce
commit 725ac7f40f
No known key found for this signature in database
GPG Key ID: 708511AE7ABC5314
2 changed files with 17 additions and 4 deletions

16
external/views.py vendored
View File

@ -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", "")})

View File

@ -67,4 +67,9 @@
.rule {
margin-bottom: .5em;
}
.errorlist {
color: #D8000C;
background-color: #FFD2D2;
}