2016-03-21 09:35:21 -07:00
|
|
|
import requests
|
|
|
|
|
|
|
|
from django.conf import settings
|
2016-03-21 09:38:46 -07:00
|
|
|
from django.http import HttpResponse
|
2016-05-10 08:35:51 -07:00
|
|
|
from registration.backends.default.views import ActivationView, RegistrationView
|
2013-03-24 15:15:49 -07:00
|
|
|
from utils.forms import SniptRegistrationForm
|
|
|
|
|
2015-07-24 18:28:31 -07:00
|
|
|
|
2013-03-24 15:15:49 -07:00
|
|
|
class SniptRegistrationView(RegistrationView):
|
|
|
|
"""
|
|
|
|
Custom registration view that uses our custom form.
|
|
|
|
"""
|
|
|
|
form_class = SniptRegistrationForm
|
2015-11-05 18:10:25 -08:00
|
|
|
|
2016-03-21 09:35:21 -07:00
|
|
|
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']:
|
2016-03-21 09:38:46 -07:00
|
|
|
return HttpResponse('You failed the robot check. Go back and try again.')
|
2016-03-21 09:35:21 -07:00
|
|
|
|
|
|
|
return super(RegistrationView, self).dispatch(request, *args, **kwargs)
|
|
|
|
|
2015-11-05 18:10:25 -08:00
|
|
|
def get_success_url(self, request, user):
|
|
|
|
return '/{}/'.format(user.username)
|