mirror of https://github.com/jumpserver/jumpserver
feat: move face setiing to profile
parent
35a1655905
commit
4036420d0e
|
@ -1,7 +1,4 @@
|
||||||
from django.core.cache import cache
|
|
||||||
|
|
||||||
from authentication.mfa.base import BaseMFA
|
from authentication.mfa.base import BaseMFA
|
||||||
from django.shortcuts import reverse
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from authentication.mixins import MFAFaceMixin
|
from authentication.mixins import MFAFaceMixin
|
||||||
|
@ -39,10 +36,10 @@ class MFAFace(BaseMFA, MFAFaceMixin):
|
||||||
and settings.FACE_RECOGNITION_ENABLED
|
and settings.FACE_RECOGNITION_ENABLED
|
||||||
|
|
||||||
def get_enable_url(self) -> str:
|
def get_enable_url(self) -> str:
|
||||||
return reverse('authentication:user-face-enable')
|
return '/ui/#/profile/index'
|
||||||
|
|
||||||
def get_disable_url(self) -> str:
|
def get_disable_url(self) -> str:
|
||||||
return reverse('authentication:user-face-disable')
|
return '/ui/#/profile/index'
|
||||||
|
|
||||||
def disable(self):
|
def disable(self):
|
||||||
assert self.is_authenticated()
|
assert self.is_authenticated()
|
||||||
|
@ -54,4 +51,8 @@ class MFAFace(BaseMFA, MFAFaceMixin):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def help_text_of_enable():
|
def help_text_of_enable():
|
||||||
return _("Frontal Face Recognition")
|
return _("Bind face to enable")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def help_text_of_disable():
|
||||||
|
return _("Unbind face to disable")
|
||||||
|
|
|
@ -15,6 +15,10 @@ logger = get_logger(__file__)
|
||||||
class FaceMixin:
|
class FaceMixin:
|
||||||
face_vector = None
|
face_vector = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_face_code_set(self):
|
||||||
|
return self.face_vector is not None
|
||||||
|
|
||||||
def get_face_vector(self) -> list[float]:
|
def get_face_vector(self) -> list[float]:
|
||||||
if not self.face_vector:
|
if not self.face_vector:
|
||||||
raise ValidationError("Face vector is not set.")
|
raise ValidationError("Face vector is not set.")
|
||||||
|
|
|
@ -140,6 +140,10 @@ class UserSerializer(
|
||||||
label=_("Can public key authentication"),
|
label=_("Can public key authentication"),
|
||||||
read_only=True,
|
read_only=True,
|
||||||
)
|
)
|
||||||
|
is_face_code_set = serializers.BooleanField(
|
||||||
|
label=_("Is face code set"),
|
||||||
|
read_only=True,
|
||||||
|
)
|
||||||
password = EncryptedField(
|
password = EncryptedField(
|
||||||
label=_("Password"),
|
label=_("Password"),
|
||||||
required=False,
|
required=False,
|
||||||
|
@ -205,6 +209,7 @@ class UserSerializer(
|
||||||
"can_public_key_auth",
|
"can_public_key_auth",
|
||||||
"mfa_enabled",
|
"mfa_enabled",
|
||||||
"need_update_password",
|
"need_update_password",
|
||||||
|
"is_face_code_set",
|
||||||
]
|
]
|
||||||
# 包含不太常用的字段,可以没有
|
# 包含不太常用的字段,可以没有
|
||||||
fields_verbose = (
|
fields_verbose = (
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
from django.contrib.auth import logout as auth_logout
|
|
||||||
from django.shortcuts import redirect
|
|
||||||
from django.views.generic import FormView
|
from django.views.generic import FormView
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
@ -53,15 +51,14 @@ class UserFaceEnableView(MFAFaceMixin, UserFaceCaptureView):
|
||||||
form.add_error("code", str(e))
|
form.add_error("code", str(e))
|
||||||
return super().form_invalid(form)
|
return super().form_invalid(form)
|
||||||
|
|
||||||
auth_logout(self.request)
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
message_data = {
|
message_data = {
|
||||||
'title': _('Face recognition enable success'),
|
'title': _('Face binding successful'),
|
||||||
'message': _('Face recognition enable success, return login page'),
|
'message': _('Face binding successful'),
|
||||||
'interval': 5,
|
'interval': 2,
|
||||||
'redirect_url': reverse('authentication:login'),
|
'redirect_url': '/ui/#/profile/index'
|
||||||
}
|
}
|
||||||
url = FlashMessageUtil.gen_message_url(message_data)
|
url = FlashMessageUtil.gen_message_url(message_data)
|
||||||
return url
|
return url
|
||||||
|
@ -77,16 +74,14 @@ class UserFaceDisableView(UserFaceCaptureView):
|
||||||
except (errors.MFAFailedError, errors.BlockMFAError) as e:
|
except (errors.MFAFailedError, errors.BlockMFAError) as e:
|
||||||
form.add_error('code', e.msg)
|
form.add_error('code', e.msg)
|
||||||
return super().form_invalid(form)
|
return super().form_invalid(form)
|
||||||
|
|
||||||
auth_logout(self.request)
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
message_data = {
|
message_data = {
|
||||||
'title': _('Face recognition disable success'),
|
'title': _('Face unbinding successful'),
|
||||||
'message': _('Face recognition disable success, return login page'),
|
'message': _('Face unbinding successful'),
|
||||||
'interval': 5,
|
'interval': 2,
|
||||||
'redirect_url': reverse('authentication:login'),
|
'redirect_url': '/ui/#/profile/index'
|
||||||
}
|
}
|
||||||
url = FlashMessageUtil.gen_message_url(message_data)
|
url = FlashMessageUtil.gen_message_url(message_data)
|
||||||
return url
|
return url
|
||||||
|
|
Loading…
Reference in New Issue