From 7596dcc08dbc7bf1c5b38b72be1c87eb20c5bbae Mon Sep 17 00:00:00 2001 From: Tom Price Date: Sat, 25 Apr 2015 16:28:11 +0100 Subject: [PATCH 1/4] Add recaptcha library. --- PyRIGS/settings.py | 6 ++++++ requirements.txt | 1 + 2 files changed, 7 insertions(+) diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index 1f0c8cad..dc922a98 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -44,6 +44,7 @@ INSTALLED_APPS = ( 'debug_toolbar', 'registration', 'reversion', + 'captcha', 'widget_tweaks', ) @@ -131,6 +132,11 @@ LOGOUT_URL = '/user/logout' ACCOUNT_ACTIVATION_DAYS = 7 +# reCAPTCHA settings +RECAPTCHA_PUBLIC_KEY = '6Le16gUTAAAAAO5f-6te_x0NjWmF65_h7saBI6Cg' +RECAPTCHA_PRIVATE_KEY = '6Le16gUTAAAAAByo-ZxRRX3RKyoBngf7ms3dnoEW' +NOCAPTCHA = True + # Email EMAILER_TEST = False if not DEBUG or EMAILER_TEST: diff --git a/requirements.txt b/requirements.txt index 9a46f2f2..3a90e9d6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,6 +7,7 @@ dj-database-url==0.3.0 dj-static==0.0.6 django-debug-toolbar==1.2.2 django-ical==1.3 +django-recaptcha==1.0.4 django-registration-redux==1.1 django-reversion==1.8.5 django-toolbelt==0.0.1 From 6b1ac008c541bbbedbfbb2b97ae5b32fe37c6da5 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Sat, 25 Apr 2015 16:30:42 +0100 Subject: [PATCH 2/4] Add recaptcha field to form --- RIGS/forms.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RIGS/forms.py b/RIGS/forms.py index 3f38f9d5..134fc0bd 100644 --- a/RIGS/forms.py +++ b/RIGS/forms.py @@ -4,6 +4,7 @@ from django.utils import formats from django.conf import settings from django.core import serializers from registration.forms import RegistrationFormUniqueEmail +from captcha.fields import ReCaptchaField import simplejson from RIGS import models @@ -14,6 +15,7 @@ class ProfileRegistrationFormUniqueEmail(RegistrationFormUniqueEmail): last_name = forms.CharField(required=False, max_length=50) initials = forms.CharField(required=True, max_length=5) phone = forms.CharField(required=False, max_length=13) + captcha = ReCaptchaField() def clean_initials(self): """ From 42e8de7d9d667f3c2057a3f67adc66b4167c730e Mon Sep 17 00:00:00 2001 From: Tom Price Date: Sat, 25 Apr 2015 16:54:01 +0100 Subject: [PATCH 3/4] Add recaptcha to login page --- RIGS/forms.py | 5 +++++ RIGS/views.py | 2 +- templates/registration/loginform.html | 8 +++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/RIGS/forms.py b/RIGS/forms.py index 134fc0bd..7a9dc854 100644 --- a/RIGS/forms.py +++ b/RIGS/forms.py @@ -3,6 +3,7 @@ from django import forms from django.utils import formats from django.conf import settings from django.core import serializers +from django.contrib.auth.forms import AuthenticationForm from registration.forms import RegistrationFormUniqueEmail from captcha.fields import ReCaptchaField import simplejson @@ -25,6 +26,10 @@ class ProfileRegistrationFormUniqueEmail(RegistrationFormUniqueEmail): raise forms.ValidationError("These initials are already in use. Please supply different initials.") return self.cleaned_data['initials'] +# Login form +class LoginForm(AuthenticationForm): + captcha = ReCaptchaField(label='Captcha') + # Events Shit class EventForm(forms.ModelForm): datetime_input_formats = formats.get_format_lazy("DATETIME_INPUT_FORMATS") + settings.DATETIME_INPUT_FORMATS diff --git a/RIGS/views.py b/RIGS/views.py index 38cbe99a..472f20ec 100644 --- a/RIGS/views.py +++ b/RIGS/views.py @@ -30,7 +30,7 @@ def login(request, **kwargs): else: from django.contrib.auth.views import login - return login(request) + return login(request, authentication_form=forms.LoginForm) """ diff --git a/templates/registration/loginform.html b/templates/registration/loginform.html index 01c0b900..1ad39bd7 100644 --- a/templates/registration/loginform.html +++ b/templates/registration/loginform.html @@ -1,7 +1,7 @@ {% load url from future %} {% load widget_tweaks %} {% include 'form_errors.html' %} -
+
{% csrf_token %}
@@ -12,6 +12,12 @@ {% render_field form.password class+="form-control" placeholder=form.password.label %}
+
+ +
+ {{ form.captcha }} +
+
Register Forgotten Password From 291e6d5c26fd1fc7c6b7efbeb6e4cf959e229767 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Sat, 25 Apr 2015 17:04:15 +0100 Subject: [PATCH 4/4] Add recaptcha to password reset form. This should be all public facing pages covered. --- RIGS/forms.py | 5 ++++- RIGS/urls.py | 3 ++- templates/registration/password_reset_form.html | 11 ++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/RIGS/forms.py b/RIGS/forms.py index 7a9dc854..8a019409 100644 --- a/RIGS/forms.py +++ b/RIGS/forms.py @@ -3,7 +3,7 @@ from django import forms from django.utils import formats from django.conf import settings from django.core import serializers -from django.contrib.auth.forms import AuthenticationForm +from django.contrib.auth.forms import AuthenticationForm, PasswordResetForm from registration.forms import RegistrationFormUniqueEmail from captcha.fields import ReCaptchaField import simplejson @@ -30,6 +30,9 @@ class ProfileRegistrationFormUniqueEmail(RegistrationFormUniqueEmail): class LoginForm(AuthenticationForm): captcha = ReCaptchaField(label='Captcha') +class PasswordReset(PasswordResetForm): + captcha = ReCaptchaField(label='Captcha') + # Events Shit class EventForm(forms.ModelForm): datetime_input_formats = formats.get_format_lazy("DATETIME_INPUT_FORMATS") + settings.DATETIME_INPUT_FORMATS diff --git a/RIGS/urls.py b/RIGS/urls.py index dfe725c2..cab2532c 100644 --- a/RIGS/urls.py +++ b/RIGS/urls.py @@ -1,6 +1,6 @@ from django.conf.urls import patterns, include, url from django.contrib.auth.decorators import login_required -from RIGS import views, rigboard, finance, ical +from RIGS import views, rigboard, finance, ical, forms from django.views.generic import RedirectView from PyRIGS.decorators import permission_required_with_403 @@ -14,6 +14,7 @@ urlpatterns = patterns('', url(r'^closemodal/$', views.CloseModal.as_view(), name='closemodal'), url('^user/login/$', 'RIGS.views.login', name='login'), + url(r'^user/password_reset/$', 'django.contrib.auth.views.password_reset', {'password_reset_form':forms.PasswordReset}), # People url(r'^people/$', permission_required_with_403('RIGS.view_person')(views.PersonList.as_view()), diff --git a/templates/registration/password_reset_form.html b/templates/registration/password_reset_form.html index bbe77669..b9358488 100644 --- a/templates/registration/password_reset_form.html +++ b/templates/registration/password_reset_form.html @@ -21,11 +21,12 @@ {% render_field form.email type="email" class+="form-control" %}
-
-
-
- -
+
+
+ {{ form.captcha }} +
+
+