def register(request): html_captcha = captcha.displayhtml(settings.RECAPTCHA_PUB_KEY) if request.method == 'POST': check_captcha = captcha.submit(request.POST['recaptcha_challenge_field'], request.POST['recaptcha_response_field'], settings.RECAPTCHA_PRIVATE_KEY, request.META['REMOTE_ADDR']) form = RegisterForm(request.POST) redirectTo = request.POST.get('redirectTo', '/') if form.is_valid(): if check_captcha.is_valid is False: return render_to_response("register.html", {'form': form, 'redirectTo': redirectTo, 'html_captcha': html_captcha, 'recaptchaError': 'True'}, context_instance=RequestContext(request)) else: form.save() return HttpResponseRedirect("/login/?redirectTo="+redirectTo) else: form = RegisterForm() try: redirectTo = re.search(r'http://[-.\w\d]+/(.+)', request.META['HTTP_REFERER']).group(1) redirectTo = '/'+redirectTo except: redirectTo = '/' return render_to_response("register.html", {'form': form, 'redirectTo': redirectTo, 'html_captcha': html_captcha, }, context_instance=RequestContext(request))
def get_context_data(self, form, **kwargs): context = super(RegisterWizard, self).get_context_data(form, **kwargs) if self.steps.current == '1': html_captcha = captcha.displayhtml(settings.RECAPTCHA_PUB_KEY) context.update({'html_captcha': html_captcha}) return context