2021-11-10 03:30:48 +00:00
|
|
|
from django.conf import settings
|
2023-07-24 03:52:25 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2021-11-10 03:30:48 +00:00
|
|
|
|
|
|
|
from .base import BaseMFA
|
|
|
|
from ..backends.radius import RadiusBackend
|
|
|
|
|
|
|
|
mfa_failed_msg = _("Radius verify code invalid")
|
|
|
|
|
|
|
|
|
|
|
|
class MFARadius(BaseMFA):
|
|
|
|
name = 'otp_radius'
|
2021-11-15 10:36:22 +00:00
|
|
|
display_name = 'Radius'
|
|
|
|
placeholder = _("Radius verification code")
|
2021-11-10 03:30:48 +00:00
|
|
|
|
|
|
|
def check_code(self, code):
|
|
|
|
assert self.is_authenticated()
|
|
|
|
backend = RadiusBackend()
|
|
|
|
username = self.user.username
|
|
|
|
user = backend.authenticate(
|
|
|
|
None, username=username, password=code
|
|
|
|
)
|
|
|
|
ok = user is not None
|
|
|
|
msg = '' if ok else mfa_failed_msg
|
|
|
|
return ok, msg
|
|
|
|
|
|
|
|
def is_active(self):
|
|
|
|
return True
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def global_enabled():
|
|
|
|
return settings.OTP_IN_RADIUS
|
|
|
|
|
|
|
|
def get_enable_url(self) -> str:
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def can_disable(self):
|
|
|
|
return False
|
|
|
|
|
|
|
|
def disable(self):
|
|
|
|
return ''
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def help_text_of_disable():
|
|
|
|
return _("Radius global enabled, cannot disable")
|
|
|
|
|
|
|
|
def get_disable_url(self) -> str:
|
|
|
|
return ''
|