Initial commit: Django inventory system
This commit is contained in:
0
myproject/accounts/management/commands/__init__.py
Normal file
0
myproject/accounts/management/commands/__init__.py
Normal file
30
myproject/accounts/management/commands/confirm_email.py
Normal file
30
myproject/accounts/management/commands/confirm_email.py
Normal file
@@ -0,0 +1,30 @@
|
||||
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} не найден.')
|
||||
)
|
||||
Reference in New Issue
Block a user