diff --git a/app/main.py b/app/main.py index 4873d99..13075c5 100644 --- a/app/main.py +++ b/app/main.py @@ -1735,7 +1735,9 @@ def welcome_email(name: str, setup_url: str) -> tuple[str, str, str]: "Thanks for joining the Inference Cooperative!\n\n" "To finish setting up your account and start using private AI chat, " "click the link below to create your account:\n\n" - f"{setup_url}\n\n" + f"{setup_url}\n\n" + + "This link expires after seven days. If it lapses, write to\n" + "info@inference.coop and we will send a fresh one.\n\n" "This takes about a minute.\n\n" "Questions? Reply to this email or write to info@inference.coop.\n\n" "— The Inference Cooperative\n" @@ -1782,7 +1784,7 @@ def welcome_email(name: str, setup_url: str) -> tuple[str, str, str]:
Thanks for joining the Inference Cooperative.
Finish setting up your account to start using private AI chat.
- Finish setup + Finish setupThis link expires after seven days. If it lapses, write to info@inference.coop and we will send a fresh one.
This takes about a minute.
@@ -2794,7 +2796,9 @@ def guest_invitation_email(name: str, setup_url: str, inviter_name: str = "") -> f"API. Access runs for {int(GUEST_DAYS)} days from today; the credits\n" "themselves don't expire early.\n\n" "To accept, create your account — it takes about a minute:\n\n" - f"{setup_url}\n\n" + f"{setup_url}\n\n" + + "This link expires after seven days. If it lapses, write to\n" + "info@inference.coop and we will send a fresh one.\n\n" "If you like it, become a member: pay on a sliding scale, and\n" "receive a $15/month allowance, plus optional credit packs — plus a\n" "say in how it's run.\n\n" @@ -2822,7 +2826,7 @@ def guest_invitation_email(name: str, setup_url: str, inviter_name: str = "") ->{html_invited} — a member-governed AI cooperative running open models.
Your invitation comes with $2 of credits for the co-op's chat and API. Access runs for {int(GUEST_DAYS)} days from today; the credits themselves don't expire early.
- Create your account + Create your accountThis link expires after seven days. If it lapses, write to info@inference.coop and we will send a fresh one.
This takes about a minute.
If you like it, become a member.
Pay on a sliding scale, and receive a $15/month allowance, plus optional credit packs — plus a say in how it's run.
@@ -2857,7 +2861,9 @@ def guest_member_congrats_email(name: str, setup_url: str | None) -> tuple[str, setup_line = "" if setup_url: setup_line = (f"Your account isn't set up yet — one minute and you're in:\n\n" - f"{setup_url}\n\n") + f"{setup_url}\n\n" + + "This link expires after seven days. If it lapses, write to\n" + "info@inference.coop and we will send a fresh one.\n\n") text = ( f"Hi {name},\n\n" "Great news: your guest account is now a full membership. Nothing about\n" @@ -4672,6 +4678,80 @@ async def admin_provision_guest(request: Request): } +async def resend_guest_setup_email(email: str) -> dict: + """Issue a FRESH Cloudron setup link and resend the guest invitation email. + + Cloudron's account-setup links expire after seven days, so an unaccepted + invitation goes stale — the member did nothing wrong. Never resends to an + account that has already been activated (inviteAccepted), so this is safe to + sweep across old invites. + """ + email = (email or "").strip().lower() + conn = get_db() + row = conn.execute("SELECT cloudron_user_id FROM members WHERE lower(email) = ?", + (email,)).fetchone() + guest = conn.execute( + "SELECT inviter_email FROM guests WHERE lower(recipient_email) = ? " + "ORDER BY created_at DESC LIMIT 1", (email,)).fetchone() + conn.close() + if not row or not row[0]: + return {"email": email, "sent": False, "reason": "no Cloudron user on file"} + user_id = row[0] + try: + if await cloudron_is_activated(user_id): + return {"email": email, "sent": False, "reason": "already activated"} + except Exception as exc: # noqa: BLE001 + logger.warning("resend %s: activation check failed: %s", email, exc) + setup_url = await cloudron_get_invite_link(user_id) + if not setup_url: + return {"email": email, "sent": False, "reason": "no invite link returned"} + name = email.split("@")[0].replace(".", " ").replace("_", " ").title() + subject, text, html = guest_invitation_email(name, setup_url, + guest[0] if guest else "") + ok = send_email(email, subject, text, html) + if ok: + conn = get_db() + conn.execute("UPDATE members SET welcome_sent_at = datetime('now') " + "WHERE lower(email) = ?", (email,)) + conn.commit(); conn.close() + return {"email": email, "sent": bool(ok), + "inviter": guest[0] if guest else None} + + +@app.post("/admin/guest-invites/resend") +async def admin_guest_resend(request: Request): + """Body: {"email": "guest@..."} — one fresh setup link.""" + if not ADMIN_TOKEN or request.headers.get("x-admin-token") != ADMIN_TOKEN: + raise HTTPException(401, "Invalid admin token") + body = await request.json() if request.headers.get("content-type", "").startswith("application/json") else {} + email = (body.get("email") or "").strip().lower() + if not email: + raise HTTPException(400, "email is required") + return await resend_guest_setup_email(email) + + +@app.post("/admin/guest-invites/resend-stale") +async def admin_guest_resend_stale(request: Request): + """Resend every unaccepted guest invite older than `days` (default 7).""" + if not ADMIN_TOKEN or request.headers.get("x-admin-token") != ADMIN_TOKEN: + raise HTTPException(401, "Invalid admin token") + body = await request.json() if request.headers.get("content-type", "").startswith("application/json") else {} + days = int(body.get("days") or 7) + conn = get_db() + emails = [r[0] for r in conn.execute( + "SELECT DISTINCT lower(g.recipient_email) FROM guests g " + "WHERE g.status = 'active' AND g.created_at <= datetime('now', ?) " + "ORDER BY g.created_at", (f"-{days} days",)).fetchall()] + conn.close() + results = [] + for email in emails: + try: + results.append(await resend_guest_setup_email(email)) + except Exception as exc: # noqa: BLE001 + results.append({"email": email, "sent": False, "reason": str(exc)[:120]}) + return {"window_days": days, "candidates": len(emails), "results": results} + + @app.post("/admin/guest-convert") @limiter.limit("20/minute") async def admin_guest_convert(request: Request):