mirror of
https://github.com/rommapp/romm.git
synced 2026-06-28 06:46:00 +00:00
extracted credentials exceptions in separated file
This commit is contained in:
@@ -13,6 +13,10 @@ from models.user import User, Role
|
||||
from utils.cache import cache
|
||||
from utils.auth import authenticate_user, get_password_hash
|
||||
from utils.oauth import protected_route
|
||||
from exceptions.credentials_exceptions import (
|
||||
credentials_exception,
|
||||
authentication_scheme_exception,
|
||||
)
|
||||
from config import ROMM_AUTH_ENABLED
|
||||
|
||||
router = APIRouter()
|
||||
@@ -28,16 +32,8 @@ class UserSchema(BaseModel):
|
||||
orm_mode = True
|
||||
|
||||
|
||||
credentials_exception = HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Incorrect username or password",
|
||||
headers={"WWW-Authenticate": "Basic"},
|
||||
)
|
||||
|
||||
|
||||
@router.post("/login", dependencies=[Depends(HTTPBasic(auto_error=False))])
|
||||
def login(request: Request):
|
||||
|
||||
if not os.environ.get("ROMM_AUTH_ENABLED"):
|
||||
return {"message": "RomM auth not enabled."}
|
||||
|
||||
@@ -48,11 +44,8 @@ def login(request: Request):
|
||||
try:
|
||||
scheme, credentials = auth.split()
|
||||
if scheme.lower() != "basic":
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Invalid authentication scheme",
|
||||
headers={"WWW-Authenticate": "Basic"},
|
||||
)
|
||||
raise authentication_scheme_exception
|
||||
|
||||
decoded = base64.b64decode(credentials).decode("ascii")
|
||||
except (ValueError, UnicodeDecodeError, binascii.Error):
|
||||
raise credentials_exception
|
||||
|
||||
@@ -12,7 +12,7 @@ from stream_zip import ZIP_64, stream_zip
|
||||
from logger.logger import log
|
||||
from handler import dbh
|
||||
from utils import fs, get_file_name_with_no_tags
|
||||
from utils.exceptions import RomNotFoundError, RomAlreadyExistsException
|
||||
from exceptions.fs_exceptions import RomNotFoundError, RomAlreadyExistsException
|
||||
from utils.oauth import protected_route
|
||||
from models import Rom, Platform
|
||||
from config import LIBRARY_BASE_PATH
|
||||
|
||||
@@ -4,7 +4,7 @@ from rq import Queue
|
||||
|
||||
from logger.logger import log
|
||||
from utils import fs, fastapi
|
||||
from utils.exceptions import PlatformsNotFoundException, RomsNotFoundException
|
||||
from exceptions.fs_exceptions import PlatformsNotFoundException, RomsNotFoundException
|
||||
from handler import dbh
|
||||
from utils.socket import socket_server
|
||||
from utils.cache import redis_client, redis_url, redis_connectable
|
||||
|
||||
14
backend/exceptions/credentials_exceptions.py
Normal file
14
backend/exceptions/credentials_exceptions.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
credentials_exception = HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Incorrect username or password",
|
||||
headers={"WWW-Authenticate": "Basic"},
|
||||
)
|
||||
|
||||
authentication_scheme_exception = HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Invalid authentication scheme",
|
||||
headers={"WWW-Authenticate": "Basic"},
|
||||
)
|
||||
@@ -14,7 +14,7 @@ from config import (
|
||||
DEFAULT_PATH_COVER_S,
|
||||
)
|
||||
from config.config_loader import config
|
||||
from utils.exceptions import (
|
||||
from exceptions.fs_exceptions import (
|
||||
PlatformsNotFoundException,
|
||||
RomsNotFoundException,
|
||||
RomNotFoundError,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from ..fastapi import scan_platform, scan_rom
|
||||
from ..exceptions import RomsNotFoundException
|
||||
from ...exceptions.fs_exceptions import RomsNotFoundException
|
||||
from models import Platform, Rom
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user