Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: fix language switch in ce login page #180

Merged
merged 1 commit into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/login/bklogin/bkauth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ""))
Expand Down
1 change: 1 addition & 0 deletions src/login/bklogin/config/common/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/login/bklogin/templates/account/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</div>
<div class="language-switcher">
<form id="language-form" action="{{SITE_URL}}i18n/setlang/" method="post">{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}" />
<input name="next" type="hidden" value="{{ login_redirect_to }}" />
<select name="language" style="display: none;">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
Expand Down
42 changes: 21 additions & 21 deletions src/login/bklogin/templates/account/login_ce.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<link href="{{STATIC_URL}}assets/bk-icon-2.0/iconfont.css" rel="stylesheet" type="text/css" />
<link href="{{STATIC_URL}}assets/blueking-icon/index.css" rel="stylesheet" type="text/css" />
<link href="{{STATIC_URL}}css_ce/login.{{CSS_SUFFIX}}?v={{STATIC_VERSION}}" rel="stylesheet" type="text/css" />
<title>登录|蓝鲸智云</title>
<title>{% trans '登录|蓝鲸智云' %}</title>

{% if is_plain %}
<style>
Expand Down Expand Up @@ -42,7 +42,7 @@
<img src="{{STATIC_URL}}img/logo_ce/logo_ce.png" alt="">
</div>
<div>
<span class="title">社区版</span>
<span class="title">{% trans '社区版' %}</span>
<img src="{{STATIC_URL}}/img/logo_ce/v7.png" alt="">
</div>
</div>
Expand All @@ -51,33 +51,33 @@
<div class="form-login">
<div class="user group-control">
<i class="bk-icon icon-user"></i>
<input id="user" type="text" name="username" placeholder="请输入用户名" >
<input id="user" type="text" name="username" placeholder={% trans "请输入用户名" %}>
</div>
<div class="pwd group-control">
<i class="bk-icon icon-invisible-eye" id="invisible"></i>
<input class="password" id="password" type="password" name="password" value="" placeholder="请输入密码">
<input class="password" id="password" type="password" name="password" value="" placeholder={% trans "请输入密码" %}>
</div>
<p class="change-password">
{% if error_message %}
<span>{{ error_message }}</span>
{% if token_set_password_url %}
<a href="{{ token_set_password_url }}" target="_blank">请修改密码</a>
,<a href="{{ token_set_password_url }}" target="_blank">{% trans '请修改密码' %}</a>
{% endif %}
{% endif %}
</p>
<div>
<input type="hidden" name="next" value="{{ next }}" />
<input type="hidden" name="app_id" value="{{app_id }}">
<input type="hidden" name="app_id" value="{{ app_id }}">
</div>
<div class="btn-content clearfix">
<button class="login-btn" id="login-btn">立即登录</button>
<button class="login-btn" id="login-btn">{% trans '立即登录' %}</button>
<!-- <span class="protocol-btn">查看用户协议</span> -->
</div>
<div class="action clearfix">
<!-- {% if "/plain/" not in APP_PATH %} -->
<a href="javascript: void(0);" class="protocol-btn fl">用户协议 ></a>
<a href="javascript: void(0);" class="protocol-btn fl">{% trans '用户协议 >' %}</a>
<!-- {% endif %} -->
<a href="{{ reset_password_url }}" class="password-btn fr" target="_blank">忘记密码?</a>
<a href="{{ forget_password_url }}" class="password-btn fr" target="_blank">{% trans '忘记密码?' %}</a>
</div>
<div class="language-switcher">
<p class="language-item active">
Expand All @@ -93,42 +93,42 @@
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected="selected"{% endif %}>
{{ language.name_local }}
<option class="language-item" value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected="selected"{% endif %}>
<span class="text-active">{{ language.name_local }}</span>
</option>
{% endfor %}
</select>
<a href="javascript: void(0);">
<img class="{% if LANGUAGE_CODE == 'en' %} en {% endif %}" src="{{STATIC_URL}}{% trans 'img/logo/btn_cn.png' %}" />
</a>
</form> -->
</a> -->
</form>
</div>
</div>
</form>
</div>
</div>
<footer class="footer">
<p>
<a id="contact_us" class="link">QQ群支持(495299374)</a>
| <a href="https://bk.tencent.com/s-mart/community/" target="_blank" hotrep="hp.footer.feedback" class="link">社区论坛</a>
| <a href="http://bk.tencent.com/" target="_blank" hotrep="hp.footer.feedback" class="link">产品官网</a>
|<a class="follow-us" href="###">关注我们</a>
<a id="contact_us" class="link">{% trans 'QQ群支持' %}(495299374)</a>
| <a href="https://bk.tencent.com/s-mart/community/" target="_blank" hotrep="hp.footer.feedback" class="link">{% trans '社区论坛' %}</a>
| <a href="http://bk.tencent.com/" target="_blank" hotrep="hp.footer.feedback" class="link">{% trans '产品官网' %}</a>
|<a class="follow-us" href="###">{% trans '关注我们' %}</a>
</p>
<p>Copyright © 2012-{{NOW.year}} Tencent BlueKing. All Rights Reserved.</p>
<p>蓝鲸智云 版权所有</p>
<p>{% trans '蓝鲸智云 版权所有' %}</p>
</footer>
</div>
<!-- 查看用户协议 -->
{% include "account/agreement.part" %}
<!-- 浏览器验证 -->
<div class="error-message-content is-chrome">
<span>您的浏览器非Chrome,建议您使用最新版本的Chrome浏览,以保证最好的体验效果</span><i class="bk-icon icon-close-circle-shape" id="close-chrome"></i>
<span>{% trans '您的浏览器非Chrome,建议您使用最新版本的Chrome浏览,以保证最好的体验效果' %}</span><i class="bk-icon icon-close-circle-shape" id="close-chrome"></i>
</div>
</body>
<!-- js 国际化 -->

<script type="text/javascript" src="{{SITE_URL}}jsi18n/i18n/"></script>

<script src="{{STATIC_URL}}assets/jquery-1.10.2.min.js"></script>
<script src="{{STATIC_URL}}js_ce/login.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/particlesjs/2.2.3/particles.min.js"></script>
Expand Down
80 changes: 0 additions & 80 deletions src/login/bklogin/templates/account/login_ce_i18n.html

This file was deleted.

15 changes: 6 additions & 9 deletions src/login/bklogin/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<packages>\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<packages>\S+?)/$", JavaScriptCatalog.as_view(), name="javascript-catalog"),
]


from django.contrib.staticfiles.urls import staticfiles_urlpatterns # noqa
Expand Down
1 change: 0 additions & 1 deletion src/login/static/js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ $(document).ready(function(){
setTimeout(function(){
$("#language-form").submit();
}, 500);

});

// 点击查看协议
Expand Down
30 changes: 13 additions & 17 deletions src/login/static/js_ce/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down