Make users recaptcha on signup.
parent
4a49a60479
commit
e4d56bf861
|
@ -76,6 +76,7 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div style="margin-left: 180px;" class="g-recaptcha" data-sitekey="6LerYA0TAAAAAFJaMf7JMnlQR2wzqd_3dMRvLd-4"></div>
|
||||
<div class="form-actions group">
|
||||
<a class="btn pull-right" href="/login/">Log in</a>
|
||||
<button class="btn btn-primary" type="submit">Sign up</button>
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
import requests
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import HttpResponseBadRequest
|
||||
from registration.backends.default.views import RegistrationView
|
||||
from utils.forms import SniptRegistrationForm
|
||||
|
||||
|
@ -8,5 +12,21 @@ class SniptRegistrationView(RegistrationView):
|
|||
"""
|
||||
form_class = SniptRegistrationForm
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
|
||||
if request.method == 'POST':
|
||||
payload = {
|
||||
'secret': settings.RECAPTCHA_SECRET,
|
||||
'response': request.POST['g-recaptcha-response'],
|
||||
'remoteip': request.META.get('REMOTE_ADDR')
|
||||
}
|
||||
r = requests.post('https://www.google.com/recaptcha/api/siteverify',
|
||||
data=payload)
|
||||
|
||||
if not r.json()['success']:
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
return super(RegistrationView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_success_url(self, request, user):
|
||||
return '/{}/'.format(user.username)
|
||||
|
|
Loading…
Reference in New Issue