Fix captcha and generify community invite

Signed-off-by: Etzelia <etzelia@hotmail.com>
captcha
Etzelia 2020-06-06 11:37:04 -05:00
parent faa342933e
commit 1489b5aa7d
No known key found for this signature in database
GPG Key ID: 708511AE7ABC5314
3 changed files with 10 additions and 9 deletions

15
external/views.py vendored
View File

@ -1,5 +1,5 @@
from django.views.generic import View from django.views.generic import View
from django.shortcuts import render, reverse, redirect from django.shortcuts import render
from django.conf import settings from django.conf import settings
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
@ -8,12 +8,13 @@ import minecraft_manager.api.api as mcm_api
import minecraft_manager.utils as mcm_utils import minecraft_manager.utils as mcm_utils
import minecraft_manager.external.stats as mcm_stats import minecraft_manager.external.stats as mcm_stats
from minecraft_manager.models import Player from minecraft_manager.models import Player
import random, yaml, os, json, datetime, pytz import random, yaml, os
def config(): def config():
data = {} data = {}
data['discord_invite'] = getattr(settings, "DISCORD_INVITE", "#") data['invite_link'] = getattr(settings, "INVITE_LINK", "#")
data['invite_label'] = getattr(settings, "INVITE_LABEL", "community")
dynmap_url = getattr(settings, "DYNMAP_URL", "") dynmap_url = getattr(settings, "DYNMAP_URL", "")
data['dynmap_url'] = dynmap_url data['dynmap_url'] = dynmap_url
@ -60,7 +61,7 @@ class Apply(View):
form = ApplicationForm() form = ApplicationForm()
return render(request, 'minecraft_manager/external/apply.html', return render(request, 'minecraft_manager/external/apply.html',
{'form': form.as_p(), 'rules': rules(), 'valid': False, 'map': config(), {'form': form.as_p(), 'rules': rules(), 'valid': False, 'map': config(),
'captcha': hasattr(settings, "CAPTCHA_SECRET")}) 'captcha': getattr(settings, "CAPTCHA_SITE", "")})
def post(self, request): def post(self, request):
form = ApplicationForm(request.POST) form = ApplicationForm(request.POST)
@ -79,7 +80,7 @@ class Apply(View):
form.add_error(None, "That username is not a premium Minecraft account") form.add_error(None, "That username is not a premium Minecraft account")
return render(request, 'minecraft_manager/external/apply.html', 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': rules(), 'valid': valid and valid_username and captcha.success, 'map': config(),
'captcha': hasattr(settings, "CAPTCHA_SECRET")}) 'captcha': getattr(settings, "CAPTCHA_SITE", "")})
@method_decorator(csrf_exempt, name='dispatch') @method_decorator(csrf_exempt, name='dispatch')
@ -89,7 +90,7 @@ class Ticket(View):
form = TicketForm() form = TicketForm()
return render(request, 'minecraft_manager/external/ticket.html', return render(request, 'minecraft_manager/external/ticket.html',
{'form': form.as_p(), 'valid': False, 'map': config(), {'form': form.as_p(), 'valid': False, 'map': config(),
'captcha': hasattr(settings, "CAPTCHA_SECRET")}) 'captcha': getattr(settings, "CAPTCHA_SITE", "")})
def post(self, request): def post(self, request):
post = request.POST.copy() post = request.POST.copy()
@ -120,7 +121,7 @@ class Ticket(View):
form.data['player'] = username form.data['player'] = username
return render(request, 'minecraft_manager/external/ticket.html', return render(request, 'minecraft_manager/external/ticket.html',
{'form': form.as_p(), 'valid': valid and captcha.success, 'map': config(), {'form': form.as_p(), 'valid': valid and captcha.success, 'map': config(),
'captcha': hasattr(settings, "CAPTCHA_SECRET")}) 'captcha': getattr(settings, "CAPTCHA_SITE", "")})
@method_decorator(csrf_exempt, name='dispatch') @method_decorator(csrf_exempt, name='dispatch')

View File

@ -17,7 +17,7 @@
<br/> <br/>
We will get back to you soon. We will get back to you soon.
<br/> <br/>
Consider joining our <a href="https://discord.gg/{{ map.discord_invite }}">Discord</a></h2> Consider joining our <a href="{{ map.invite_link }}">{{ map.invite_label }}</a></h2>
{% endblock %} {% endblock %}
{% endif %} {% endif %}

View File

@ -21,7 +21,7 @@
{% else %} {% else %}
<form method="{% block method %}POST{% endblock %}"> <form method="{% block method %}POST{% endblock %}">
{% block form %}{{ form }}{% endblock %}<br/><br/> {% block form %}{{ form }}{% endblock %}<br/><br/>
{% if captcha %}<div class="g-recaptcha" data-sitekey="6LeLcGEUAAAAAMMpHR-7VL6Q3nNV5v03S5sq1Ddz"></div>{% endif %} {% if captcha %}<div class="g-recaptcha" data-sitekey="{{ captcha }}"></div>{% endif %}
<button type="submit">{% block submit %}Submit{% endblock %}</button> <button type="submit">{% block submit %}Submit{% endblock %}</button>
</form> </form>
{% endif %} {% endif %}