forked from Hostea/dashboard
feat: management command to remove unverified users
parent
87039a043b
commit
8bcc6a390b
@ -0,0 +1,42 @@
|
||||
# Copyright © 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
from datetime import datetime, timedelta
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.conf import settings
|
||||
|
||||
from accounts.models import AccountConfirmChallenge
|
||||
|
||||
|
||||
class CleanUnverifiedUsersCommand(BaseCommand):
|
||||
help = "Deletes unverified users after the period specified in settings.py"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
now = datetime.now()
|
||||
delta = now - timedelta(
|
||||
seconds=settings.HOSTEA["ACCOUNTS"]["MAX_VERIFICATION_TOLERANCE_PERIOD"]
|
||||
)
|
||||
# delta = delta.time()
|
||||
challenges = AccountConfirmChallenge.objects.filter(created_at__lt=(delta))
|
||||
self.stdout.write(self.style.SUCCESS(f"[*] Found {len(challenges)} challenges"))
|
||||
for challenge in challenges:
|
||||
if not challenge.owned_by.is_active:
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
f"[*] Deleting user {challenge.owned_by.username}"
|
||||
)
|
||||
)
|
||||
challenge.owned_by.delete()
|
||||
else:
|
||||
challenge.delete()
|
Loading…
Reference in New Issue