Fix admin authentication to use environment variables
- Update AuthService to read ADMIN_USERNAME and ADMIN_PASSWORD from environment - Remove hardcoded admin123 password and use install.py credentials - Add auto-redirect from root URL to admin interface - Authentication now properly respects .env.docker configuration
This commit is contained in:
@@ -351,7 +351,8 @@ app.mount("/admin", StaticFiles(directory="admin-frontend/build", html=True), na
|
|||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def root():
|
async def root():
|
||||||
"""Root endpoint redirects to admin interface"""
|
"""Root endpoint redirects to admin interface"""
|
||||||
return {"message": "Discord Fishbowl Admin Interface", "admin_url": "/admin", "socket_url": "/socket.io"}
|
from fastapi.responses import RedirectResponse
|
||||||
|
return RedirectResponse(url="/admin/", status_code=302)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import os
|
import os
|
||||||
|
|||||||
@@ -19,16 +19,21 @@ class AuthService:
|
|||||||
"""Authentication service for admin users"""
|
"""Authentication service for admin users"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
import os
|
||||||
self.settings = get_settings()
|
self.settings = get_settings()
|
||||||
self.secret_key = self.settings.admin.secret_key if hasattr(self.settings, 'admin') else "fallback-secret-key"
|
self.secret_key = self.settings.admin.secret_key if hasattr(self.settings, 'admin') else "fallback-secret-key"
|
||||||
self.algorithm = "HS256"
|
self.algorithm = "HS256"
|
||||||
self.access_token_expire_minutes = 480 # 8 hours
|
self.access_token_expire_minutes = 480 # 8 hours
|
||||||
|
|
||||||
|
# Get admin credentials from environment
|
||||||
|
admin_username = os.getenv("ADMIN_USERNAME", "admin")
|
||||||
|
admin_password = os.getenv("ADMIN_PASSWORD", "admin123")
|
||||||
|
|
||||||
# Simple in-memory user storage (replace with database in production)
|
# Simple in-memory user storage (replace with database in production)
|
||||||
self.users = {
|
self.users = {
|
||||||
"admin": {
|
admin_username: {
|
||||||
"username": "admin",
|
"username": admin_username,
|
||||||
"password_hash": self._hash_password("admin123"), # Default password
|
"password_hash": self._hash_password(admin_password),
|
||||||
"permissions": ["read", "write", "admin"],
|
"permissions": ["read", "write", "admin"],
|
||||||
"active": True
|
"active": True
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user