Skip to content

Commit

Permalink
Merge pull request TencentBlueKing#183 from IMBlues/development
Browse files Browse the repository at this point in the history
refactor: 修正社区版登录页面国际化功能
  • Loading branch information
IMBlues authored Dec 6, 2021
2 parents 376c726 + e718089 commit 91bd33c
Show file tree
Hide file tree
Showing 8 changed files with 1,057 additions and 1,367 deletions.
12 changes: 9 additions & 3 deletions src/api/bkuser_core/profiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,15 @@ def login(self, request):
logger.exception("check profile<%s> failed", profile.username)
raise error_codes.PASSWORD_ERROR

self._check_password_status(request, profile, config_loader, time_aware_now)

create_profile_log(profile=profile, operation="LogIn", request=request, params={"is_success": True})
return Response(data=local_serializers.ProfileSerializer(profile, context={"request": request}).data)

def _check_password_status(
self, request, profile: Profile, config_loader: ConfigProvider, time_aware_now: datetime.datetime
):
"""当密码校验成功后,检查用户密码状态"""
# 密码状态校验:初始密码未修改
# 暂时跳过判断 admin,考虑在 login 模块未升级替换时,admin 可以在 SaaS 配置中关掉该特性
if (
Expand Down Expand Up @@ -649,9 +658,6 @@ def login(self, request):

raise error_codes.PASSWORD_EXPIRED.format(data=self._generate_reset_passwd_url_with_token(profile))

create_profile_log(profile=profile, operation="LogIn", request=request, params={"is_success": True})
return Response(data=local_serializers.ProfileSerializer(profile, context={"request": request}).data)

@staticmethod
def _generate_reset_passwd_url_with_token(profile: Profile) -> dict:
data = {}
Expand Down
59 changes: 29 additions & 30 deletions src/login/bklogin/templates/account/login_ce.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@
<div class="login-from">
<div class="logo-title">
<div class="logo_ce">
<img src="{{STATIC_URL}}img/logo_ce/logo_ce.png" alt="">
<img src="{{STATIC_URL}}{% trans 'img/logo_ce/logo_ce.png' %}" alt="">
</div>
<div>
<span class="title">{% trans '社区版' %}</span>
<img src="{{STATIC_URL}}/img/logo_ce/v7.png" alt="">
</div>
</div>
<div class="from-detail">
<form action="{{ app_path }}" method="post" id="login-form" onsubmit="return refresh_token()">{% csrf_token %}
<div class="form-login">
<div class="form-login">
<form action="{{ app_path }}" method="post" id="login-form" onsubmit="return refresh_token()">{% csrf_token %}
<div class="user group-control">
<i class="bk-icon icon-user"></i>
<input id="user" type="text" name="username" placeholder={% trans "请输入用户名" %}>
<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={% trans "请输入密码" %}>
<input class="password" id="password" type="password" name="password" value="" placeholder="{% trans '请输入密码' %}">
</div>
<p class="change-password">
{% if error_message %}
Expand All @@ -79,32 +79,31 @@
<!-- {% endif %} -->
<a href="{{ forget_password_url }}" class="password-btn fr" target="_blank">{% trans '忘记密码?' %}</a>
</div>
<div class="language-switcher">
<p class="language-item active">
<span id="ch" class="text-active">中文</span>
</p>
<p class="language-item">
<span id="en" class="text-active">English</span>
</p>
<!-- <form id="language-form" action="{{SITE_URL}}i18n/setlang/" method="post">{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}" />
<select name="language" style="display: none;">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<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>
</div>
</form>
<div class="language-switcher">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
<form id="language-form" action="{{SITE_URL}}i18n/setlang/" method="post">{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}" />
<select name="language" style="display: none;">
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected="selected"{% endif %}>
{{ language.name_local }}
</option>
{% endfor %}
</select>
<div class="language-select" style="display: flex">
<p class="language-item {% if LANGUAGE_CODE == 'zh-hans' %} active {% endif %}" >
<span id="ch" class="text-active">中文</span>
</p>
<p class="language-item {% if LANGUAGE_CODE == 'en' %} active {% endif %}">
<span id="en" class="text-active">English</span>
</p>
</div>
</form>
</form>
</div>
</div>
</div>
</div>
<footer class="footer">
Expand Down
2 changes: 1 addition & 1 deletion src/login/bklogin/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
# 无登录态下切换语言
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"),
url(r"^jsi18n/", JavaScriptCatalog.as_view(), name="javascript-catalog"),
]


Expand Down
Loading

0 comments on commit 91bd33c

Please sign in to comment.