From 5b4de02fff6de41905cbc9d32bf168ee7c29426e Mon Sep 17 00:00:00 2001 From: Aaron3S Date: Tue, 19 Nov 2024 17:06:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E5=A4=B1=E8=B4=A5=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/i18n/core/en/LC_MESSAGES/django.po | 18 +++++++++++- apps/i18n/core/ja/LC_MESSAGES/django.po | 26 +++++++++++++++- apps/i18n/core/zh/LC_MESSAGES/django.po | 18 +++++++++++- apps/i18n/core/zh_Hant/LC_MESSAGES/django.po | 26 +++++++++++++++- apps/users/views/profile/face.py | 31 +++++++++++++++++--- 5 files changed, 111 insertions(+), 8 deletions(-) diff --git a/apps/i18n/core/en/LC_MESSAGES/django.po b/apps/i18n/core/en/LC_MESSAGES/django.po index 13c8cb362..a3bab146b 100644 --- a/apps/i18n/core/en/LC_MESSAGES/django.po +++ b/apps/i18n/core/en/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-11-19 15:05+0800\n" +"POT-Creation-Date: 2024-11-19 16:36+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -9484,6 +9484,22 @@ msgstr "" msgid "Redirecting to JumpServer Client" msgstr "" +#: users/views/profile/face.py:54 +msgid "Face recognition enable success" +msgstr "" + +#: users/views/profile/face.py:55 +msgid "Face recognition enable success, return login page" +msgstr "" + +#: users/views/profile/face.py:78 +msgid "Face recognition disable success" +msgstr "" + +#: users/views/profile/face.py:79 +msgid "Face recognition disable success, return login page" +msgstr "" + #: users/views/profile/otp.py:106 msgid "Already bound" msgstr "" diff --git a/apps/i18n/core/ja/LC_MESSAGES/django.po b/apps/i18n/core/ja/LC_MESSAGES/django.po index e41e43b20..0238232a6 100644 --- a/apps/i18n/core/ja/LC_MESSAGES/django.po +++ b/apps/i18n/core/ja/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-11-19 15:05+0800\n" +"POT-Creation-Date: 2024-11-19 16:36+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -9984,6 +9984,30 @@ msgstr "認証データベース" msgid "Redirecting to JumpServer Client" msgstr "" +#: users/views/profile/face.py:54 +#, fuzzy +#| msgid "Basic edition" +msgid "Face recognition enable success" +msgstr "エンタープライズ基本版" + +#: users/views/profile/face.py:55 +#, fuzzy +#| msgid "OTP enable success, return login page" +msgid "Face recognition enable success, return login page" +msgstr "OTP有効化成功、ログインページを返す" + +#: users/views/profile/face.py:78 +#, fuzzy +#| msgid "OTP disable success" +msgid "Face recognition disable success" +msgstr "OTP無効化成功" + +#: users/views/profile/face.py:79 +#, fuzzy +#| msgid "OTP disable success, return login page" +msgid "Face recognition disable success, return login page" +msgstr "OTP無効化成功、ログインページを返す" + #: users/views/profile/otp.py:106 msgid "Already bound" msgstr "すでにバインド済み" diff --git a/apps/i18n/core/zh/LC_MESSAGES/django.po b/apps/i18n/core/zh/LC_MESSAGES/django.po index fba74ef49..cf7f059c6 100644 --- a/apps/i18n/core/zh/LC_MESSAGES/django.po +++ b/apps/i18n/core/zh/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: JumpServer 0.3.3\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-11-19 15:05+0800\n" +"POT-Creation-Date: 2024-11-19 16:36+0800\n" "PO-Revision-Date: 2021-05-20 10:54+0800\n" "Last-Translator: ibuler \n" "Language-Team: JumpServer team\n" @@ -9710,6 +9710,22 @@ msgstr "认证成功" msgid "Redirecting to JumpServer Client" msgstr "" +#: users/views/profile/face.py:54 +msgid "Face recognition enable success" +msgstr "MFA(人脸识别) 开启成功" + +#: users/views/profile/face.py:55 +msgid "Face recognition enable success, return login page" +msgstr "MFA(人脸识别) 启用成功,返回到登录页面" + +#: users/views/profile/face.py:78 +msgid "Face recognition disable success" +msgstr "MFA(人脸识别) 禁用成功" + +#: users/views/profile/face.py:79 +msgid "Face recognition disable success, return login page" +msgstr "MFA(人脸识别) 禁用成功,返回登录页面" + #: users/views/profile/otp.py:106 msgid "Already bound" msgstr "已经绑定" diff --git a/apps/i18n/core/zh_Hant/LC_MESSAGES/django.po b/apps/i18n/core/zh_Hant/LC_MESSAGES/django.po index bbbcec23b..dae3c1509 100644 --- a/apps/i18n/core/zh_Hant/LC_MESSAGES/django.po +++ b/apps/i18n/core/zh_Hant/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: JumpServer 0.3.3\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-11-19 15:05+0800\n" +"POT-Creation-Date: 2024-11-19 16:36+0800\n" "PO-Revision-Date: 2021-05-20 10:54+0800\n" "Last-Translator: ibuler \n" "Language-Team: JumpServer team\n" @@ -9741,6 +9741,30 @@ msgstr "認證資料庫" msgid "Redirecting to JumpServer Client" msgstr "" +#: users/views/profile/face.py:54 +#, fuzzy +#| msgid "Basic edition" +msgid "Face recognition enable success" +msgstr "企業基礎版" + +#: users/views/profile/face.py:55 +#, fuzzy +#| msgid "OTP enable success, return login page" +msgid "Face recognition enable success, return login page" +msgstr "MFA(OTP) 啟用成功,返回到登入頁面" + +#: users/views/profile/face.py:78 +#, fuzzy +#| msgid "OTP disable success" +msgid "Face recognition disable success" +msgstr "MFA(OTP) 禁用成功" + +#: users/views/profile/face.py:79 +#, fuzzy +#| msgid "OTP disable success, return login page" +msgid "Face recognition disable success, return login page" +msgstr "MFA(OTP) 禁用成功,返回登入頁面" + #: users/views/profile/otp.py:106 msgid "Already bound" msgstr "已經綁定" diff --git a/apps/users/views/profile/face.py b/apps/users/views/profile/face.py index c5db60623..6eb63f95f 100644 --- a/apps/users/views/profile/face.py +++ b/apps/users/views/profile/face.py @@ -2,6 +2,7 @@ from django.contrib.auth import logout as auth_logout from django.shortcuts import redirect from django.views.generic import FormView from django import forms +from django.utils.translation import gettext_lazy as _ from authentication import errors from authentication.mixins import AuthMixin, MFAFaceMixin @@ -9,6 +10,8 @@ from authentication.mixins import AuthMixin, MFAFaceMixin __all__ = ['UserFaceCaptureView', 'UserFaceEnableView', 'UserFaceDisableView'] +from common.utils import reverse, FlashMessageUtil + class UserFaceCaptureForm(forms.Form): code = forms.CharField(label='MFA Code', max_length=128, required=False) @@ -21,7 +24,7 @@ class UserFaceCaptureView(AuthMixin, FormView): code = '' def form_valid(self, form): - raise NotImplementedError + return super().form_valid(form) def get_context_data(self, **kwargs): context = super().get_context_data() @@ -44,7 +47,17 @@ class UserFaceEnableView(UserFaceCaptureView, MFAFaceMixin): user.save(update_fields=['face_vector']) auth_logout(self.request) - return redirect('authentication:login') + return super().form_valid(form) + + def get_success_url(self): + message_data = { + 'title': _('Face recognition enable success'), + 'message': _('Face recognition enable success, return login page'), + 'interval': 5, + 'redirect_url': reverse('authentication:login'), + } + url = FlashMessageUtil.gen_message_url(message_data) + return url class UserFaceDisableView(UserFaceCaptureView): @@ -54,9 +67,19 @@ class UserFaceDisableView(UserFaceCaptureView): user = self.get_user_from_session() user.face_vector = None user.save(update_fields=['face_vector']) - auth_logout(self.request) except (errors.MFAFailedError, errors.BlockMFAError) as e: form.add_error('code', e.msg) return super().form_invalid(form) - return redirect('authentication:login') + auth_logout(self.request) + return super().form_valid(form) + + def get_success_url(self): + message_data = { + 'title': _('Face recognition disable success'), + 'message': _('Face recognition disable success, return login page'), + 'interval': 5, + 'redirect_url': reverse('authentication:login'), + } + url = FlashMessageUtil.gen_message_url(message_data) + return url