Skip to content

Commit cc47d86

Browse files
committed
refactor: Move OTP verification check to a dedicated function and update usage in RegistrationService
1 parent 85617e6 commit cc47d86

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

accounts/services/registration_service.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
MAX_OTP_ATTEMPTS = 5
1414
MAX_RESENDS = 3
1515

16-
# Check if OTP verification is enabled (default: True)
17-
# Pass --otp-verification=False when running docker to disable
18-
OTP_VERIFICATION_ENABLED = os.environ.get('OTP_VERIFICATION_ENABLED', 'True').lower() in ('true', '1', 'yes')
16+
def is_otp_verification_enabled():
17+
"""Check if OTP verification is enabled at runtime (not at import time)"""
18+
return os.environ.get('OTP_VERIFICATION_ENABLED', 'True').lower() in ('true', '1', 'yes')
1919

2020
class RegistrationService:
2121
"""
@@ -53,7 +53,8 @@ def register(username, email, raw_password, first_name="", last_name="", recaptc
5353
)
5454

5555
# Send email (use Celery in prod)
56-
send_otp_email(email, otp, username=username)
56+
if is_otp_verification_enabled():
57+
send_otp_email(email, otp, username=username)
5758
return pending
5859

5960
@staticmethod
@@ -90,7 +91,7 @@ def verify_otp_and_create_user(email, otp):
9091
raise ValueError("No pending registration found")
9192

9293
# Skip OTP verification if disabled via environment variable
93-
if OTP_VERIFICATION_ENABLED:
94+
if is_otp_verification_enabled():
9495
# expired
9596
if pending.is_expired(OTP_EXPIRY_MINUTES):
9697
pending.delete()

docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
services:
22
web:
3-
image: ujjwalkar/bizbuch-backend:latest
3+
build: .
4+
volumes:
5+
- .:/app
46
command: >
57
sh -c "
68
python manage.py migrate &&

0 commit comments

Comments
 (0)