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)