31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
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} не найден.')
|
||
)
|