mirror of
https://github.com/thecyberlearn/quantum-ai-v3.git
synced 2026-08-18 15:12:58 +00:00
🔄 Create fresh admin user reset command
- Delete all existing admin users (admin@netcop.ai, admin@quantumtaskai.com) - Create completely fresh admin user with proper Django methods - Test authentication to verify working credentials - Add detailed logging for troubleshooting This ensures clean admin state without any database artifacts. Admin Credentials: - Email: admin@quantumtaskai.com - Username: admin - Password: QuantumAI2024! 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
737611969c
commit
7b0e166adf
73
core/management/commands/check_admin.py
Normal file
73
core/management/commands/check_admin.py
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
User = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'Check and fix admin user status'
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
# Check both possible admin emails
|
||||||
|
possible_emails = ['admin@netcop.ai', 'admin@quantumtaskai.com']
|
||||||
|
username = 'admin'
|
||||||
|
password = 'QuantumAI2024!'
|
||||||
|
|
||||||
|
user = None
|
||||||
|
found_email = None
|
||||||
|
|
||||||
|
# Try to find existing admin user
|
||||||
|
for email in possible_emails:
|
||||||
|
try:
|
||||||
|
user = User.objects.get(email=email)
|
||||||
|
found_email = email
|
||||||
|
break
|
||||||
|
except User.DoesNotExist:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if user:
|
||||||
|
# User found with one of the emails
|
||||||
|
self.stdout.write(f"✅ User found: {user.email}")
|
||||||
|
self.stdout.write(f"Username: {user.username}")
|
||||||
|
self.stdout.write(f"Is superuser: {user.is_superuser}")
|
||||||
|
self.stdout.write(f"Is staff: {user.is_staff}")
|
||||||
|
self.stdout.write(f"Is active: {user.is_active}")
|
||||||
|
self.stdout.write(f"Email verified: {user.email_verified}")
|
||||||
|
|
||||||
|
# Fix user permissions if needed
|
||||||
|
if not user.is_superuser or not user.is_staff:
|
||||||
|
user.is_superuser = True
|
||||||
|
user.is_staff = True
|
||||||
|
user.is_active = True
|
||||||
|
user.save()
|
||||||
|
self.stdout.write("🔧 Fixed user permissions")
|
||||||
|
|
||||||
|
# Reset password to ensure it's correct
|
||||||
|
user.set_password(password)
|
||||||
|
user.save()
|
||||||
|
self.stdout.write("🔑 Password reset successfully")
|
||||||
|
|
||||||
|
# Show login instructions
|
||||||
|
self.stdout.write("\n📝 Login Instructions:")
|
||||||
|
self.stdout.write(f"URL: https://quantum-ai.up.railway.app/admin/")
|
||||||
|
self.stdout.write(f"Email: {found_email}")
|
||||||
|
self.stdout.write(f"Username: {username}")
|
||||||
|
self.stdout.write(f"Password: {password}")
|
||||||
|
|
||||||
|
else:
|
||||||
|
self.stdout.write("❌ Admin user not found! Creating new admin user...")
|
||||||
|
|
||||||
|
# Create new admin user with preferred email
|
||||||
|
preferred_email = 'admin@quantumtaskai.com'
|
||||||
|
user = User.objects.create_superuser(
|
||||||
|
username=username,
|
||||||
|
email=preferred_email,
|
||||||
|
password=password,
|
||||||
|
)
|
||||||
|
user.add_balance(100, "Initial admin balance")
|
||||||
|
|
||||||
|
self.stdout.write("✅ New admin user created successfully!")
|
||||||
|
self.stdout.write(f"Email: {preferred_email}")
|
||||||
|
self.stdout.write(f"Username: {username}")
|
||||||
|
self.stdout.write(f"Password: {password}")
|
||||||
|
self.stdout.write(f"Balance: {user.wallet_balance} AED")
|
||||||
86
core/management/commands/reset_admin.py
Normal file
86
core/management/commands/reset_admin.py
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
User = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'Reset admin user - delete existing and create fresh'
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
email = 'admin@quantumtaskai.com'
|
||||||
|
username = 'admin'
|
||||||
|
password = 'QuantumAI2024!'
|
||||||
|
|
||||||
|
self.stdout.write("🔄 Resetting admin user...")
|
||||||
|
|
||||||
|
# Delete ANY existing admin users (all possible emails/usernames)
|
||||||
|
deleted_count = 0
|
||||||
|
|
||||||
|
# Check for users with admin emails
|
||||||
|
admin_emails = ['admin@quantumtaskai.com', 'admin@netcop.ai']
|
||||||
|
for admin_email in admin_emails:
|
||||||
|
try:
|
||||||
|
user = User.objects.get(email=admin_email)
|
||||||
|
user.delete()
|
||||||
|
deleted_count += 1
|
||||||
|
self.stdout.write(f"❌ Deleted user with email: {admin_email}")
|
||||||
|
except User.DoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Check for users with admin username
|
||||||
|
try:
|
||||||
|
user = User.objects.get(username=username)
|
||||||
|
if user.email not in admin_emails: # Don't double-delete
|
||||||
|
user.delete()
|
||||||
|
deleted_count += 1
|
||||||
|
self.stdout.write(f"❌ Deleted user with username: {username}")
|
||||||
|
except User.DoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
|
self.stdout.write(f"🗑️ Deleted {deleted_count} existing admin user(s)")
|
||||||
|
|
||||||
|
# Create fresh admin user
|
||||||
|
self.stdout.write("🆕 Creating fresh admin user...")
|
||||||
|
|
||||||
|
user = User.objects.create_superuser(
|
||||||
|
username=username,
|
||||||
|
email=email,
|
||||||
|
password=password,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add initial balance
|
||||||
|
user.add_balance(100, "Initial admin balance")
|
||||||
|
|
||||||
|
# Verify user was created correctly
|
||||||
|
user.refresh_from_db()
|
||||||
|
|
||||||
|
self.stdout.write("✅ Fresh admin user created successfully!")
|
||||||
|
self.stdout.write(f"📧 Email: {user.email}")
|
||||||
|
self.stdout.write(f"👤 Username: {user.username}")
|
||||||
|
self.stdout.write(f"🔐 Password: {password}")
|
||||||
|
self.stdout.write(f"⚡ Is superuser: {user.is_superuser}")
|
||||||
|
self.stdout.write(f"👥 Is staff: {user.is_staff}")
|
||||||
|
self.stdout.write(f"✅ Is active: {user.is_active}")
|
||||||
|
self.stdout.write(f"💰 Balance: {user.wallet_balance} AED")
|
||||||
|
|
||||||
|
self.stdout.write("\n🎯 Login Instructions:")
|
||||||
|
self.stdout.write("URL: https://quantum-ai.up.railway.app/admin/")
|
||||||
|
self.stdout.write(f"Email: {email}")
|
||||||
|
self.stdout.write(f"Username: {username}")
|
||||||
|
self.stdout.write(f"Password: {password}")
|
||||||
|
|
||||||
|
self.stdout.write("\n🔍 Authentication Test:")
|
||||||
|
# Test authentication
|
||||||
|
from django.contrib.auth import authenticate
|
||||||
|
auth_user = authenticate(username=email, password=password)
|
||||||
|
if auth_user:
|
||||||
|
self.stdout.write("✅ Email authentication: WORKING")
|
||||||
|
else:
|
||||||
|
self.stdout.write("❌ Email authentication: FAILED")
|
||||||
|
|
||||||
|
auth_user = authenticate(username=username, password=password)
|
||||||
|
if auth_user:
|
||||||
|
self.stdout.write("✅ Username authentication: WORKING")
|
||||||
|
else:
|
||||||
|
self.stdout.write("❌ Username authentication: FAILED")
|
||||||
@ -4,7 +4,7 @@
|
|||||||
"builder": "NIXPACKS"
|
"builder": "NIXPACKS"
|
||||||
},
|
},
|
||||||
"deploy": {
|
"deploy": {
|
||||||
"startCommand": "python manage.py migrate --run-syncdb; python manage.py populate_agents; python manage.py create_user admin@quantumtaskai.com QuantumAI2024! --username admin --superuser --balance 100 || true; python manage.py collectstatic --noinput && gunicorn netcop_hub.wsgi:application --bind 0.0.0.0:$PORT --workers 1 --timeout 60",
|
"startCommand": "python manage.py migrate --run-syncdb; python manage.py populate_agents; python manage.py reset_admin; python manage.py collectstatic --noinput && gunicorn netcop_hub.wsgi:application --bind 0.0.0.0:$PORT --workers 1 --timeout 60",
|
||||||
"restartPolicyType": "ON_FAILURE",
|
"restartPolicyType": "ON_FAILURE",
|
||||||
"restartPolicyMaxRetries": 3
|
"restartPolicyMaxRetries": 3
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user