add signup captcha

master
alice 4 years ago
parent 53f0664f23
commit cacbcdc731

@ -12,4 +12,5 @@ def some_settings(request):
'ADDITIONAL_HTML': settings.ADDITIONAL_HTML, 'ADDITIONAL_HTML': settings.ADDITIONAL_HTML,
'SUPPORT_TEMPLATE': settings.SUPPORT_TEMPLATE, 'SUPPORT_TEMPLATE': settings.SUPPORT_TEMPLATE,
'ADDITIONAL_HEADER_HTML': settings.ADDITIONAL_HEADER_HTML, 'ADDITIONAL_HEADER_HTML': settings.ADDITIONAL_HEADER_HTML,
'HCAPTCHA_SITE_KEY': settings.HCAPTCHA_SITE_KEY,
} }

@ -71,6 +71,13 @@ def signup(request):
form = SignupForm(request.POST) form = SignupForm(request.POST)
grr = request.POST.get('g-recaptcha-response', '')
if captcha_test(grr, request):
request.session['signup_captcha_pass'] = True
elif not request.session.get('signup_captcha_pass'):
messages.error(request, _("Invalid captcha. Please try again"))
return render(request, 'ccvpn/signup.html', dict(form=form))
if not form.is_valid(): if not form.is_valid():
return render(request, 'ccvpn/signup.html', dict(form=form)) return render(request, 'ccvpn/signup.html', dict(form=form))
@ -92,6 +99,9 @@ def signup(request):
user.backend = 'django.contrib.auth.backends.ModelBackend' user.backend = 'django.contrib.auth.backends.ModelBackend'
auth.login(request, user) auth.login(request, user)
# invalidate that captcha
request.session['signup_captcha_pass'] = False
return redirect('account:index') return redirect('account:index')

@ -34,6 +34,11 @@
{% trans 'Used to recover your password and confirm stuff.' %} {% trans 'Used to recover your password and confirm stuff.' %}
</p> </p>
{% if not request.session.signup_captcha_pass %}
<div class="h-captcha" data-sitekey="{{ HCAPTCHA_SITE_KEY }}" data-callback="onCaptcha"></div>
<script src="https://hcaptcha.com/1/api.js" async defer></script>
{% endif %}
<input type="submit" class="pure-button pure-button-primary" value="{% trans 'Sign up' %}" /> <input type="submit" class="pure-button pure-button-primary" value="{% trans 'Sign up' %}" />
</form> </form>
<div class="rightsignup links"> <div class="rightsignup links">

Loading…
Cancel
Save