From 5eeff0aabfbc74060138b76260be2d89e19ff88e Mon Sep 17 00:00:00 2001 From: Aaron3S Date: Tue, 19 Nov 2024 17:31:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=BE=E7=BD=AE=E4=BA=BA=E8=84=B8?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=96=87=E5=AD=98=E6=B4=BB=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/api/mfa.py | 6 +++--- apps/authentication/const.py | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/authentication/api/mfa.py b/apps/authentication/api/mfa.py index 4ba5665d4..c02970608 100644 --- a/apps/authentication/api/mfa.py +++ b/apps/authentication/api/mfa.py @@ -18,7 +18,7 @@ from common.utils import get_logger from users.models.user import User from .. import errors from .. import serializers -from ..const import MFA_FACE_CONTEXT_CACHE_KEY_PREFIX, MFA_FACE_SESSION_KEY +from ..const import MFA_FACE_CONTEXT_CACHE_KEY_PREFIX, MFA_FACE_SESSION_KEY, MFA_FACE_CONTEXT_CACHE_TTL from ..errors import SessionEmptyError from ..mixins import AuthMixin @@ -74,7 +74,7 @@ class MFAFaceCallbackApi(AuthMixin, CreateAPIView): def _update_cache(self, context): cache_key = self.get_face_cache_key(context['token']) - cache.set(cache_key, context, 3600) + cache.set(cache_key, context, MFA_FACE_CONTEXT_CACHE_TTL) def _handle_success(self, context, face_code): context.update({ @@ -100,7 +100,7 @@ class MFAFaceContextApi(AuthMixin, RetrieveAPIView, CreateAPIView): "token": token, "is_finished": False } - cache.set(cache_key, face_context) + cache.set(cache_key, face_context, MFA_FACE_CONTEXT_CACHE_TTL) self.request.session[self.face_token_session_key] = token return token diff --git a/apps/authentication/const.py b/apps/authentication/const.py index 1a27889f1..927f6d204 100644 --- a/apps/authentication/const.py +++ b/apps/authentication/const.py @@ -41,4 +41,5 @@ class MFAType(TextChoices): MFA_FACE_CONTEXT_CACHE_KEY_PREFIX = "MFA_FACE_RECOGNITION_CONTEXT" +MFA_FACE_CONTEXT_CACHE_TTL = 60 MFA_FACE_SESSION_KEY = "mfa_face_token"