Commit da9a3794 authored by Grégoire Duvauchelle's avatar Grégoire Duvauchelle

Add captcha to registration form

parent b2abc786
Pipeline #1509 failed with stage
in 5 minutes and 17 seconds
......@@ -55,6 +55,8 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942',
'password1': 'plop',
'password2': 'plop',
'captcha_0': 'dummy-value',
'captcha_1': 'PASSED'
})
self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_OK' in str(response.content))
......@@ -70,6 +72,8 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942',
'password1': 'plop',
'password2': 'plop2',
'captcha_0': 'dummy-value',
'captcha_1': 'PASSED'
})
self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
......@@ -85,6 +89,8 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942',
'password1': 'plop',
'password2': 'plop',
'captcha_0': 'dummy-value',
'captcha_1': 'PASSED'
})
self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
......@@ -100,6 +106,8 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942',
'password1': 'plop',
'password2': 'plop',
'captcha_0': 'dummy-value',
'captcha_1': 'PASSED'
})
self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
......@@ -115,6 +123,8 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '',
'password1': 'plop',
'password2': 'plop',
'captcha_0': 'dummy-value',
'captcha_1': 'PASSED'
})
self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
......@@ -130,6 +140,25 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942',
'password1': 'plop',
'password2': 'plop',
'captcha_0': 'dummy-value',
'captcha_1': 'PASSED'
})
self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
def test_register_user_form_fail_wrong_captcha(self):
"""
Should not register a user correctly
"""
c = Client()
response = c.post(reverse('core:register'), {'first_name': 'Bibou',
'last_name': 'Carlier',
'email': 'bibou@git.an',
'date_of_birth': '12/6/1942',
'password1': 'plop',
'password2': 'plop',
'captcha_0': 'dummy-value',
'captcha_1': 'WRONG_CAPTCHA'
})
self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
......@@ -145,6 +174,8 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942',
'password1': 'plop',
'password2': 'plop',
'captcha_0': 'dummy-value',
'captcha_1': 'PASSED'
})
response = c.post(reverse('core:register'), {'first_name': 'Bibou',
'last_name': 'Carlier',
......@@ -152,6 +183,8 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942',
'password1': 'plop',
'password2': 'plop',
'captcha_0': 'dummy-value',
'captcha_1': 'PASSED'
})
self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
......
......@@ -21,7 +21,7 @@
# Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
from captcha.fields import CaptchaField
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from django import forms
from django.conf import settings
......@@ -148,6 +148,7 @@ class LoginForm(AuthenticationForm):
class RegisteringForm(UserCreationForm):
error_css_class = 'error'
required_css_class = 'required'
captcha = CaptchaField()
class Meta:
model = User
......
......@@ -74,6 +74,7 @@ INSTALLED_APPS = (
'rest_framework',
'ajax_select',
'haystack',
'captcha',
'core',
'club',
'subscription',
......@@ -625,3 +626,4 @@ if DEBUG:
SASS_INCLUDE_FOLDERS = [
'core/static/',
]
CAPTCHA_TEST_MODE = True
......@@ -72,6 +72,7 @@ urlpatterns = [
url(r'^ajax_select/', include(ajax_select_urls)),
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^jsi18n/$', javascript_catalog, js_info_dict, name='javascript-catalog'),
url(r'^captcha/', include('captcha.urls')),
]
if settings.DEBUG:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment