schon/engine/vibes_auth/management/commands/get_otp.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

25 lines
895 B
Python

from django.core.management.base import BaseCommand, CommandError
from engine.vibes_auth.models import User
from engine.vibes_auth.utils.otp import generate_otp_code
class Command(BaseCommand):
help = "Generate a fresh admin OTP code for a user (for when SMTP is down)"
def add_arguments(self, parser):
parser.add_argument("email", type=str, help="Email of the staff user")
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 not user.is_staff:
raise CommandError(f'User "{email}" is not a staff member.')
code = generate_otp_code(user)
self.stdout.write(f"OTP code for {email}: {code}")
self.stdout.write("Valid for 5 minutes.")