From 1bc8e99523f047362c1566354d2babfcf4bdfc86 Mon Sep 17 00:00:00 2001 From: IMBlues Date: Thu, 2 Dec 2021 16:40:38 +0800 Subject: [PATCH] wip: fix language switch in ce login page --- src/login/bklogin/bkauth/views.py | 2 +- src/login/bklogin/config/common/platform.py | 1 + .../bklogin/templates/account/login.html | 2 +- .../bklogin/templates/account/login_ce.html | 42 +++++----- .../templates/account/login_ce_i18n.html | 80 ------------------- src/login/bklogin/urls.py | 15 ++-- src/login/static/js/login.js | 1 - src/login/static/js_ce/login.js | 30 +++---- 8 files changed, 43 insertions(+), 130 deletions(-) delete mode 100755 src/login/bklogin/templates/account/login_ce_i18n.html diff --git a/src/login/bklogin/bkauth/views.py b/src/login/bklogin/bkauth/views.py index b6f5fe6a1..2599a0d31 100755 --- a/src/login/bklogin/bkauth/views.py +++ b/src/login/bklogin/bkauth/views.py @@ -92,7 +92,7 @@ def _bk_login(request): authentication_form = BkAuthenticationForm # NOTE: account/login.html 为支持自适应大小的模板 template_name = "account/login.html" - forget_reset_password_url = "%s://%s/o/bk_user_manage/reset_password" % (settings.HTTP_SCHEMA, request.get_host()) + forget_reset_password_url = f"{settings.BK_USERMGR_SAAS_URL}/reset_password" token_set_password_url = "" redirect_to = request.POST.get(REDIRECT_FIELD_NAME, request.GET.get(REDIRECT_FIELD_NAME, "")) diff --git a/src/login/bklogin/config/common/platform.py b/src/login/bklogin/config/common/platform.py index ab809ecb5..0e2a99793 100644 --- a/src/login/bklogin/config/common/platform.py +++ b/src/login/bklogin/config/common/platform.py @@ -40,6 +40,7 @@ # 用户管理API访问地址 BK_USERMGR_API_URL = env.str("BK_USERMGR_API_URL", "http://bkuserapi-web") +BK_USERMGR_SAAS_URL = env.str("BK_USERMGR_SAAS_URL", "http://bkusersaas-web") # external config # license diff --git a/src/login/bklogin/templates/account/login.html b/src/login/bklogin/templates/account/login.html index 04b680926..73b1e41cf 100755 --- a/src/login/bklogin/templates/account/login.html +++ b/src/login/bklogin/templates/account/login.html @@ -64,7 +64,7 @@
{% csrf_token %} - + +
- +

{% if error_message %} {{ error_message }} {% if token_set_password_url %} - ,请修改密码 + ,{% trans '请修改密码' %} {% endif %} {% endif %}

- +
- +
- 用户协议 > + {% trans '用户协议 >' %} - 忘记密码? + {% trans '忘记密码?' %}

@@ -93,15 +93,15 @@ {% get_available_languages as LANGUAGES %} {% get_language_info_list for LANGUAGES as languages %} {% for language in languages %} - {% endfor %} - - --> + --> +

@@ -109,26 +109,26 @@ {% include "account/agreement.part" %}
- 您的浏览器非Chrome,建议您使用最新版本的Chrome浏览,以保证最好的体验效果 + {% trans '您的浏览器非Chrome,建议您使用最新版本的Chrome浏览,以保证最好的体验效果' %}
- + - + diff --git a/src/login/bklogin/templates/account/login_ce_i18n.html b/src/login/bklogin/templates/account/login_ce_i18n.html deleted file mode 100755 index 0e6bb8ec8..000000000 --- a/src/login/bklogin/templates/account/login_ce_i18n.html +++ /dev/null @@ -1,80 +0,0 @@ -{% load i18n %} - - - - - - - - - {% trans '登录|蓝鲸智云' %} - - -
- - -
- - {% include "account/agreement.part" %} - -
- {% trans '您的浏览器非Chrome,建议您使用最新版本的Chrome浏览,以保证最好的体验效果' %} -
- - - - - - - diff --git a/src/login/bklogin/urls.py b/src/login/bklogin/urls.py index ce8efe98f..50d5daea3 100755 --- a/src/login/bklogin/urls.py +++ b/src/login/bklogin/urls.py @@ -14,7 +14,6 @@ from bklogin.bkauth.decorators import login_exempt from bklogin.healthz import views as healthz_views from decorator_include import decorator_include -from django.conf import settings from django.conf.urls import include, url from django.http import HttpResponse from django.views import i18n as django_i18n_views @@ -101,14 +100,12 @@ url(r"", decorator_include(login_exempt, "django_prometheus.urls")), ] -# ce not support i18n, so no setlang and jsi18n -if settings.EDITION == "ee": - urlpatterns += [ - # 无登录态下切换语言 - url(r"^i18n/setlang/$", django_i18n_views.set_language, name="set_language"), - # 处理JS翻译 - url(r"^jsi18n/(?P\S+?)/$", JavaScriptCatalog.as_view(), name="javascript-catalog"), - ] +urlpatterns += [ + # 无登录态下切换语言 + url(r"^i18n/setlang/$", django_i18n_views.set_language, name="set_language"), + # 处理JS翻译 + url(r"^jsi18n/(?P\S+?)/$", JavaScriptCatalog.as_view(), name="javascript-catalog"), +] from django.contrib.staticfiles.urls import staticfiles_urlpatterns # noqa diff --git a/src/login/static/js/login.js b/src/login/static/js/login.js index a24079f33..34aae1e6c 100755 --- a/src/login/static/js/login.js +++ b/src/login/static/js/login.js @@ -31,7 +31,6 @@ $(document).ready(function(){ setTimeout(function(){ $("#language-form").submit(); }, 500); - }); // 点击查看协议 diff --git a/src/login/static/js_ce/login.js b/src/login/static/js_ce/login.js index 1b17c22a6..0b28bc3b4 100755 --- a/src/login/static/js_ce/login.js +++ b/src/login/static/js_ce/login.js @@ -28,34 +28,30 @@ function refresh_token(){ $(document).ready(function(){ - // 中英文切换 - // $('.language-switcher img').click(function() { - // $(this).toggleClass('en'); - // var language = 'zh-hans'; - // if ($(this).hasClass('en')) { - // language = 'en'; - // } - // $("#language-form select").val(language); - // setTimeout(function(){ - // $("#language-form").submit(); - // }, 500); - - // }); - // 中英文切换 const languageCH = $('#ch').parent(); const languageEN = $('#en').parent(); + + function changeLanguage (language) { + $("#language-value").val(language); + setTimeout(function(){ + $("#language-form").submit(); + }, 500); + } + languageCH.on('click', function() { $(this).attr('class', 'language-item active'); languageEN.attr('class', 'language-item'); - }) + changeLanguage("zh-hans"); + }); languageEN.on('click', function() { $(this).attr('class', 'language-item active'); languageCH.attr('class', 'language-item'); - }) + changeLanguage("en"); + }); // 点击查看协议 - $('.btn-content .protocol-btn').click(function(event) { + $('.action .protocol-btn').click(function(event) { $('.protocol-pop').show(); });