From 74ff5c4ea670b5e51458ebd1ceddbb5e16db30ec Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 26 Jul 2025 23:37:17 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Fix=20email=20verification=20'No?= =?UTF-8?q?t=20Found'=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit โœ… Root Cause Fixed: - SITE_URL was pointing to quantumtaskai.com instead of actual Railway domain - Email verification links were going to wrong domain causing 404 errors ๐Ÿ”ง Changes Made: - Update SITE_URL to use quantum-ai.up.railway.app for Railway environment - Email verification links now point to correct domain ๐Ÿ› ๏ธ Added Management Command: - Create verify_email command for manual email verification - Usage: python manage.py verify_email user@example.com - Useful for admin-created users or troubleshooting โœ… Expected Result: - Email verification links now work correctly - Users can successfully verify their emails - Manual verification available for admin use ๐Ÿค– Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../management/commands/verify_email.py | 68 +++++++++++++++++++ netcop_hub/settings.py | 3 +- 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 authentication/management/commands/verify_email.py diff --git a/authentication/management/commands/verify_email.py b/authentication/management/commands/verify_email.py new file mode 100644 index 0000000..0365743 --- /dev/null +++ b/authentication/management/commands/verify_email.py @@ -0,0 +1,68 @@ +from django.core.management.base import BaseCommand +from django.contrib.auth import get_user_model + +User = get_user_model() + + +class Command(BaseCommand): + help = 'Manually verify user email address' + + def add_arguments(self, parser): + parser.add_argument('email', help='User email address to verify') + parser.add_argument( + '--force', + action='store_true', + help='Force verification even if already verified', + ) + + def handle(self, *args, **options): + email = options['email'] + force = options['force'] + + try: + user = User.objects.get(email=email) + + if user.email_verified and not force: + self.stdout.write( + self.style.WARNING(f"Email {email} is already verified!") + ) + self.stdout.write("Use --force to override") + return + + # Manually verify the email + user.email_verified = True + user.save() + + self.stdout.write( + self.style.SUCCESS(f"โœ… Successfully verified email: {email}") + ) + self.stdout.write(f"User: {user.username}") + self.stdout.write(f"Email verified: {user.email_verified}") + + # Clean up any existing verification tokens + from authentication.models import EmailVerificationToken + tokens = EmailVerificationToken.objects.filter(user=user, is_used=False) + token_count = tokens.count() + if token_count > 0: + tokens.update(is_used=True) + self.stdout.write(f"๐Ÿงน Cleaned up {token_count} unused verification tokens") + + except User.DoesNotExist: + self.stdout.write( + self.style.ERROR(f"โŒ User with email '{email}' not found!") + ) + + # Show available users + all_users = User.objects.all() + if all_users.exists(): + self.stdout.write("\nAvailable users:") + for user in all_users: + status = "โœ… Verified" if user.email_verified else "โŒ Unverified" + self.stdout.write(f" - {user.email} ({user.username}) - {status}") + else: + self.stdout.write("No users found in database") + + except Exception as e: + self.stdout.write( + self.style.ERROR(f"โŒ Error verifying email: {str(e)}") + ) \ No newline at end of file diff --git a/netcop_hub/settings.py b/netcop_hub/settings.py index d7e2522..426abab 100644 --- a/netcop_hub/settings.py +++ b/netcop_hub/settings.py @@ -56,7 +56,8 @@ ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='localhost,127.0.0.1,testserver, # Site URL configuration for emails if config('RAILWAY_ENVIRONMENT', default=''): - SITE_URL = 'https://quantumtaskai.com' + # Use actual Railway domain for email verification links + SITE_URL = 'https://quantum-ai.up.railway.app' else: SITE_URL = config('SITE_URL', default='http://localhost:8000')