Commit 290f6ca8 authored by Skia's avatar Skia
Browse files

Merge branch 'feature/captcha' into 'master'

Add captcha to registration form

Closes #52

See merge request !154
parents b2abc786 afe78ea6
Pipeline #1512 passed with stage
in 5 minutes and 18 seconds
...@@ -55,6 +55,8 @@ class UserRegistrationTest(TestCase): ...@@ -55,6 +55,8 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop', 'password2': 'plop',
'captcha_0': 'dummy-value',
'captcha_1': 'PASSED'
}) })
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_OK' in str(response.content)) self.assertTrue('TEST_REGISTER_USER_FORM_OK' in str(response.content))
...@@ -70,6 +72,8 @@ class UserRegistrationTest(TestCase): ...@@ -70,6 +72,8 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop2', 'password2': 'plop2',
'captcha_0': 'dummy-value',
'captcha_1': 'PASSED'
}) })
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content)) self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
...@@ -85,6 +89,8 @@ class UserRegistrationTest(TestCase): ...@@ -85,6 +89,8 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop', 'password2': 'plop',
'captcha_0': 'dummy-value',
'captcha_1': 'PASSED'
}) })
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content)) self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
...@@ -100,6 +106,8 @@ class UserRegistrationTest(TestCase): ...@@ -100,6 +106,8 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop', 'password2': 'plop',
'captcha_0': 'dummy-value',
'captcha_1': 'PASSED'
}) })
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content)) self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
...@@ -115,6 +123,8 @@ class UserRegistrationTest(TestCase): ...@@ -115,6 +123,8 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '', 'date_of_birth': '',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop', 'password2': 'plop',
'captcha_0': 'dummy-value',
'captcha_1': 'PASSED'
}) })
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content)) self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
...@@ -130,6 +140,25 @@ class UserRegistrationTest(TestCase): ...@@ -130,6 +140,25 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': '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(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content)) self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
...@@ -145,6 +174,8 @@ class UserRegistrationTest(TestCase): ...@@ -145,6 +174,8 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop', 'password2': 'plop',
'captcha_0': 'dummy-value',
'captcha_1': 'PASSED'
}) })
response = c.post(reverse('core:register'), {'first_name': 'Bibou', response = c.post(reverse('core:register'), {'first_name': 'Bibou',
'last_name': 'Carlier', 'last_name': 'Carlier',
...@@ -152,6 +183,8 @@ class UserRegistrationTest(TestCase): ...@@ -152,6 +183,8 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop', 'password2': 'plop',
'captcha_0': 'dummy-value',
'captcha_1': 'PASSED'
}) })
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content)) self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
...@@ -167,6 +200,8 @@ class UserRegistrationTest(TestCase): ...@@ -167,6 +200,8 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop', 'password2': 'plop',
'captcha_0': 'dummy-value',
'captcha_1': 'PASSED'
}) })
response = c.post(reverse('core:login'), {'username': 'gcarlier', 'password': 'plop'}) response = c.post(reverse('core:login'), {'username': 'gcarlier', 'password': 'plop'})
self.assertTrue(response.status_code == 302) self.assertTrue(response.status_code == 302)
...@@ -183,6 +218,8 @@ class UserRegistrationTest(TestCase): ...@@ -183,6 +218,8 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop', 'password2': 'plop',
'captcha_0': 'dummy-value',
'captcha_1': 'PASSED'
}) })
response = c.post(reverse('core:login'), {'username': 'gcarlier', 'password': 'guy'}) response = c.post(reverse('core:login'), {'username': 'gcarlier', 'password': 'guy'})
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
# Place - Suite 330, Boston, MA 02111-1307, USA. # Place - Suite 330, Boston, MA 02111-1307, USA.
# #
# #
from captcha.fields import CaptchaField
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from django import forms from django import forms
from django.conf import settings from django.conf import settings
...@@ -148,6 +148,7 @@ class LoginForm(AuthenticationForm): ...@@ -148,6 +148,7 @@ class LoginForm(AuthenticationForm):
class RegisteringForm(UserCreationForm): class RegisteringForm(UserCreationForm):
error_css_class = 'error' error_css_class = 'error'
required_css_class = 'required' required_css_class = 'required'
captcha = CaptchaField()
class Meta: class Meta:
model = User model = User
......
...@@ -74,6 +74,7 @@ INSTALLED_APPS = ( ...@@ -74,6 +74,7 @@ INSTALLED_APPS = (
'rest_framework', 'rest_framework',
'ajax_select', 'ajax_select',
'haystack', 'haystack',
'captcha',
'core', 'core',
'club', 'club',
'subscription', 'subscription',
...@@ -625,3 +626,6 @@ if DEBUG: ...@@ -625,3 +626,6 @@ if DEBUG:
SASS_INCLUDE_FOLDERS = [ SASS_INCLUDE_FOLDERS = [
'core/static/', 'core/static/',
] ]
if 'test' in sys.argv:
CAPTCHA_TEST_MODE = True
...@@ -72,6 +72,7 @@ urlpatterns = [ ...@@ -72,6 +72,7 @@ urlpatterns = [
url(r'^ajax_select/', include(ajax_select_urls)), url(r'^ajax_select/', include(ajax_select_urls)),
url(r'^i18n/', include('django.conf.urls.i18n')), url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^jsi18n/$', javascript_catalog, js_info_dict, name='javascript-catalog'), url(r'^jsi18n/$', javascript_catalog, js_info_dict, name='javascript-catalog'),
url(r'^captcha/', include('captcha.urls')),
] ]
if settings.DEBUG: 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