🔐 Add email verification bypass for testing environments

- Add REQUIRE_EMAIL_VERIFICATION setting (default: True)
- Skip email verification when setting is False
- Auto-verify users and provide welcome bonus when bypassed
- Updated .env.example with documentation
- Allows testing on Railway without email setup until final domain

Perfect for Railway deployment until email/domain configuration is ready.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude 2025-08-02 13:04:16 +05:30
parent 7120bfdf98
commit 7f3b678d39
3 changed files with 30 additions and 9 deletions

View File

@ -4,6 +4,10 @@ DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1,your-domain.com
CSRF_TRUSTED_ORIGINS=http://localhost:8000,http://127.0.0.1:8000
# Email Verification
# Set to False to bypass email verification for testing (until final domain is ready)
REQUIRE_EMAIL_VERIFICATION=True
# Database Configuration
# Default: SQLite (simple, reliable, no setup required)
# Railway: Automatically uses PostgreSQL via DATABASE_URL

View File

@ -101,8 +101,8 @@ def login_view(request):
user = authenticate(request, username=email, password=password)
if user is not None:
# Check if email is verified
if not user.email_verified:
# Check if email is verified (only if email verification is required)
if settings.REQUIRE_EMAIL_VERIFICATION and not user.email_verified:
messages.warning(request, 'Please verify your email address before logging in. Check your inbox for the verification link.')
return render(request, 'authentication/login.html')
@ -154,15 +154,28 @@ def register_view(request):
email=email,
password=password1
)
# Don't automatically login - require email verification first
# Send verification email
if send_verification_email(user):
messages.success(request, 'Account created successfully! Please check your email to verify your account.')
# Handle email verification based on settings
if settings.REQUIRE_EMAIL_VERIFICATION:
# Don't automatically login - require email verification first
# Send verification email
if send_verification_email(user):
messages.success(request, 'Account created successfully! Please check your email to verify your account.')
else:
messages.warning(request, 'Account created but verification email could not be sent. You can request a new one after logging in.')
return redirect('authentication:login')
else:
messages.warning(request, 'Account created but verification email could not be sent. You can request a new one after logging in.')
# Skip email verification - auto-verify and login
user.email_verified = True
user.save()
return redirect('authentication:login')
# Add initial wallet balance for new users
user.add_balance(50, "Welcome bonus - 50 AED to get started!")
login(request, user)
messages.success(request, f'Welcome {user.username}! Your account has been created and you\'ve received 50 AED welcome bonus.')
return redirect('core:homepage')
except Exception as e:
logger.error(f"Error creating account for {email}: {str(e)}")
messages.error(request, 'Error creating account')

View File

@ -61,6 +61,10 @@ if config('RAILWAY_ENVIRONMENT', default=''):
else:
SITE_URL = config('SITE_URL', default='http://localhost:8000')
# Email verification requirement
# Set to False for testing environments until final domain is ready
REQUIRE_EMAIL_VERIFICATION = config('REQUIRE_EMAIL_VERIFICATION', default=True, cast=bool)
# Application definition