mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2024-11-19 09:54:21 +01:00
added require_invoice_key
clean up
This commit is contained in:
parent
0ef0188462
commit
df2345bda9
@ -171,6 +171,24 @@ async def require_admin_key(
|
||||
else:
|
||||
return wallet
|
||||
|
||||
async def require_invoice_key(
|
||||
r: Request,
|
||||
api_key_header: str = Security(api_key_header),
|
||||
api_key_query: str = Security(api_key_query),
|
||||
):
|
||||
token = api_key_header if api_key_header else api_key_query
|
||||
|
||||
wallet = await get_key_type(r, token)
|
||||
|
||||
if wallet.wallet_type > 1:
|
||||
# If wallet type is not invoice then return the unauthorized status
|
||||
# This also covers when the user passes an invalid key type
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED, detail="Invoice (or Admin) key required."
|
||||
)
|
||||
else:
|
||||
return wallet
|
||||
|
||||
|
||||
async def check_user_exists(usr: UUID4) -> User:
|
||||
g().user = await get_user(usr.hex)
|
||||
|
@ -6,11 +6,10 @@ from fastapi.params import Depends
|
||||
from starlette.exceptions import HTTPException
|
||||
|
||||
from lnbits.decorators import (
|
||||
WalletAdminKeyChecker,
|
||||
WalletInvoiceKeyChecker,
|
||||
WalletTypeInfo,
|
||||
get_key_type,
|
||||
require_admin_key,
|
||||
require_invoice_key,
|
||||
)
|
||||
from lnbits.extensions.satspay import satspay_ext
|
||||
|
||||
@ -26,15 +25,15 @@ from .models import CreateCharge
|
||||
|
||||
#############################CHARGES##########################
|
||||
|
||||
@satspay_ext.post("/api/v1/charge", dependencies=[Depends(WalletInvoiceKeyChecker())])
|
||||
@satspay_ext.post("/api/v1/charge")
|
||||
async def api_charge_create(
|
||||
data: CreateCharge,
|
||||
wallet: WalletTypeInfo = Depends(get_key_type)
|
||||
wallet: WalletTypeInfo = Depends(require_invoice_key)
|
||||
):
|
||||
charge = await create_charge(user=wallet.wallet.user, data=data)
|
||||
return charge.dict()
|
||||
|
||||
@satspay_ext.put("/api/v1/charge/{charge_id}", dependencies=[Depends(WalletAdminKeyChecker())])
|
||||
@satspay_ext.put("/api/v1/charge/{charge_id}")
|
||||
async def api_charge_update(
|
||||
data: CreateCharge,
|
||||
wallet: WalletTypeInfo = Depends(require_admin_key),
|
||||
|
Loading…
Reference in New Issue
Block a user