mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-01-19 05:33:47 +01:00
fix: /extensions endpoint
This commit is contained in:
parent
7b69852acc
commit
3bae5c92c2
@ -15,6 +15,8 @@ from starlette.responses import HTMLResponse
|
|||||||
from lnbits.core import db
|
from lnbits.core import db
|
||||||
from lnbits.helpers import template_renderer, url_for
|
from lnbits.helpers import template_renderer, url_for
|
||||||
from lnbits.requestvars import g
|
from lnbits.requestvars import g
|
||||||
|
from lnbits.core.models import User
|
||||||
|
from lnbits.decorators import check_user_exists
|
||||||
from lnbits.settings import (LNBITS_ALLOWED_USERS, LNBITS_SITE_TITLE,
|
from lnbits.settings import (LNBITS_ALLOWED_USERS, LNBITS_SITE_TITLE,
|
||||||
SERVICE_FEE)
|
SERVICE_FEE)
|
||||||
|
|
||||||
@ -35,10 +37,13 @@ async def home(request: Request, lightning: str = None):
|
|||||||
return template_renderer().TemplateResponse("core/index.html", {"request": request, "lnurl": lightning})
|
return template_renderer().TemplateResponse("core/index.html", {"request": request, "lnurl": lightning})
|
||||||
|
|
||||||
|
|
||||||
@core_html_routes.get("/extensions")
|
@core_html_routes.get("/extensions", name="core.extensions")
|
||||||
# @validate_uuids(["usr"], required=True)
|
async def extensions(
|
||||||
# @check_user_exists()
|
request: Request,
|
||||||
async def extensions(request: Request, enable: str, disable: str):
|
user: User = Depends(check_user_exists),
|
||||||
|
enable: str= Query(None),
|
||||||
|
disable: str = Query(None)
|
||||||
|
):
|
||||||
extension_to_enable = enable
|
extension_to_enable = enable
|
||||||
extension_to_disable = disable
|
extension_to_disable = disable
|
||||||
|
|
||||||
@ -47,13 +52,18 @@ async def extensions(request: Request, enable: str, disable: str):
|
|||||||
|
|
||||||
if extension_to_enable:
|
if extension_to_enable:
|
||||||
await update_user_extension(
|
await update_user_extension(
|
||||||
user_id=g.user.id, extension=extension_to_enable, active=True
|
user_id=user.id, extension=extension_to_enable, active=True
|
||||||
)
|
)
|
||||||
elif extension_to_disable:
|
elif extension_to_disable:
|
||||||
await update_user_extension(
|
await update_user_extension(
|
||||||
user_id=g.user.id, extension=extension_to_disable, active=False
|
user_id=user.id, extension=extension_to_disable, active=False
|
||||||
)
|
)
|
||||||
return template_renderer().TemplateResponse("core/extensions.html", {"request": request, "user": get_user(g.user.id)})
|
|
||||||
|
# Update user as his extensions have been updated
|
||||||
|
if extension_to_enable or extension_to_disable:
|
||||||
|
user = await get_user(user.id)
|
||||||
|
|
||||||
|
return template_renderer().TemplateResponse("core/extensions.html", {"request": request, "user": user.dict()})
|
||||||
|
|
||||||
|
|
||||||
@core_html_routes.get("/wallet", response_class=HTMLResponse)
|
@core_html_routes.get("/wallet", response_class=HTMLResponse)
|
||||||
|
Loading…
Reference in New Issue
Block a user