-
Notifications
You must be signed in to change notification settings - Fork 14
/
views.py
91 lines (78 loc) · 2.93 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from http import HTTPStatus
from fastapi import APIRouter, Depends, HTTPException, Request
from lnbits.core.models import User
from lnbits.decorators import check_user_exists
from lnbits.helpers import template_renderer
from lnbits.settings import settings
from starlette.responses import HTMLResponse
from .crud import get_clean_tpos, get_tpos
from .models import TposClean
tpos_generic_router = APIRouter()
def tpos_renderer():
return template_renderer(["tpos/templates"])
@tpos_generic_router.get("/", response_class=HTMLResponse)
async def index(request: Request, user: User = Depends(check_user_exists)):
return tpos_renderer().TemplateResponse(
"tpos/index.html", {"request": request, "user": user.json()}
)
@tpos_generic_router.get("/{tpos_id}")
async def tpos(request: Request, tpos_id):
tpos = await get_tpos(tpos_id)
if not tpos:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
)
withdraw_pin_open = 0
if tpos.withdraw_pin_disabled:
withdraw_pin_open = tpos.withdraw_pin
tpos_clean = TposClean(**tpos.dict())
response = tpos_renderer().TemplateResponse(
"tpos/tpos.html",
{
"request": request,
"tpos": tpos_clean.json(),
"withdraw_pin_open": withdraw_pin_open,
"withdraw_maximum": tpos.withdraw_maximum,
"web_manifest": f"/tpos/manifest/{tpos_id}.webmanifest",
},
)
# This is just for hiding the user-account UI elements.
# It is not a security measure.
response.set_cookie("is_lnbits_user_authorized", "false", path=request.url.path)
return response
@tpos_generic_router.get("/manifest/{tpos_id}.webmanifest")
async def manifest(tpos_id: str):
tpos = await get_clean_tpos(tpos_id)
if not tpos:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
)
return {
"short_name": settings.lnbits_site_title,
"name": tpos.name + " - " + settings.lnbits_site_title,
"icons": [
{
"src": (
settings.lnbits_custom_logo
if settings.lnbits_custom_logo
else "https://cdn.jsdelivr.net/gh/lnbits/[email protected]/docs/logos/lnbits.png"
),
"type": "image/png",
"sizes": "900x900",
}
],
"start_url": "/tpos/" + tpos_id,
"background_color": "#1F2234",
"description": "Bitcoin Lightning tPOS",
"display": "standalone",
"scope": "/tpos/" + tpos_id,
"theme_color": "#1F2234",
"shortcuts": [
{
"name": tpos.name + " - " + settings.lnbits_site_title,
"short_name": tpos.name,
"description": tpos.name + " - " + settings.lnbits_site_title,
"url": "/tpos/" + tpos_id,
}
],
}