From 7fc7c3d5e486e23d6229fedfd81e56ca2db4fec8 Mon Sep 17 00:00:00 2001 From: vapao Date: Sat, 18 Jul 2020 15:37:42 +0800 Subject: [PATCH] =?UTF-8?q?U=20=E5=90=AF=E7=94=A8=E8=A2=AB=E7=A6=81?= =?UTF-8?q?=E8=B4=A6=E6=88=B7=E6=97=B6=E8=87=AA=E5=8A=A8=E6=B8=85=E9=99=A4?= =?UTF-8?q?=E8=AE=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/account/management/commands/user.py | 2 ++ spug_api/apps/account/views.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/spug_api/apps/account/management/commands/user.py b/spug_api/apps/account/management/commands/user.py index 11e8017..e97660b 100644 --- a/spug_api/apps/account/management/commands/user.py +++ b/spug_api/apps/account/management/commands/user.py @@ -2,6 +2,7 @@ # Copyright: (c) # Released under the AGPL-3.0 License. from django.core.management.base import BaseCommand +from django.core.cache import cache from apps.account.models import User @@ -55,6 +56,7 @@ class Command(BaseCommand): return self.echo_error(f'未找到登录名为【{options["u"]}】的账户') user.is_active = True user.save() + cache.delete(user.username) self.echo_success('账户已启用') elif action == 'reset': if not all((options['u'], options['p'])): diff --git a/spug_api/apps/account/views.py b/spug_api/apps/account/views.py index 53ea371..999b309 100644 --- a/spug_api/apps/account/views.py +++ b/spug_api/apps/account/views.py @@ -50,8 +50,12 @@ class UserView(View): if form.get('password'): form.token_expired = 0 form.password_hash = User.make_password(form.pop('password')) - if User.objects.filter(username=form.username, deleted_by_id__isnull=True).exclude(id=form.id).exists(): - return json_response(error=f'已存在登录名为【{form.username}】的用户') + if 'username' in form: + if User.objects.filter(username=form.username, deleted_by_id__isnull=True).exclude(id=form.id).exists(): + return json_response(error=f'已存在登录名为【{form.username}】的用户') + if 'is_active' in form: + user = User.objects.get(pk=form.id) + cache.delete(user.username) User.objects.filter(pk=form.pop('id')).update(**form) return json_response(error=error)