mirror of https://github.com/jumpserver/jumpserver
perf: Update confirmation backend definitions to use ConfirmType
parent
96a0cbc35d
commit
ff9ad2680f
|
@ -3,3 +3,4 @@ from .password import ConfirmPassword
|
|||
from .relogin import ConfirmReLogin
|
||||
|
||||
CONFIRM_BACKENDS = [ConfirmReLogin, ConfirmPassword, ConfirmMFA]
|
||||
CONFIRM_BACKEND_MAP = {backend.name: backend for backend in CONFIRM_BACKENDS}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
from users.models import User
|
||||
|
||||
from .base import BaseConfirm
|
||||
from ..const import ConfirmType
|
||||
|
||||
|
||||
class ConfirmMFA(BaseConfirm):
|
||||
name = 'mfa'
|
||||
display_name = 'MFA'
|
||||
name = ConfirmType.MFA.value
|
||||
display_name = ConfirmType.MFA.name
|
||||
|
||||
def check(self):
|
||||
return self.user.active_mfa_backends and self.user.mfa_enabled
|
||||
|
|
|
@ -2,11 +2,12 @@ from django.utils.translation import gettext_lazy as _
|
|||
|
||||
from authentication.mixins import authenticate
|
||||
from .base import BaseConfirm
|
||||
from ..const import ConfirmType
|
||||
|
||||
|
||||
class ConfirmPassword(BaseConfirm):
|
||||
name = 'password'
|
||||
display_name = _('Password')
|
||||
name = ConfirmType.PASSWORD.value
|
||||
display_name = ConfirmType.PASSWORD.name
|
||||
|
||||
def check(self):
|
||||
return self.user.is_password_authenticate()
|
||||
|
|
|
@ -4,6 +4,7 @@ from django.utils import timezone
|
|||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .base import BaseConfirm
|
||||
from ..const import ConfirmType
|
||||
|
||||
SPECIFIED_TIME = 5
|
||||
|
||||
|
@ -11,8 +12,8 @@ RELOGIN_ERROR = _('Login time has exceeded {} minutes, please login again').form
|
|||
|
||||
|
||||
class ConfirmReLogin(BaseConfirm):
|
||||
name = 'relogin'
|
||||
display_name = 'Re-Login'
|
||||
name = ConfirmType.RELOGIN.value
|
||||
display_name = ConfirmType.RELOGIN.name
|
||||
|
||||
def check(self):
|
||||
return not self.user.is_password_authenticate()
|
||||
|
|
|
@ -1,19 +1,14 @@
|
|||
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
|
||||
|
||||
RSA_PRIVATE_KEY = 'rsa_private_key'
|
||||
RSA_PUBLIC_KEY = 'rsa_public_key'
|
||||
|
||||
CONFIRM_BACKEND_MAP = {backend.name: backend for backend in CONFIRM_BACKENDS}
|
||||
|
||||
|
||||
class ConfirmType(TextChoices):
|
||||
RELOGIN = ConfirmReLogin.name, ConfirmReLogin.display_name
|
||||
PASSWORD = ConfirmPassword.name, ConfirmPassword.display_name
|
||||
MFA = ConfirmMFA.name, ConfirmMFA.display_name
|
||||
RELOGIN = 'relogin', 'Re-Login'
|
||||
PASSWORD = 'password', _('Password')
|
||||
MFA = 'mfa', 'MFA'
|
||||
|
||||
@classmethod
|
||||
def get_can_confirm_types(cls, confirm_type):
|
||||
|
@ -24,6 +19,7 @@ class ConfirmType(TextChoices):
|
|||
|
||||
@classmethod
|
||||
def get_prop_backends(cls, confirm_type):
|
||||
from authentication.confirm import CONFIRM_BACKEND_MAP
|
||||
types = cls.get_can_confirm_types(confirm_type)
|
||||
backend_classes = [
|
||||
CONFIRM_BACKEND_MAP[tp]
|
||||
|
|
Loading…
Reference in New Issue