diff --git a/apps/authentication/forms.py b/apps/authentication/forms.py index 2f03d935b..fe28edb68 100644 --- a/apps/authentication/forms.py +++ b/apps/authentication/forms.py @@ -4,7 +4,7 @@ from django import forms from django.conf import settings from django.utils.translation import gettext_lazy as _ -from captcha.fields import CaptchaField +from captcha.fields import CaptchaField, CaptchaTextInput class UserLoginForm(forms.Form): @@ -26,8 +26,12 @@ class UserCheckOtpCodeForm(forms.Form): otp_code = forms.CharField(label=_('MFA code'), max_length=6) +class CustomCaptchaTextInput(CaptchaTextInput): + template_name = 'authentication/_captcha_field.html' + + class CaptchaMixin(forms.Form): - captcha = CaptchaField() + captcha = CaptchaField(widget=CustomCaptchaTextInput) class ChallengeMixin(forms.Form): diff --git a/apps/authentication/templates/authentication/_captcha_field.html b/apps/authentication/templates/authentication/_captcha_field.html new file mode 100644 index 000000000..a190aacb7 --- /dev/null +++ b/apps/authentication/templates/authentication/_captcha_field.html @@ -0,0 +1,29 @@ +{% load i18n %} +{% spaceless %} + captcha +
+
+
+ {% if audio %} + + {% endif %} +
+ {% include "django/forms/widgets/multiwidget.html" %} +
+
+ + +{% endspaceless %} \ No newline at end of file diff --git a/apps/jumpserver/settings/base.py b/apps/jumpserver/settings/base.py index 47b3d7a04..2a6291751 100644 --- a/apps/jumpserver/settings/base.py +++ b/apps/jumpserver/settings/base.py @@ -64,6 +64,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'django.forms', ] diff --git a/apps/jumpserver/settings/libs.py b/apps/jumpserver/settings/libs.py index 782d2bc06..8a8df7ca4 100644 --- a/apps/jumpserver/settings/libs.py +++ b/apps/jumpserver/settings/libs.py @@ -64,10 +64,10 @@ SWAGGER_SETTINGS = { # Captcha settings, more see https://django-simple-captcha.readthedocs.io/en/latest/advanced.html -CAPTCHA_IMAGE_SIZE = (80, 33) +CAPTCHA_IMAGE_SIZE = (140, 34) CAPTCHA_FOREGROUND_COLOR = '#001100' CAPTCHA_NOISE_FUNCTIONS = ('captcha.helpers.noise_dots',) -CAPTCHA_TEST_MODE = CONFIG.CAPTCHA_TEST_MODE +CAPTCHA_CHALLENGE_FUNCT = 'captcha.helpers.math_challenge' # Django bootstrap3 setting, more see http://django-bootstrap3.readthedocs.io/en/latest/settings.html BOOTSTRAP3 = { diff --git a/apps/jumpserver/urls.py b/apps/jumpserver/urls.py index c6d85b48b..47518d946 100644 --- a/apps/jumpserver/urls.py +++ b/apps/jumpserver/urls.py @@ -30,7 +30,6 @@ api_v2 = [ path('users/', include('users.urls.api_urls_v2', namespace='api-users-v2')), ] - app_view_patterns = [ path('auth/', include('authentication.urls.view_urls'), name='auth'), path('ops/', include('ops.urls.view_urls'), name='ops'), diff --git a/apps/templates/captcha/field.html b/apps/templates/captcha/field.html deleted file mode 100644 index 6979e870c..000000000 --- a/apps/templates/captcha/field.html +++ /dev/null @@ -1,12 +0,0 @@ -{{image}}{{hidden_field}}{{text_field}} - - \ No newline at end of file diff --git a/apps/templates/captcha/hidden_field.html b/apps/templates/captcha/hidden_field.html deleted file mode 100644 index 36d7490a3..000000000 --- a/apps/templates/captcha/hidden_field.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/apps/templates/captcha/image.html b/apps/templates/captcha/image.html deleted file mode 100644 index b4a415536..000000000 --- a/apps/templates/captcha/image.html +++ /dev/null @@ -1,4 +0,0 @@ -{% load i18n %} -{% spaceless %} - {% if audio %}{% endif %}captcha{% if audio %}{% endif %} -{% endspaceless %} \ No newline at end of file diff --git a/apps/templates/captcha/text_field.html b/apps/templates/captcha/text_field.html deleted file mode 100644 index 413eb1893..000000000 --- a/apps/templates/captcha/text_field.html +++ /dev/null @@ -1,7 +0,0 @@ -{% load i18n %} -
-
- -
-
-