From 6e912173032323eea1eb31d28a710d87175abb95 Mon Sep 17 00:00:00 2001 From: Bai Date: Wed, 30 Sep 2020 11:37:11 +0800 Subject: [PATCH] =?UTF-8?q?perf(authentication):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95=E9=A1=B5=E9=9D=A2=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=85=B6=E4=BB=96=E6=96=B9=E5=BC=8F=E8=AE=A4?= =?UTF-8?q?=E8=AF=81=E6=97=B6=E7=82=B9=E5=87=BB=E5=BF=98=E8=AE=B0=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E6=8F=90=E7=A4=BA=E8=81=94=E7=B3=BB=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/authentication/login.html | 14 +++++++++++++- .../templates/authentication/xpack_login.html | 15 ++++++++++++++- apps/authentication/views/login.py | 3 ++- apps/jumpserver/conf.py | 3 +++ apps/jumpserver/settings/auth.py | 3 +++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/apps/authentication/templates/authentication/login.html b/apps/authentication/templates/authentication/login.html index bf0afa30b..521f3dbd2 100644 --- a/apps/authentication/templates/authentication/login.html +++ b/apps/authentication/templates/authentication/login.html @@ -57,7 +57,7 @@
- + {% trans 'Forgot password' %}?
@@ -90,5 +90,17 @@ $('#password-hidden').val(passwordEncrypted); //返回给密码输入input $('#form').submit();//post提交 } + + var authDB = '{{ AUTH_DB }}'; + var forgotPasswordUrl = "{% url 'authentication:forgot-password' %}"; + $(document).ready(function () { + }).on('click', '#forgot_password', function () { + if (authDB === 'True'){ + window.open(forgotPasswordUrl, "_blank") + } + else{ + alert("{% trans 'You are using another authentication server, please contact your administrator' %}") + } + }) {% endblock %} diff --git a/apps/authentication/templates/authentication/xpack_login.html b/apps/authentication/templates/authentication/xpack_login.html index a7a3773fc..d566ce1f8 100644 --- a/apps/authentication/templates/authentication/xpack_login.html +++ b/apps/authentication/templates/authentication/xpack_login.html @@ -131,7 +131,7 @@
- + {% trans 'Forgot password' %}?
@@ -144,6 +144,7 @@ + @@ -161,6 +162,18 @@ $('#password-hidden').val(passwordEncrypted); //返回给密码输入input $('#contact-form').submit();//post提交 } + + var authDB = '{{ AUTH_DB }}'; + var forgotPasswordUrl = "{% url 'authentication:forgot-password' %}"; + $(document).ready(function () { + }).on('click', '#forgot_password', function () { + if (authDB === 'True'){ + window.open(forgotPasswordUrl, "_blank") + } + else{ + alert("{% trans 'You are using another authentication server, please contact your administrator' %}") + } + }) diff --git a/apps/authentication/views/login.py b/apps/authentication/views/login.py index 100e190b6..42925b9ff 100644 --- a/apps/authentication/views/login.py +++ b/apps/authentication/views/login.py @@ -131,7 +131,8 @@ class UserLoginView(mixins.AuthMixin, FormView): context = { 'demo_mode': os.environ.get("DEMO_MODE"), 'AUTH_OPENID': settings.AUTH_OPENID, - 'rsa_public_key': rsa_public_key + 'rsa_public_key': rsa_public_key, + 'AUTH_DB': settings.AUTH_DB } kwargs.update(context) return super().get_context_data(**kwargs) diff --git a/apps/jumpserver/conf.py b/apps/jumpserver/conf.py index d5bff1819..57c5bed89 100644 --- a/apps/jumpserver/conf.py +++ b/apps/jumpserver/conf.py @@ -455,6 +455,9 @@ class DynamicConfig: backends.insert(0, 'authentication.backends.api.SSOAuthentication') return backends + def AUTH_DB(self): + return len(self.AUTHENTICATION_BACKENDS()) == 2 + def XPACK_LICENSE_IS_VALID(self): if not HAS_XPACK: return False diff --git a/apps/jumpserver/settings/auth.py b/apps/jumpserver/settings/auth.py index 4430aae2f..9f91cdb1d 100644 --- a/apps/jumpserver/settings/auth.py +++ b/apps/jumpserver/settings/auth.py @@ -9,6 +9,9 @@ from ..const import CONFIG, DYNAMIC, PROJECT_DIR OTP_ISSUER_NAME = CONFIG.OTP_ISSUER_NAME OTP_VALID_WINDOW = CONFIG.OTP_VALID_WINDOW +# Auth DB +AUTH_DB = DYNAMIC.AUTH_DB + # Auth LDAP settings AUTH_LDAP = DYNAMIC.AUTH_LDAP AUTH_LDAP_SERVER_URI = DYNAMIC.AUTH_LDAP_SERVER_URI