From 654ec4970ef7b1c61a625f34ca37f1a9d16635c3 Mon Sep 17 00:00:00 2001 From: xinwen Date: Thu, 9 Sep 2021 21:11:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E8=AE=BE=E7=BD=AE=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/common/message/backends/sms/__init__.py | 4 +-- apps/settings/serializers/auth/sms.py | 36 ++++++++------------ 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/apps/common/message/backends/sms/__init__.py b/apps/common/message/backends/sms/__init__.py index be32c6e94..af7a0e170 100644 --- a/apps/common/message/backends/sms/__init__.py +++ b/apps/common/message/backends/sms/__init__.py @@ -40,8 +40,8 @@ class SMS_MESSAGE(TextChoices): class BACKENDS(TextChoices): - ALIBABA = 'alibaba', _('Alibaba') - TENCENT = 'tencent', _('Tencent') + ALIBABA = 'alibaba', _('Alibaba cloud') + TENCENT = 'tencent', _('Tencent cloud') class BaseSMSClient: diff --git a/apps/settings/serializers/auth/sms.py b/apps/settings/serializers/auth/sms.py index c018720b2..2e186c07b 100644 --- a/apps/settings/serializers/auth/sms.py +++ b/apps/settings/serializers/auth/sms.py @@ -8,7 +8,12 @@ __all__ = ['SMSSettingSerializer', 'AlibabaSMSSettingSerializer', 'TencentSMSSet class SMSSettingSerializer(serializers.Serializer): SMS_ENABLED = serializers.BooleanField(default=False, label=_('Enable SMS')) - SMS_BACKEND = serializers.ChoiceField(choices=BACKENDS.choices, default=BACKENDS.ALIBABA) + SMS_BACKEND = serializers.ChoiceField(choices=BACKENDS.choices, default=BACKENDS.ALIBABA, label=_('SMS provider')) + + +class SignAndTmplPairSerializer(serializers.Serializer): + sign_name = serializers.CharField(max_length=256, required=True, label=_('Signature')) + template_code = serializers.CharField(max_length=256, required=True, label=_('Template')) class BaseSMSSettingSerializer(serializers.Serializer): @@ -20,20 +25,16 @@ class BaseSMSSettingSerializer(serializers.Serializer): return data +class SignAndTmplSerializer(serializers.Serializer): + verification_code = SignAndTmplPairSerializer(default={'sign_name': '', 'template_code': ''}) + + class AlibabaSMSSettingSerializer(BaseSMSSettingSerializer): ALIBABA_ACCESS_KEY_ID = serializers.CharField(max_length=256, required=True, label='AccessKeyId') ALIBABA_ACCESS_KEY_SECRET = serializers.CharField( max_length=256, required=False, label='AccessKeySecret', write_only=True) - ALIBABA_SMS_SIGN_AND_TEMPLATES = serializers.DictField( - label=_('Signatures and Templates'), required=True, help_text=_(''' - Filling in JSON Data: - { - "verification_code": { - "sign_name": "", - "template_code": "" - } - } - ''') + ALIBABA_SMS_SIGN_AND_TEMPLATES = SignAndTmplSerializer( + label=_('Signatures and Templates'), required=True ) @@ -41,13 +42,6 @@ class TencentSMSSettingSerializer(BaseSMSSettingSerializer): TENCENT_SECRET_ID = serializers.CharField(max_length=256, required=True, label='Secret id') TENCENT_SECRET_KEY = serializers.CharField(max_length=256, required=False, label='Secret key', write_only=True) TENCENT_SDKAPPID = serializers.CharField(max_length=256, required=True, label='SDK app id') - TENCENT_SMS_SIGN_AND_TEMPLATES = serializers.DictField( - label=_('Signatures and Templates'), required=True, help_text=_(''' - Filling in JSON Data: - { - "verification_code": { - "sign_name": "", - "template_code": "" - } - } - ''')) + TENCENT_SMS_SIGN_AND_TEMPLATES = SignAndTmplSerializer( + label=_('Signatures and Templates'), required=True + )