diff --git a/layerindex/auth_forms.py b/layerindex/auth_forms.py new file mode 100644 index 0000000..42d4e4b --- /dev/null +++ b/layerindex/auth_forms.py @@ -0,0 +1,16 @@ +# layerindex-web - extended authentication forms +# +# Copyright (C) 2018 Intel Corporation +# +# Licensed under the MIT license, see COPYING.MIT for details + +from captcha.fields import CaptchaField +from registration.forms import RegistrationForm +from django.contrib.auth.forms import PasswordResetForm + + +class CaptchaRegistrationForm(RegistrationForm): + captcha = CaptchaField(label='Verification', help_text='Please enter the letters displayed for verification purposes', error_messages={'invalid':'Incorrect entry, please try again'}) + +class CaptchaPasswordResetForm(PasswordResetForm): + captcha = CaptchaField(label='Verification', help_text='Please enter the letters displayed for verification purposes', error_messages={'invalid':'Incorrect entry, please try again'}) diff --git a/layerindex/auth_views.py b/layerindex/auth_views.py new file mode 100644 index 0000000..0fcf4ec --- /dev/null +++ b/layerindex/auth_views.py @@ -0,0 +1,30 @@ +# layerindex-web - extended authentication views +# +# Copyright (C) 2018 Intel Corporation +# +# Licensed under the MIT license, see COPYING.MIT for details + +from registration.backends.model_activation.views import RegistrationView +from django.contrib.auth.views import PasswordResetView +from layerindex.auth_forms import CaptchaRegistrationForm, CaptchaPasswordResetForm + + +class CaptchaRegistrationView(RegistrationView): + form_class = CaptchaRegistrationForm + + def get_context_data(self, **kwargs): + context = super(CaptchaRegistrationView, self).get_context_data(**kwargs) + form = context['form'] + # Prepare a list of fields with errors + # We do this so that if there's a problem with the captcha, that's the only error shown + # (since we have a username field, we want to make user enumeration difficult) + if 'captcha' in form.errors: + error_fields = ['captcha'] + else: + error_fields = form.errors.keys() + context['error_fields'] = error_fields + return context + + +class CaptchaPasswordResetView(PasswordResetView): + form_class = CaptchaPasswordResetForm diff --git a/templates/registration/registration_form.html b/templates/registration/registration_form.html index f0864c1..45f8c9a 100644 --- a/templates/registration/registration_form.html +++ b/templates/registration/registration_form.html @@ -3,7 +3,25 @@ {% block content %}