diff --git a/alliance_auth/settings.py.example b/alliance_auth/settings.py.example index 2aa364b2..cfc68fce 100644 --- a/alliance_auth/settings.py.example +++ b/alliance_auth/settings.py.example @@ -67,6 +67,7 @@ INSTALLED_APPS = [ 'permissions_tool', 'geelweb.django.navhelper', 'bootstrap_pagination', + 'captcha', # Services 'services.modules.mumble', @@ -221,6 +222,15 @@ CACHES = { } } +# Google Recaptcha + +CAPTCHA_ENABLED = False + +RECAPTCHA_PUBLIC_KEY = 'MyRecaptchaKey' +RECAPTCHA_PRIVATE_KEY = 'MyRecaptchaPrivateKey' + +NOCAPTCHA = True + ##################################################### ## ## Auth configuration starts here diff --git a/authentication/forms.py b/authentication/forms.py index 76aa3771..7374ac03 100644 --- a/authentication/forms.py +++ b/authentication/forms.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals from django import forms from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.models import User +from django.conf import settings import re @@ -9,6 +10,10 @@ class LoginForm(forms.Form): username = forms.CharField(label=_('Username'), max_length=32, required=True) password = forms.CharField(label=_('Password'), widget=forms.PasswordInput()) + if getattr(settings, 'CAPTCHA_ENABLED', False): + from captcha.fields import ReCaptchaField + captcha = ReCaptchaField() + class RegistrationForm(forms.Form): username = forms.CharField(label=_('Username'), max_length=30, required=True) @@ -17,6 +22,10 @@ class RegistrationForm(forms.Form): email = forms.CharField(label=_('Email'), max_length=254, required=True) email_again = forms.CharField(label=_('Email Again'), max_length=254, required=True) + if getattr(settings, 'CAPTCHA_ENABLED', False): + from captcha.fields import ReCaptchaField + captcha = ReCaptchaField() + def clean(self): if ' ' in self.cleaned_data['username']: raise forms.ValidationError('Username cannot contain a space') diff --git a/docs/installation/auth/settings.md b/docs/installation/auth/settings.md index 8347660f..8fa74d05 100644 --- a/docs/installation/auth/settings.md +++ b/docs/installation/auth/settings.md @@ -136,6 +136,13 @@ Fittings and operations can be imported from Fleet-Up. Define the following to d - [FLEETUP_API_ID](#fleetup-api-id) - [FLEETUP_GROUP_ID](#fleetup-group-id) +### Captcha +To help prevent bots from registering and brute forcing the login. Get the reCaptcha keys from (here)[https://www.google.com/recaptcha/intro/index.html] + - [CAPTCHA_ENABLED](#captcha_enabled) + - [RECAPTCHA_PUBLIC_KEY](#recaptcha_public_key) + - [RECAPTCHA_PRIVATE_KEY](#recaptcha_private_key) + - [NOCAPTCHA](#nocaptcha) + # Description of Settings ## Django ### SECRET_KEY @@ -150,6 +157,14 @@ List of databases available. Contains the Django database, and may include servi Friendly name of the local language. ### TIME_ZONE Friendly name of the local timezone. +### CAPTCHA_ENABLED +Enable Google reCaptcha +### RECAPTCHA_PUBLIC_KEY +Google reCaptcha public key +### RECAPTCHA_PRIVATE_KEY +Google reCaptcha private key +### NOCAPTCHA +Enable New No Captcha reCaptcha ### STATIC_URL Absolute URL to serve static files from. ### STATIC_ROOT diff --git a/requirements.txt b/requirements.txt index 5ccdd5a0..a704a314 100755 --- a/requirements.txt +++ b/requirements.txt @@ -16,6 +16,7 @@ django-bootstrap-form django-navhelper django-bootstrap-pagination django-redis>=4.4 +django-recaptcha # awating release for fix to celery/django-celery#447 # django-celery