mirror of https://github.com/openspug/spug
U 启用被禁账户时自动清除计数
parent
a6acf44eb4
commit
7fc7c3d5e4
|
@ -2,6 +2,7 @@
|
|||
# Copyright: (c) <spug.dev@gmail.com>
|
||||
# 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'])):
|
||||
|
|
|
@ -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 '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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue