From 91a1da57e9bcf0f0f157eb28c1200ec79ced43fc Mon Sep 17 00:00:00 2001
From: feng <1304903146@qq.com>
Date: Tue, 28 May 2024 16:09:22 +0800
Subject: [PATCH] perf: mfa interface optimization, mobile phone number can be
empty
---
apps/authentication/mfa/sms.py | 6 +-
apps/common/const/choices.py | 6 +-
apps/common/serializers/fields.py | 22 +-
apps/common/validators.py | 3 +
apps/static/css/otp.css | 4 +-
apps/templates/_mfa_login_field.html | 7 +-
apps/templates/_without_nav_base.html | 2 +-
apps/users/notifications.py | 2 +-
apps/users/templates/users/mfa_setting.html | 267 ++++++++++++++------
9 files changed, 215 insertions(+), 104 deletions(-)
diff --git a/apps/authentication/mfa/sms.py b/apps/authentication/mfa/sms.py
index d114b648e..7cf71985e 100644
--- a/apps/authentication/mfa/sms.py
+++ b/apps/authentication/mfa/sms.py
@@ -44,13 +44,13 @@ class MFASms(BaseMFA):
return settings.SMS_ENABLED
def get_enable_url(self) -> str:
- return '/ui/#/profile/setting?activeTab=ProfileUpdate'
+ return '/ui/#/profile/index'
def can_disable(self) -> bool:
return True
def disable(self):
- return '/ui/#/profile/setting?activeTab=ProfileUpdate'
+ return '/ui/#/profile/index'
@staticmethod
def help_text_of_enable():
@@ -61,4 +61,4 @@ class MFASms(BaseMFA):
return _("Clear phone number to disable")
def get_disable_url(self) -> str:
- return '/ui/#/profile/setting?activeTab=ProfileUpdate'
+ return '/ui/#/profile/index'
diff --git a/apps/common/const/choices.py b/apps/common/const/choices.py
index ee8519c34..86f0f00db 100644
--- a/apps/common/const/choices.py
+++ b/apps/common/const/choices.py
@@ -26,10 +26,12 @@ COUNTRY_CALLING_CODES = [
{'name': 'HongKong(中国香港)', 'value': '+852'},
{'name': 'Macao(中国澳门)', 'value': '+853'},
{'name': 'Taiwan(中国台湾)', 'value': '+886'},
- {'name': 'America(America)', 'value': '+1'}, {'name': 'Russia(Россия)', 'value': '+7'},
+ {'name': 'America(America)', 'value': '+1'},
+ {'name': 'Russia(Россия)', 'value': '+7'},
{'name': 'France(français)', 'value': '+33'},
{'name': 'Britain(Britain)', 'value': '+44'},
{'name': 'Germany(Deutschland)', 'value': '+49'},
- {'name': 'Japan(日本)', 'value': '+81'}, {'name': 'Korea(한국)', 'value': '+82'},
+ {'name': 'Japan(日本)', 'value': '+81'},
+ {'name': 'Korea(한국)', 'value': '+82'},
{'name': 'India(भारत)', 'value': '+91'}
]
diff --git a/apps/common/serializers/fields.py b/apps/common/serializers/fields.py
index 282394106..d8cf420c1 100644
--- a/apps/common/serializers/fields.py
+++ b/apps/common/serializers/fields.py
@@ -251,21 +251,21 @@ class PhoneField(serializers.CharField):
data = '+{}{}'.format(code, phone)
else:
data = phone
- try:
- phone = phonenumbers.parse(data, 'CN')
- data = '+{}{}'.format(phone.country_code, phone.national_number)
- except phonenumbers.NumberParseException:
- data = '+86{}'.format(data)
+ if data:
+ try:
+ phone = phonenumbers.parse(data, 'CN')
+ data = '+{}{}'.format(phone.country_code, phone.national_number)
+ except phonenumbers.NumberParseException:
+ data = '+86{}'.format(data)
return super().to_internal_value(data)
def to_representation(self, value):
- if value:
- try:
- phone = phonenumbers.parse(value, 'CN')
- value = {'code': '+%s' % phone.country_code, 'phone': phone.national_number}
- except phonenumbers.NumberParseException:
- value = {'code': '+86', 'phone': value}
+ try:
+ phone = phonenumbers.parse(value, 'CN')
+ value = {'code': '+%s' % phone.country_code, 'phone': phone.national_number}
+ except phonenumbers.NumberParseException:
+ value = {'code': '+86', 'phone': value}
return value
diff --git a/apps/common/validators.py b/apps/common/validators.py
index 7e33d7d76..a926ef9dc 100644
--- a/apps/common/validators.py
+++ b/apps/common/validators.py
@@ -47,6 +47,9 @@ class PhoneValidator:
message = _('The mobile phone number format is incorrect')
def __call__(self, value):
+ if not value:
+ return
+
try:
phone = phonenumbers.parse(value, 'CN')
valid = phonenumbers.is_valid_number(phone)
diff --git a/apps/static/css/otp.css b/apps/static/css/otp.css
index 67608d309..6c2883510 100644
--- a/apps/static/css/otp.css
+++ b/apps/static/css/otp.css
@@ -23,8 +23,8 @@ button{
/*header样式*/
header{
overflow:hidden ;
- background: #dedede;
- padding:15px 200px;
+ background: #ffffff;
+ padding:15px 10%;
}
header .logo a{
float:left;
diff --git a/apps/templates/_mfa_login_field.html b/apps/templates/_mfa_login_field.html
index 463e5732e..782f98f00 100644
--- a/apps/templates/_mfa_login_field.html
+++ b/apps/templates/_mfa_login_field.html
@@ -25,7 +25,7 @@
{% endif %}
@@ -39,15 +39,14 @@
}
.challenge-required .input-style {
- width: calc(100% - 160px);
+ width: calc(100% - 104px);
display: inline-block;
}
.btn-challenge {
- width: 156px !important;
+ width: 100px !important;
height: 100%;
vertical-align: top;
- padding: 8px 12px;
}
{% endblock %}