mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-25 17:21:15 +00:00
Add captcha to registration form
This commit is contained in:
parent
b2abc78694
commit
afe78ea634
@ -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))
|
||||
@ -167,6 +200,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:login'), {'username': 'gcarlier', 'password': 'plop'})
|
||||
self.assertTrue(response.status_code == 302)
|
||||
@ -183,6 +218,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:login'), {'username': 'gcarlier', 'password': 'guy'})
|
||||
self.assertTrue(response.status_code == 200)
|
||||
|
@ -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
|
||||
|
@ -14,5 +14,6 @@ whoosh
|
||||
django-debug-toolbar
|
||||
libsass
|
||||
django-ordered-model
|
||||
django-simple-captcha
|
||||
pygraphviz
|
||||
# mysqlclient
|
||||
|
@ -74,6 +74,7 @@ INSTALLED_APPS = (
|
||||
'rest_framework',
|
||||
'ajax_select',
|
||||
'haystack',
|
||||
'captcha',
|
||||
'core',
|
||||
'club',
|
||||
'subscription',
|
||||
@ -625,3 +626,6 @@ if DEBUG:
|
||||
SASS_INCLUDE_FOLDERS = [
|
||||
'core/static/',
|
||||
]
|
||||
|
||||
if 'test' in sys.argv:
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user