27 lines
693 B
Python
27 lines
693 B
Python
from functools import wraps
|
|
|
|
from flask import Response, request
|
|
|
|
from app.services.user import verify_basic_admin
|
|
|
|
|
|
def _authenticate_response() -> Response:
|
|
return Response(
|
|
"Требуется авторизация",
|
|
401,
|
|
{"WWW-Authenticate": 'Basic realm="Admin Login Required"'},
|
|
)
|
|
|
|
|
|
def requires_admin_basic_auth(view_func):
|
|
@wraps(view_func)
|
|
def wrapped(*args, **kwargs):
|
|
auth = request.authorization
|
|
if not auth:
|
|
return _authenticate_response()
|
|
if not verify_basic_admin(auth.username, auth.password):
|
|
return _authenticate_response()
|
|
return view_func(*args, **kwargs)
|
|
|
|
return wrapped
|