style: apply black and isort formatting across entire codebase
- Standardize quote style (single to double quotes) - Reorder and group imports alphabetically - Fix line breaks and indentation for consistency - Apply PEP 8 formatting standards Also updated Makefile to exclude both venv and .venv from code quality checks. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -26,14 +26,10 @@ from jose import jwt
|
||||
from passlib.context import CryptContext
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.exceptions import (
|
||||
AdminRequiredException,
|
||||
InvalidTokenException,
|
||||
TokenExpiredException,
|
||||
UserNotActiveException,
|
||||
InvalidCredentialsException,
|
||||
InsufficientPermissionsException
|
||||
)
|
||||
from app.exceptions import (AdminRequiredException,
|
||||
InsufficientPermissionsException,
|
||||
InvalidCredentialsException, InvalidTokenException,
|
||||
TokenExpiredException, UserNotActiveException)
|
||||
from models.database.user import User
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -99,7 +95,9 @@ class AuthManager:
|
||||
"""
|
||||
return pwd_context.verify(plain_password, hashed_password)
|
||||
|
||||
def authenticate_user(self, db: Session, username: str, password: str) -> Optional[User]:
|
||||
def authenticate_user(
|
||||
self, db: Session, username: str, password: str
|
||||
) -> Optional[User]:
|
||||
"""Authenticate user credentials against the database.
|
||||
|
||||
Supports authentication using either username or email address.
|
||||
@@ -201,7 +199,9 @@ class AuthManager:
|
||||
raise InvalidTokenException("Token missing expiration")
|
||||
|
||||
# Check if token has expired (additional check beyond jwt.decode)
|
||||
if datetime.now(timezone.utc) > datetime.fromtimestamp(exp, tz=timezone.utc):
|
||||
if datetime.now(timezone.utc) > datetime.fromtimestamp(
|
||||
exp, tz=timezone.utc
|
||||
):
|
||||
raise TokenExpiredException()
|
||||
|
||||
# Validate user identifier claim exists
|
||||
@@ -214,7 +214,9 @@ class AuthManager:
|
||||
"user_id": int(user_id),
|
||||
"username": payload.get("username"),
|
||||
"email": payload.get("email"),
|
||||
"role": payload.get("role", "user"), # Default to "user" role if not specified
|
||||
"role": payload.get(
|
||||
"role", "user"
|
||||
), # Default to "user" role if not specified
|
||||
}
|
||||
|
||||
except jwt.ExpiredSignatureError:
|
||||
@@ -232,7 +234,9 @@ class AuthManager:
|
||||
logger.error(f"Token verification error: {e}")
|
||||
raise InvalidTokenException("Authentication failed")
|
||||
|
||||
def get_current_user(self, db: Session, credentials: HTTPAuthorizationCredentials) -> User:
|
||||
def get_current_user(
|
||||
self, db: Session, credentials: HTTPAuthorizationCredentials
|
||||
) -> User:
|
||||
"""Extract and validate the current authenticated user from request credentials.
|
||||
|
||||
Verifies the JWT token from the Authorization header, looks up the user
|
||||
@@ -286,8 +290,10 @@ class AuthManager:
|
||||
# This will only execute if user has "admin" role
|
||||
pass
|
||||
"""
|
||||
|
||||
def decorator(func):
|
||||
"""Decorator that wraps the function with role checking."""
|
||||
|
||||
def wrapper(current_user: User, *args, **kwargs):
|
||||
# Check if current user has the required role
|
||||
if current_user.role != required_role:
|
||||
@@ -339,8 +345,7 @@ class AuthManager:
|
||||
# Check if user has vendor or admin role (admins have full access)
|
||||
if current_user.role not in ["vendor", "admin"]:
|
||||
raise InsufficientPermissionsException(
|
||||
message="Vendor access required",
|
||||
required_permission="vendor"
|
||||
message="Vendor access required", required_permission="vendor"
|
||||
)
|
||||
return current_user
|
||||
|
||||
@@ -363,7 +368,7 @@ class AuthManager:
|
||||
if current_user.role not in ["customer", "admin"]:
|
||||
raise InsufficientPermissionsException(
|
||||
message="Customer account access required",
|
||||
required_permission="customer"
|
||||
required_permission="customer",
|
||||
)
|
||||
return current_user
|
||||
|
||||
|
||||
Reference in New Issue
Block a user