From 348de8c36be9f8de44a3d22157259626ca832fe3 Mon Sep 17 00:00:00 2001 From: vapao Date: Mon, 20 Dec 2021 14:53:34 +0800 Subject: [PATCH] =?UTF-8?q?A=20=E6=B7=BB=E5=8A=A0=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=A1=8C=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apps/account/management/commands/set.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 spug_api/apps/account/management/commands/set.py diff --git a/spug_api/apps/account/management/commands/set.py b/spug_api/apps/account/management/commands/set.py new file mode 100644 index 0000000..a8fb61a --- /dev/null +++ b/spug_api/apps/account/management/commands/set.py @@ -0,0 +1,37 @@ +# Copyright: (c) OpenSpug Organization. https://github.com/openspug/spug +# Copyright: (c) +# Released under the AGPL-3.0 License. +from django.core.management.base import BaseCommand +from apps.setting.utils import AppSetting + + +class Command(BaseCommand): + help = '系统设置' + + def add_arguments(self, parser): + parser.add_argument('target', type=str, help='设置对象') + parser.add_argument('value', type=str, help='设置值') + + def echo_success(self, msg): + self.stdout.write(self.style.SUCCESS(msg)) + + def echo_error(self, msg): + self.stderr.write(self.style.ERROR(msg)) + + def print_help(self, *args): + message = ''' + 系统设置命令用法: + set mfa disable 禁用登录MFA + ''' + self.stdout.write(message) + + def handle(self, *args, **options): + target = options['target'] + if target == 'mfa': + if options['value'] != 'disable': + return self.echo_error(f'mfa设置,不支持的值【{options["value"]}】') + AppSetting.set('MFA', {'enable': False}) + self.echo_success('MFA已禁用') + else: + self.echo_error('未识别的操作') + self.print_help()