From 7f3b678d390a311d88114a0369a5d982c4939431 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 2 Aug 2025 13:04:16 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=90=20Add=20email=20verification=20byp?= =?UTF-8?q?ass=20for=20testing=20environments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- .env.example | 4 ++++ authentication/views.py | 31 ++++++++++++++++++++++--------- netcop_hub/settings.py | 4 ++++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.env.example b/.env.example index 5426543..bafd0b1 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/authentication/views.py b/authentication/views.py index 80a093b..deeca29 100644 --- a/authentication/views.py +++ b/authentication/views.py @@ -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.') - - return redirect('authentication:login') + # Skip email verification - auto-verify and login + user.email_verified = True + user.save() + + # 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') diff --git a/netcop_hub/settings.py b/netcop_hub/settings.py index e6c044a..baa702b 100644 --- a/netcop_hub/settings.py +++ b/netcop_hub/settings.py @@ -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