U 启用被禁账户时自动清除计数

pull/154/head
vapao 2020-07-18 15:37:42 +08:00
parent a6acf44eb4
commit 7fc7c3d5e4
2 changed files with 8 additions and 2 deletions

View File

@ -2,6 +2,7 @@
# Copyright: (c) <spug.dev@gmail.com> # Copyright: (c) <spug.dev@gmail.com>
# Released under the AGPL-3.0 License. # Released under the AGPL-3.0 License.
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.core.cache import cache
from apps.account.models import User from apps.account.models import User
@ -55,6 +56,7 @@ class Command(BaseCommand):
return self.echo_error(f'未找到登录名为【{options["u"]}】的账户') return self.echo_error(f'未找到登录名为【{options["u"]}】的账户')
user.is_active = True user.is_active = True
user.save() user.save()
cache.delete(user.username)
self.echo_success('账户已启用') self.echo_success('账户已启用')
elif action == 'reset': elif action == 'reset':
if not all((options['u'], options['p'])): if not all((options['u'], options['p'])):

View File

@ -50,8 +50,12 @@ class UserView(View):
if form.get('password'): if form.get('password'):
form.token_expired = 0 form.token_expired = 0
form.password_hash = User.make_password(form.pop('password')) 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(): if 'username' in form:
return json_response(error=f'已存在登录名为【{form.username}】的用户') 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) User.objects.filter(pk=form.pop('id')).update(**form)
return json_response(error=error) return json_response(error=error)