diff --git a/app/main.py b/app/main.py index 8176268..3fcb425 100644 --- a/app/main.py +++ b/app/main.py @@ -218,6 +218,42 @@ async def api_set_matrix_mxid(request: Request): return JSONResponse({"error": e.detail}, status_code=e.status_code) +@app.get("/api/gift-status") +async def api_gift_status(request: Request): + """What became of the caller's gift account (guest view). + + Loaded when the usage view refuses a GUEST (access ended): the portal + answers for ended gift accounts so the dashboard can say plainly that + access ended, the data is kept, and a membership is still available. + Members get guest: false — the caller falls back to the usage error. + """ + identity = get_user_identity(request) + if not identity: + return JSONResponse({"error": "unauthenticated"}, status_code=401) + try: + return await broker_get(identity, "/broker/gift-status") + except HTTPException as e: + return JSONResponse({"error": e.detail}, status_code=e.status_code) + + +@app.post("/api/cancel-gift") +async def api_cancel_gift(request: Request): + """End the caller's own gift account (self-service cancel, guest view). + + One hop to the portal broker, which holds the actual semantics: access + ends immediately, unspent credit returns to the co-op, the ledger keeps + the trail, and a repeat call is a no-op. Gift accounts only — the portal + refuses a paying member with 403. + """ + identity = get_user_identity(request) + if not identity: + return JSONResponse({"error": "unauthenticated"}, status_code=401) + try: + return await broker_post(identity, "/broker/cancel-gift") + except HTTPException as e: + return JSONResponse({"error": e.detail}, status_code=e.status_code) + + # --------------------------------------------------------------------------- # OIDC routes — authorization-code flow against Cloudron's OIDC provider. # Active only when the `oidc` addon is configured (CLOUDRON_OIDC_* present). @@ -393,6 +429,36 @@ PAGE_HTML = """ .buy-hint { color: var(--muted); font-size: 12px; } a.buy-docs { color: var(--green-deep); font-weight: 600; text-decoration: none; white-space: nowrap; } a.buy-docs:hover { text-decoration: underline; } + /* The membership-payment line: how a membership ends, in one plain + sentence under the balance. Members only (a guest has no payment). */ + .oc-note { color: var(--muted); font-size: 12px; margin-top: 12px; } + .oc-note a { color: var(--green-deep); font-weight: 600; text-decoration: none; } + .oc-note a:hover { text-decoration: underline; } + /* Guest self-service cancel: a quiet link that reveals the confirm step, + then ends the gift. Sits under the Become-a-member row. */ + .cancel-row { margin-top: 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; } + .cancel-link { + font-family: inherit; cursor: pointer; background: none; border: none; + color: var(--danger); font-size: 12px; font-weight: 600; text-decoration: underline; + padding: 0; + } + .cancel-confirm-note { color: var(--muted); font-size: 12px; } + button.cancel-go { + font-family: inherit; cursor: pointer; background: #fff; color: var(--danger); + border: 1px solid var(--danger); border-radius: 8px; font-size: 13px; + font-weight: 600; padding: 6px 14px; + } + button.cancel-go:hover { background: var(--danger); color: #fff; } + button.cancel-keep { + font-family: inherit; cursor: pointer; background: none; border: none; + color: var(--muted); font-size: 12px; font-weight: 600; text-decoration: underline; + } + /* The ended state: access over, account and data kept, membership one + contribution away. Replaces the usage numbers for an ended guest. */ + .ended { padding: 4px 0 2px; } + .ended h3 { font-size: 17px; font-weight: 700; margin-bottom: 8px; color: var(--ink); } + .ended .hint { color: var(--muted); font-size: 13px; margin-bottom: 10px; } + .ended .buy-btn { margin-top: 4px; } .models { margin-top: 16px; } .model-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; @@ -574,7 +640,7 @@ PAGE_HTML = """
Keys let you use the co-op's AI from your own tools. They draw from the same balance as chat.
' + line + '
' + + 'Your account and data are kept. Become a member anytime with the same login — your account resumes as a full membership, and a member can re-invite you.
' + + 'Become a member' + + '