From 96a0cbc35da457e1dcf93c1c308e6fb362b58871 Mon Sep 17 00:00:00 2001 From: Bai Date: Mon, 24 Feb 2025 20:08:06 +0800 Subject: [PATCH] fix: import error --- apps/authentication/const.py | 12 ++++++------ apps/authentication/mfa/custom.py | 5 +++-- apps/authentication/mfa/face.py | 5 +++-- apps/authentication/mfa/otp.py | 5 +++-- apps/authentication/mfa/radius.py | 5 +++-- apps/authentication/mfa/sms.py | 5 +++-- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/apps/authentication/const.py b/apps/authentication/const.py index 5ecabb045..19eec0c1f 100644 --- a/apps/authentication/const.py +++ b/apps/authentication/const.py @@ -1,8 +1,8 @@ from django.db.models import TextChoices +from django.utils.translation import gettext_lazy as _ from authentication.confirm import CONFIRM_BACKENDS from .confirm import ConfirmMFA, ConfirmPassword, ConfirmReLogin -from .mfa import MFAOtp, MFASms, MFARadius, MFAFace, MFACustom RSA_PRIVATE_KEY = 'rsa_private_key' RSA_PUBLIC_KEY = 'rsa_public_key' @@ -33,11 +33,11 @@ class ConfirmType(TextChoices): class MFAType(TextChoices): - OTP = MFAOtp.name, MFAOtp.display_name - SMS = MFASms.name, MFASms.display_name - Face = MFAFace.name, MFAFace.display_name - Radius = MFARadius.name, MFARadius.display_name - Custom = MFACustom.name, MFACustom.display_name + OTP = 'otp', _('OTP') + SMS = 'sms', _('SMS') + Face = 'face', _('Face Recognition') + Radius = 'otp_radius', _('Radius') + Custom = 'mfa_custom', _('Custom') FACE_CONTEXT_CACHE_KEY_PREFIX = "FACE_CONTEXT" diff --git a/apps/authentication/mfa/custom.py b/apps/authentication/mfa/custom.py index 70ceaf34c..455b852f3 100644 --- a/apps/authentication/mfa/custom.py +++ b/apps/authentication/mfa/custom.py @@ -4,6 +4,7 @@ from django.utils.translation import gettext_lazy as _ from common.utils import get_logger from .base import BaseMFA +from ..const import MFAType logger = get_logger(__file__) @@ -21,8 +22,8 @@ custom_failed_msg = _("MFA Custom code invalid") class MFACustom(BaseMFA): - name = 'mfa_custom' - display_name = 'Custom' + name = MFAType.Custom.value + display_name = MFAType.Custom.name placeholder = _("MFA custom verification code") def check_code(self, code): diff --git a/apps/authentication/mfa/face.py b/apps/authentication/mfa/face.py index 62acb99ce..4edf46655 100644 --- a/apps/authentication/mfa/face.py +++ b/apps/authentication/mfa/face.py @@ -3,11 +3,12 @@ from django.utils.translation import gettext_lazy as _ from authentication.mfa.base import BaseMFA from authentication.mixins import AuthFaceMixin +from ..const import MFAType class MFAFace(BaseMFA, AuthFaceMixin): - name = "face" - display_name = _('Face Recognition') + name = MFAType.Face.value + display_name = MFAType.Face.name placeholder = 'Face Recognition' def check_code(self, code): diff --git a/apps/authentication/mfa/otp.py b/apps/authentication/mfa/otp.py index 912978d25..fc7decee1 100644 --- a/apps/authentication/mfa/otp.py +++ b/apps/authentication/mfa/otp.py @@ -2,14 +2,15 @@ from django.utils.translation import gettext_lazy as _ from django.shortcuts import reverse from .base import BaseMFA +from ..const import MFAType otp_failed_msg = _("OTP code invalid, or server time error") class MFAOtp(BaseMFA): - name = 'otp' - display_name = _('OTP') + name = MFAType.OTP.value + display_name = MFAType.OTP.name placeholder = _('OTP verification code') def check_code(self, code): diff --git a/apps/authentication/mfa/radius.py b/apps/authentication/mfa/radius.py index 5f6c7ddc8..8b24897bd 100644 --- a/apps/authentication/mfa/radius.py +++ b/apps/authentication/mfa/radius.py @@ -3,13 +3,14 @@ from django.utils.translation import gettext_lazy as _ from .base import BaseMFA from ..backends.radius import RadiusBackend +from ..const import MFAType mfa_failed_msg = _("Radius verify code invalid") class MFARadius(BaseMFA): - name = 'otp_radius' - display_name = 'Radius' + name = MFAType.Radius.value + display_name = MFAType.Radius.name placeholder = _("Radius verification code") def check_code(self, code=None): diff --git a/apps/authentication/mfa/sms.py b/apps/authentication/mfa/sms.py index f88e56d35..218931584 100644 --- a/apps/authentication/mfa/sms.py +++ b/apps/authentication/mfa/sms.py @@ -4,13 +4,14 @@ from django.utils.translation import gettext_lazy as _ from common.utils.verify_code import SendAndVerifyCodeUtil from users.serializers import SmsUserSerializer from .base import BaseMFA +from ..const import MFAType sms_failed_msg = _("SMS verify code invalid") class MFASms(BaseMFA): - name = 'sms' - display_name = _("SMS") + name = MFAType.SMS.value + display_name = MFAType.SMS.name placeholder = _("SMS verification code") def __init__(self, user):