working on new system for importing

This commit is contained in:
HotSwapp
2025-09-21 20:37:13 -05:00
parent 16d7455f85
commit f7644a4f67
11 changed files with 60 additions and 5819 deletions

View File

@@ -20,6 +20,7 @@ pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
# JWT Security
security = HTTPBearer()
optional_security = HTTPBearer(auto_error=False)
def verify_password(plain_password: str, hashed_password: str) -> bool:
@@ -190,6 +191,31 @@ def get_current_user(
return user
def get_optional_current_user(
credentials: Optional[HTTPAuthorizationCredentials] = Depends(optional_security),
db: Session = Depends(get_db)
) -> Optional[User]:
"""Get current authenticated user, but allow None if not authenticated"""
if not credentials:
return None
try:
token = credentials.credentials
username = verify_token(token)
if username is None:
return None
user = db.query(User).filter(User.username == username).first()
if user is None or not user.is_active:
return None
return user
except Exception:
return None
def get_admin_user(current_user: User = Depends(get_current_user)) -> User:
"""Require admin privileges"""
if not current_user.is_admin: