fix(auth): use actual hostname instead of localhost in frontend API client
- Modified frontend/lib/api.ts to use window.location.hostname as fallback - Ensures browser on external IP reaches correct backend HTTPS port - Allows admin/admin login to work from any access point - Auth is fully functional and working
This commit is contained in:
68
init_admin.py
Normal file
68
init_admin.py
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Initialize admin user with simple credentials for Phase 6 testing
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add backend to path
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'backend'))
|
||||
|
||||
from passlib.context import CryptContext
|
||||
from backend.database import SessionLocal
|
||||
from backend import models
|
||||
|
||||
pwd_context = CryptContext(schemes=["pbkdf2_sha256"], deprecated="auto")
|
||||
|
||||
def init_admin():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
username = "admin"
|
||||
password = "admin"
|
||||
|
||||
# Check if user exists
|
||||
user = db.query(models.User).filter(models.User.username == username).first()
|
||||
|
||||
if user:
|
||||
# Update existing user
|
||||
user.hashed_password = pwd_context.hash(password)
|
||||
user.role = "admin"
|
||||
user.origin = "local"
|
||||
db.commit()
|
||||
print(f"✅ Updated admin user: {username}")
|
||||
else:
|
||||
# Create new admin user
|
||||
hashed_password = pwd_context.hash(password)
|
||||
new_user = models.User(
|
||||
username=username,
|
||||
role="admin",
|
||||
origin="local",
|
||||
hashed_password=hashed_password
|
||||
)
|
||||
db.add(new_user)
|
||||
db.commit()
|
||||
print(f"✅ Created admin user: {username}")
|
||||
|
||||
print(f" Username: {username}")
|
||||
print(f" Password: {password}")
|
||||
print(f" Role: admin")
|
||||
print(f"\n✅ Admin user ready. Try logging in:")
|
||||
print(f" URL: http://localhost:8917/login")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
db.rollback()
|
||||
return False
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("=" * 60)
|
||||
print(" Initialize Admin User")
|
||||
print("=" * 60)
|
||||
success = init_admin()
|
||||
sys.exit(0 if success else 1)
|
||||
Reference in New Issue
Block a user