schon/engine/vibes_auth/management/commands/activate_user.py
Egor fureunoir Gorbunov ad320235d6 feat(payments, vibes_auth, core): introduce decimal fields, 2FA, and admin OTP
- Refactored monetary fields across models to use `DecimalField` for improved precision.
- Implemented two-factor authentication (2FA) for admin logins with OTP codes.
- Added ability to generate admin OTP via management commands.
- Updated Docker Compose override for dev-specific port bindings.
- Included template for 2FA OTP verification to enhance security.

Additional changes:
- Upgraded and downgraded various dependencies (e.g., django-celery-beat and yarl).
- Replaced float-based calculations with decimal for consistent rounding behavior.
- Improved admin user management commands for activation and OTP generation.
2026-03-03 00:42:21 +03:00

26 lines
961 B
Python

from django.core.management.base import BaseCommand, CommandError
from engine.vibes_auth.models import User
class Command(BaseCommand):
help = "Directly activate a user account (for when SMTP is not configured)"
def add_arguments(self, parser):
parser.add_argument("email", type=str, help="Email of the user to activate")
def handle(self, *args, **options):
email = options["email"]
try:
user = User.objects.get(email=email)
except User.DoesNotExist as e:
raise CommandError(f'User "{email}" does not exist.') from e
if user.is_active and user.is_verified:
self.stdout.write(f'User "{email}" is already active and verified.')
return
user.is_active = True
user.is_verified = True
user.save(update_fields=["is_active", "is_verified", "modified"])
self.stdout.write(self.style.SUCCESS(f'User "{email}" has been activated.'))