Files
octopus/myproject/accounts/management/commands/confirm_email.py

31 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from django.core.management.base import BaseCommand
from accounts.models import CustomUser
class Command(BaseCommand):
help = 'Подтверждает email для указанного пользователя'
def add_arguments(self, parser):
parser.add_argument('email', type=str, help='Email пользователя')
def handle(self, *args, **options):
email = options['email']
try:
user = CustomUser.objects.get(email=email)
if user.is_email_confirmed:
self.stdout.write(
self.style.WARNING(f'Email для пользователя {email} уже подтвержден.')
)
else:
user.confirm_email()
self.stdout.write(
self.style.SUCCESS(f'Email для пользователя {email} успешно подтвержден!')
)
except CustomUser.DoesNotExist:
self.stdout.write(
self.style.ERROR(f'Пользователь с email {email} не найден.')
)