From 196be4b3b0cc0e098b5c3b0c3785fc3af72b179d Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 14 Dec 2018 13:51:12 +0100 Subject: [PATCH] Add captcha_factor --- passbook/captcha_factor/__init__.py | 3 +++ passbook/captcha_factor/apps.py | 9 +++++++++ passbook/captcha_factor/factor.py | 15 +++++++++++++++ passbook/captcha_factor/forms.py | 9 +++++++++ passbook/captcha_factor/requirements.txt | 1 + passbook/captcha_factor/settings.py | 7 +++++++ passbook/core/settings.py | 2 ++ requirements.txt | 1 + 8 files changed, 47 insertions(+) create mode 100644 passbook/captcha_factor/__init__.py create mode 100644 passbook/captcha_factor/apps.py create mode 100644 passbook/captcha_factor/factor.py create mode 100644 passbook/captcha_factor/forms.py create mode 100644 passbook/captcha_factor/requirements.txt create mode 100644 passbook/captcha_factor/settings.py diff --git a/passbook/captcha_factor/__init__.py b/passbook/captcha_factor/__init__.py new file mode 100644 index 000000000..7aad72d49 --- /dev/null +++ b/passbook/captcha_factor/__init__.py @@ -0,0 +1,3 @@ +"""passbook captcha_factor Header""" +__version__ = '0.0.1-alpha' +default_app_config = 'passbook.captcha_factor.apps.PassbookCaptchaFactorConfig' diff --git a/passbook/captcha_factor/apps.py b/passbook/captcha_factor/apps.py new file mode 100644 index 000000000..9409a5e7b --- /dev/null +++ b/passbook/captcha_factor/apps.py @@ -0,0 +1,9 @@ +"""passbook captcha app""" +from django.apps import AppConfig + + +class PassbookCaptchaFactorConfig(AppConfig): + """passbook captcha app""" + + name = 'passbook.captcha_factor' + label = 'passbook_captcha_factor' diff --git a/passbook/captcha_factor/factor.py b/passbook/captcha_factor/factor.py new file mode 100644 index 000000000..a16222995 --- /dev/null +++ b/passbook/captcha_factor/factor.py @@ -0,0 +1,15 @@ +"""passbook captcha factor""" + +from django.views.generic import FormView + +from passbook.captcha_factor.forms import CaptchaForm +from passbook.core.auth.factor import AuthenticationFactor + + +class CaptchaFactor(FormView, AuthenticationFactor): + """Simple captcha checker, logic is handeled in django-captcha module""" + + form_class = CaptchaForm + + def form_valid(self, form): + return self.authenticator.user_ok() diff --git a/passbook/captcha_factor/forms.py b/passbook/captcha_factor/forms.py new file mode 100644 index 000000000..ba1c53760 --- /dev/null +++ b/passbook/captcha_factor/forms.py @@ -0,0 +1,9 @@ +"""passbook captcha factor forms""" +from captcha.fields import ReCaptchaField +from django import forms + + +class CaptchaForm(forms.Form): + """passbook captcha factor form""" + + captcha = ReCaptchaField() diff --git a/passbook/captcha_factor/requirements.txt b/passbook/captcha_factor/requirements.txt new file mode 100644 index 000000000..ec8b7d8e2 --- /dev/null +++ b/passbook/captcha_factor/requirements.txt @@ -0,0 +1 @@ +django-recaptcha diff --git a/passbook/captcha_factor/settings.py b/passbook/captcha_factor/settings.py new file mode 100644 index 000000000..cfc90dc45 --- /dev/null +++ b/passbook/captcha_factor/settings.py @@ -0,0 +1,7 @@ +"""passbook captcha_facot settings""" +RECAPTCHA_PUBLIC_KEY = '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI' +RECAPTCHA_PRIVATE_KEY = '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe' +NOCAPTCHA = True +INSTALLED_APPS = [ + 'captcha' +] diff --git a/passbook/core/settings.py b/passbook/core/settings.py index 5e4c7e716..6765a6349 100644 --- a/passbook/core/settings.py +++ b/passbook/core/settings.py @@ -52,6 +52,7 @@ AUTHENTICATION_BACKENDS = [ AUTHENTICATION_FACTORS = [ 'passbook.core.auth.backend_factor.AuthenticationBackendFactor', 'passbook.core.auth.dummy.DummyFactor', + 'passbook.captcha_factor.factor.CaptchaFactor', ] # Application definition @@ -75,6 +76,7 @@ INSTALLED_APPS = [ 'passbook.oauth_provider', 'passbook.saml_idp', 'passbook.totp', + 'passbook.captcha_factor', ] # Message Tag fix for bootstrap CSS Classes diff --git a/requirements.txt b/requirements.txt index 865377c36..ea4e38b2b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ -r passbook/totp/requirements.txt -r passbook/oauth_provider/requirements.txt -r passbook/audit/requirements.txt +-r passbook/captcha_factor/requirements.txt