mirror of https://github.com/openspug/spug
feat: update user command and settings
parent
af2d92d030
commit
9bab0ccc5c
|
|
@ -26,8 +26,10 @@ class Command(BaseCommand):
|
|||
message = '''
|
||||
账户管理命令用法:
|
||||
user add 创建账户,例如:user add -u admin -p 123 -n 管理员 -s
|
||||
user del 删除账户,例如:user del -u admin
|
||||
user reset 重置账户密码,例如:user reset -u admin -p 123
|
||||
user enable 启用被禁用的账户,例如:user enable -u admin
|
||||
user disable 禁用的账户,例如:user disable -u admin
|
||||
'''
|
||||
self.stdout.write(message)
|
||||
|
||||
|
|
@ -47,6 +49,18 @@ class Command(BaseCommand):
|
|||
is_supper=options['s'],
|
||||
)
|
||||
self.echo_success('创建用户成功')
|
||||
elif action == 'del':
|
||||
if not options['u']:
|
||||
self.echo_error('缺少参数')
|
||||
self.print_help()
|
||||
|
||||
user = User.objects.filter(username=options['u'], deleted_by_id__isnull=True).first()
|
||||
if not user:
|
||||
return self.echo_error(f'未找到登录名为【{options["u"]}】的账户')
|
||||
|
||||
user.delete()
|
||||
cache.delete(user.username)
|
||||
self.echo_success('账户已删除')
|
||||
elif action == 'enable':
|
||||
if not options['u']:
|
||||
self.echo_error('缺少参数')
|
||||
|
|
@ -58,6 +72,19 @@ class Command(BaseCommand):
|
|||
user.save()
|
||||
cache.delete(user.username)
|
||||
self.echo_success('账户已启用')
|
||||
elif action == 'disable':
|
||||
if not options['u']:
|
||||
self.echo_error('缺少参数')
|
||||
self.print_help()
|
||||
|
||||
user = User.objects.filter(username=options['u'], deleted_by_id__isnull=True).first()
|
||||
if not user:
|
||||
return self.echo_error(f'未找到登录名为【{options["u"]}】的账户')
|
||||
|
||||
user.is_active = False
|
||||
user.save()
|
||||
cache.delete(user.username)
|
||||
self.echo_success('账户已禁用')
|
||||
elif action == 'reset':
|
||||
if not all((options['u'], options['p'])):
|
||||
self.echo_error('缺少参数')
|
||||
|
|
@ -70,4 +97,4 @@ class Command(BaseCommand):
|
|||
self.echo_success('账户密码已重置')
|
||||
else:
|
||||
self.echo_error('未识别的操作')
|
||||
self.print_help()
|
||||
self.print_help()
|
||||
|
|
@ -71,12 +71,21 @@ DATABASES = {
|
|||
}
|
||||
}
|
||||
|
||||
REDIS_CONFIG = {
|
||||
"HOST": os.getenv('REDIS_HOST') or '127.0.0.1',
|
||||
"PORT": os.getenv('REDIS_PORT') or '6379',
|
||||
"PASSWORD": os.getenv('REDIS_PASSWORD') or '',
|
||||
"DB0": os.getenv('REDIS_DATABASE_0') or '0',
|
||||
"DB1": os.getenv('REDIS_DATABASE_1') or '1',
|
||||
}
|
||||
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django_redis.cache.RedisCache",
|
||||
"LOCATION": "redis://127.0.0.1:6379/1",
|
||||
"LOCATION": "redis://" + REDIS_CONFIG['HOST'] + ":" + REDIS_CONFIG['PORT'] + "/" + REDIS_CONFIG['DB1'],
|
||||
"OPTIONS": {
|
||||
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
||||
"PASSWORD": REDIS_CONFIG['PASSWORD'],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -85,7 +94,7 @@ CHANNEL_LAYERS = {
|
|||
"default": {
|
||||
"BACKEND": "channels_redis.core.RedisChannelLayer",
|
||||
"CONFIG": {
|
||||
"hosts": [("127.0.0.1", 6379)],
|
||||
"hosts": [("redis://:" + REDIS_CONFIG['PASSWORD'] + "@" + REDIS_CONFIG['HOST'] + ":" + REDIS_CONFIG['PORT'] + "/" + REDIS_CONFIG['DB0'])],
|
||||
"capacity": 1000,
|
||||
"expiry": 120,
|
||||
},
|
||||
|
|
@ -129,4 +138,4 @@ SPUG_VERSION = 'v2.3.16'
|
|||
try:
|
||||
from spug.overrides import *
|
||||
except ImportError:
|
||||
pass
|
||||
pass
|
||||
Loading…
Reference in New Issue