dashboard/accounts/management/commands/rm_unverified_users.py

43 lines
1.8 KiB
Python
Raw Permalink Normal View History

# 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 Command(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()