From f92c557235d5ddb2ad6861877f1ac0deaca78db5 Mon Sep 17 00:00:00 2001 From: Aaron3S Date: Tue, 19 Nov 2024 19:30:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E4=BA=BA=E8=84=B8?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E8=B6=85=E6=97=B6=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/mixins.py | 8 ++++++++ apps/authentication/serializers/password_mfa.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/authentication/mixins.py b/apps/authentication/mixins.py index 5f1676f86..c00335ec0 100644 --- a/apps/authentication/mixins.py +++ b/apps/authentication/mixins.py @@ -226,12 +226,20 @@ class MFAFaceMixin: def is_context_finished(context): return context.get('is_finished', False) + @staticmethod + def is_context_success(context): + return context.get('success', False) + def get_face_code(self): context = self.get_face_recognition_context() if not self.is_context_finished(context): raise RuntimeError("Face recognition is not yet completed.") + if not self.is_context_success(context): + msg = context.get('error_message', '') + raise RuntimeError("Face recognition failed,{}".format(msg)) + face_code = context.get('face_code') if not face_code: raise ValueError("Face code is missing from the context.") diff --git a/apps/authentication/serializers/password_mfa.py b/apps/authentication/serializers/password_mfa.py index accf24a89..826fdfdcc 100644 --- a/apps/authentication/serializers/password_mfa.py +++ b/apps/authentication/serializers/password_mfa.py @@ -58,7 +58,7 @@ class MFAFaceCallbackSerializer(serializers.Serializer): token = serializers.CharField(required=True, allow_blank=False) success = serializers.BooleanField(required=True, allow_null=False) error_message = serializers.CharField(required=False, allow_null=True, allow_blank=True) - face_code = serializers.CharField(required=True) + face_code = serializers.CharField(required=False, allow_null=True, allow_blank=True) def update(self, instance, validated_data): pass