perf: 优化登录提示

pull/11349/head
ibuler 2023-08-18 16:46:29 +08:00 committed by Bryan
parent 4e2c7d7aab
commit 822a124dbc
2 changed files with 24 additions and 1 deletions

View File

@ -223,10 +223,21 @@
height: 13px;
cursor: pointer;
}
.error-info {
font-size: 16px;
text-align: center;
}
</style>
</head>
<body>
{% if not origin_is_allowed %}
<div class='alert alert-danger error-info'>
配置文件存在问题无法完成登录请联系管理员解决或查看最新更新说明 <br/>
Configuration file has problems and cannot be logged in. Please contact the administrator
</div>
{% endif %}
<div class="login-content extra-fields-{{ extra_fields_count }}">
<div class="right-image-box">
<a href="{% if not XPACK_ENABLED %}https://github.com/jumpserver/jumpserver.git{% endif %}">
@ -309,7 +320,8 @@
</div>
<div class="form-group">
<button type="submit" class="btn btn-transparent" onclick="doLogin();return false;">
<button type="submit" class="btn btn-transparent" onclick="doLogin();return false;"
{% if not origin_is_allowed %} disabled {% endif %}>
{% trans 'Login' %}
</button>
</div>

View File

@ -134,6 +134,16 @@ class UserLoginContextMixin:
count += 1
return count
def origin_is_allowed(self):
from urllib.parse import urlparse
http_referer = self.request.META.get('HTTP_REFERER')
try:
referer = urlparse(http_referer)
except ValueError:
return False
allowed_domains = settings.ALLOWED_DOMAINS
return referer.netloc in allowed_domains
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context.update({
@ -143,6 +153,7 @@ class UserLoginContextMixin:
'current_lang': self.get_current_lang(),
'forgot_password_url': self.get_forgot_password_url(),
'extra_fields_count': self.get_extra_fields_count(context),
'origin_is_allowed': self.origin_is_allowed(),
**self.get_user_mfa_context(self.request.user)
})
return context