fix: ukey login user deactive error no tips

This commit is contained in:
Bai
2026-06-15 11:35:49 +08:00
parent f87248154b
commit 5322bcbde8
2 changed files with 5 additions and 6 deletions

View File

@@ -5,7 +5,6 @@ from urllib.parse import urlencode
from django.conf import settings
from django.contrib.auth import authenticate
from django.contrib import messages
from django.core.cache import cache
from django.utils.decorators import method_decorator
from django.utils.translation import gettext as _
@@ -27,6 +26,7 @@ from .sdk import ukey_sdk_config
__all__ = ['UKeyLoginView']
_CHALLENGE_CACHE_KEY_PREFIX = 'ukey_login_challenge'
_UKEY_ERROR_SESSION_KEY = 'ukey_login_error'
@method_decorator(sensitive_post_parameters(), name='dispatch')
@method_decorator(csrf_protect, name='dispatch')
@@ -79,6 +79,7 @@ class UKeyLoginView(AuthMixin, FormView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['challenge'] = self._generate_and_store_challenge()
context['error_msg'] = self.request.session.pop(_UKEY_ERROR_SESSION_KEY, '')
return context
def form_valid(self, form):
@@ -155,7 +156,7 @@ class UKeyLoginView(AuthMixin, FormView):
return field_name
def get_failed_response(self, form, username, error_msg):
messages.error(self.request, error_msg)
self.request.session[_UKEY_ERROR_SESSION_KEY] = str(error_msg or _('Unknown'))
self.send_auth_signal(success=False, reason=error_msg, username=username)
return redirect(self._build_login_redirect_url())

View File

@@ -202,11 +202,9 @@
<form id="ukey-login-form" autocomplete="off" action="" method="post" role="form" novalidate="novalidate">
{% csrf_token %}
{% if messages %}
{% if error_msg %}
<div style="margin-bottom: 16px;">
{% for message in messages %}
<p class="help-block red-fonts">{% trans "Error" %}: {{ message }}</p>
{% endfor %}
<p class="help-block red-fonts">{% trans "Error" %}: {{ error_msg }}</p>
</div>
{% endif %}