def test_remove_captcha_from_forms(self): form1 = FormCaptchaTest.FormWithCaptcha() form2 = forms.Form() form3 = FormCaptchaTest.FormWithCaptcha() remove_captcha_from_forms(form1, form2, form3) for form in [form1, form2, form3]: self.assertFalse(is_captcha_in_form(form))
def contact(request): increment_count = False should_use_captcha = captcha.CAPTCHA_ENABLED anchor = '' if request.method == 'POST': contact_form = ContactForm(request.POST) if not should_use_captcha: remove_captcha_from_forms(contact_form) increment_count = True if contact_form.is_valid(): anchor = "top" email_message = emailMessages.contactEmail( request, contact_form.cleaned_data['name'], contact_form.cleaned_data['telephone'], contact_form.cleaned_data['email'], contact_form.cleaned_data['message'], contact_form.cleaned_data['browser']) send_email(CONTACT_EMAIL, app_settings.CONTACT_FORM_EMAILS, email_message['subject'], email_message['message']) confirmed_email_message = emailMessages.confirmationContactEmailMessage( request, contact_form.cleaned_data['name'], contact_form.cleaned_data['telephone'], contact_form.cleaned_data['email'], contact_form.cleaned_data['message']) send_email(CONTACT_EMAIL, [contact_form.cleaned_data['email']], confirmed_email_message['subject'], confirmed_email_message['message']) messages.success(request, 'Your message was sent successfully.') return render(request, 'portal/help-and-support.html', { 'form': contact_form, 'anchor': anchor }) else: contact_form = ContactForm(request.POST) anchor = "contact" else: contact_form = ContactForm() if not should_use_captcha: remove_captcha_from_forms(contact_form) response = render( request, 'portal/help-and-support.html', { 'form': contact_form, 'anchor': anchor, 'captcha': should_use_captcha, 'settings': app_settings }) response.count = increment_count return response
def render_signup_form(request): invalid_form = False limits = getattr(request, "limits", {"ip": [0]}) captcha_limit = 5 should_use_captcha = (limits["ip"][0] >= captcha_limit) and captcha.CAPTCHA_ENABLED teacher_signup_form = TeacherSignupForm(prefix="teacher_signup") independent_student_signup_form = IndependentStudentSignupForm( prefix="independent_student_signup" ) if request.method == "POST": if "teacher_signup" in request.POST: teacher_signup_form = TeacherSignupForm( request.POST, prefix="teacher_signup" ) if not should_use_captcha: remove_captcha_from_forms(teacher_signup_form) if teacher_signup_form.is_valid(): data = teacher_signup_form.cleaned_data return process_signup_form(request, data) else: independent_student_signup_form = IndependentStudentSignupForm( request.POST, prefix="independent_student_signup" ) if not should_use_captcha: remove_captcha_from_forms(independent_student_signup_form) if independent_student_signup_form.is_valid(): data = independent_student_signup_form.cleaned_data return process_independent_student_signup_form(request, data) res = render( request, "portal/register.html", { "teacher_signup_form": teacher_signup_form, "independent_student_signup_form": independent_student_signup_form, "captcha": should_use_captcha, }, ) res.count = invalid_form return res
def render_signup_form(request): invalid_form = False limits = getattr(request, "limits", {"ip": [0]}) captcha_limit = 5 should_use_captcha = (limits["ip"][0] >= captcha_limit) and captcha.CAPTCHA_ENABLED teacher_signup_form = TeacherSignupForm(prefix="teacher_signup") independent_student_signup_form = IndependentStudentSignupForm( prefix="independent_student_signup") if request.method == "POST": if "teacher_signup" in request.POST: teacher_signup_form = TeacherSignupForm(request.POST, prefix="teacher_signup") if not should_use_captcha: remove_captcha_from_forms(teacher_signup_form) if teacher_signup_form.is_valid(): data = teacher_signup_form.cleaned_data return process_signup_form(request, data) else: independent_student_signup_form = IndependentStudentSignupForm( request.POST, prefix="independent_student_signup") if not should_use_captcha: remove_captcha_from_forms(independent_student_signup_form) if independent_student_signup_form.is_valid(): data = independent_student_signup_form.cleaned_data return process_independent_student_signup_form(request, data) res = render( request, "portal/register.html", { "teacher_signup_form": teacher_signup_form, "independent_student_signup_form": independent_student_signup_form, "captcha": should_use_captcha, }, ) res.count = invalid_form return res
def render_signup_form(request): invalid_form = False limits = getattr(request, 'limits', {'ip': [0]}) captcha_limit = 5 should_use_captcha = (limits['ip'][0] >= captcha_limit) and captcha.CAPTCHA_ENABLED teacher_signup_form = TeacherSignupForm(prefix='teacher_signup') student_signup_form = StudentSignupForm(prefix='student_signup') if request.method == 'POST': if 'teacher_signup' in request.POST: teacher_signup_form = TeacherSignupForm(request.POST, prefix='teacher_signup') if not should_use_captcha: remove_captcha_from_forms(teacher_signup_form) if teacher_signup_form.is_valid(): data = teacher_signup_form.cleaned_data return process_signup_form(request, data) else: student_signup_form = StudentSignupForm(request.POST, prefix='student_signup') if not should_use_captcha: remove_captcha_from_forms(student_signup_form) if student_signup_form.is_valid(): data = student_signup_form.cleaned_data return process_student_signup_form(request, data) res = render( request, 'portal/register.html', { 'teacher_signup_form': teacher_signup_form, 'student_signup_form': student_signup_form, 'captcha': should_use_captcha, }) res.count = invalid_form return res
def render_signup_form(request): invalid_form = False teacher_signup_form = TeacherSignupForm(prefix="teacher_signup") independent_student_signup_form = IndependentStudentSignupForm( prefix="independent_student_signup" ) if request.method == "POST": if "teacher_signup-teacher_email" in request.POST: teacher_signup_form = TeacherSignupForm( request.POST, prefix="teacher_signup" ) if not captcha.CAPTCHA_ENABLED: remove_captcha_from_forms(teacher_signup_form) if teacher_signup_form.is_valid(): data = teacher_signup_form.cleaned_data return process_signup_form(request, data) else: independent_student_signup_form = IndependentStudentSignupForm( request.POST, prefix="independent_student_signup" ) if independent_student_signup_form.is_valid(): data = independent_student_signup_form.cleaned_data return process_independent_student_signup_form(request, data) res = render( request, "portal/register.html", { "teacher_signup_form": teacher_signup_form, "independent_student_signup_form": independent_student_signup_form, }, ) res.count = invalid_form return res
def contact(request): increment_count = False should_use_captcha = captcha.CAPTCHA_ENABLED anchor = "" if request.method == "POST": contact_form = ContactForm(request.POST) if not should_use_captcha: remove_captcha_from_forms(contact_form) increment_count = True if contact_form.is_valid(): anchor = "top" email_message = email_messages.contactEmail( request, contact_form.cleaned_data["name"], contact_form.cleaned_data["telephone"], contact_form.cleaned_data["email"], contact_form.cleaned_data["message"], contact_form.cleaned_data["browser"], ) send_email( CONTACT_EMAIL, app_settings.CONTACT_FORM_EMAILS, email_message["subject"], email_message["message"], ) confirmed_email_message = email_messages.confirmationContactEmailMessage( request, contact_form.cleaned_data["name"], contact_form.cleaned_data["telephone"], contact_form.cleaned_data["email"], contact_form.cleaned_data["message"], ) send_email( CONTACT_EMAIL, [contact_form.cleaned_data["email"]], confirmed_email_message["subject"], confirmed_email_message["message"], ) messages.success(request, "Your message was sent successfully.") return render( request, "portal/help-and-support.html", { "form": contact_form, "anchor": anchor }, ) else: contact_form = ContactForm(request.POST) anchor = "contact" else: contact_form = ContactForm() if not should_use_captcha: remove_captcha_from_forms(contact_form) response = render( request, "portal/help-and-support.html", { "form": contact_form, "anchor": anchor, "captcha": should_use_captcha, "settings": app_settings, }, ) response.count = increment_count return response
def configure_login_form_captcha(form, render_dict, render_dict_captcha_key): if not render_dict[render_dict_captcha_key]: remove_captcha_from_forms(form)
def contact(request): increment_count = False should_use_captcha = captcha.CAPTCHA_ENABLED anchor = "" if request.method == "POST": contact_form = ContactForm(request.POST) if not should_use_captcha: remove_captcha_from_forms(contact_form) increment_count = True if contact_form.is_valid(): anchor = "top" email_message = email_messages.contactEmail( request, contact_form.cleaned_data["name"], contact_form.cleaned_data["telephone"], contact_form.cleaned_data["email"], contact_form.cleaned_data["message"], contact_form.cleaned_data["browser"], ) send_email( CONTACT_EMAIL, app_settings.CONTACT_FORM_EMAILS, email_message["subject"], email_message["message"], ) confirmed_email_message = email_messages.confirmationContactEmailMessage( request, contact_form.cleaned_data["name"], contact_form.cleaned_data["telephone"], contact_form.cleaned_data["email"], contact_form.cleaned_data["message"], ) send_email( CONTACT_EMAIL, [contact_form.cleaned_data["email"]], confirmed_email_message["subject"], confirmed_email_message["message"], ) messages.success(request, "Your message was sent successfully.") return render( request, "portal/help-and-support.html", {"form": contact_form, "anchor": anchor}, ) else: contact_form = ContactForm(request.POST) anchor = "contact" else: contact_form = ContactForm() if not should_use_captcha: remove_captcha_from_forms(contact_form) response = render( request, "portal/help-and-support.html", { "form": contact_form, "anchor": anchor, "captcha": should_use_captcha, "settings": app_settings, }, ) response.count = increment_count return response
def configure_login_form_captcha(form, render_dict, render_dict_captcha_key): if not render_dict[render_dict_captcha_key]: remove_captcha_from_forms(form)