portal: setup links expire after seven days — say so, and offer a resend
ci/woodpecker/push/woodpecker Pipeline was canceled

Cloudron's account-setup links lapse after a week, so an unaccepted invitation goes
stale through no fault of the member. Both setup emails now state the lifetime and
where to ask for a new link. New admin routes: resend one invite (fresh link, never
to an activated account) and resend every unaccepted guest invite older than N days.
This commit is contained in:
inference-admin committed 2026-11-17 16:12:40 +00:00
1 parent e6db73c6bb
commit 0ae9634f70
1 file changed
+85 -5
+85 -5
View File
@@ -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]:
<h1 style="margin:0 0 12px;font-size:24px;font-weight:700;color:#2d3327;">Welcome, {name}</h1>
<p style="margin:0 0 8px;font-size:16px;color:#6b7a62;line-height:1.5;">Thanks for joining the <strong style="color:#2d3327;">Inference Cooperative</strong>.</p>
<p style="margin:0 0 28px;font-size:15px;color:#6b7a62;line-height:1.5;">Finish setting up your account to start using private AI chat.</p>
<a href="{setup_url}" style="display:inline-block;background:#5b8c5a;color:#ffffff;text-decoration:none;padding:14px 36px;border-radius:10px;font-size:16px;font-weight:600;">Finish setup</a>
<a href="{setup_url}" style="display:inline-block;background:#5b8c5a;color:#ffffff;text-decoration:none;padding:14px 36px;border-radius:10px;font-size:16px;font-weight:600;">Finish setup</a><p style="margin:14px 0 0;font-size:13px;color:#8a9683;line-height:1.5;">This link expires after seven days. If it lapses, write to <a href="mailto:info@inference.coop" style="color:#5b8c5a;">info@inference.coop</a> and we will send a fresh one.</p>
<p style="margin:28px 0 0;font-size:13px;color:#94a08c;line-height:1.5;">This takes about a minute.</p>
</td>
</tr>
@@ -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 = "") ->
<h1 style="margin:0 0 12px;font-size:24px;font-weight:700;color:#2d3327;">{h1}</h1>
<p style="margin:0 0 8px;font-size:16px;color:#6b7a62;line-height:1.5;">{html_invited} — a member-governed AI cooperative running open models.</p>
<p style="margin:0 0 24px;font-size:15px;color:#6b7a62;line-height:1.5;">Your invitation comes with <strong style="color:#2d3327;">$2 of credits</strong> for the co-op's chat and API. Access runs for {int(GUEST_DAYS)} days from today; the credits themselves don't expire early.</p>
<a href="{setup_url}" style="display:inline-block;background:#5b8c5a;color:#ffffff;text-decoration:none;padding:14px 36px;border-radius:10px;font-size:16px;font-weight:600;">Create your account</a>
<a href="{setup_url}" style="display:inline-block;background:#5b8c5a;color:#ffffff;text-decoration:none;padding:14px 36px;border-radius:10px;font-size:16px;font-weight:600;">Create your account</a><p style="margin:14px 0 0;font-size:13px;color:#8a9683;line-height:1.5;">This link expires after seven days. If it lapses, write to <a href="mailto:info@inference.coop" style="color:#5b8c5a;">info@inference.coop</a> and we will send a fresh one.</p>
<p style="margin:14px 0 28px;font-size:13px;color:#94a08c;line-height:1.5;">This takes about a minute.</p>
<p style="margin:0 0 10px;font-size:15px;color:#2d3327;line-height:1.5;"><strong>If you like it, become a member.</strong></p>
<p style="margin:0 0 16px;font-size:14px;color:#6b7a62;line-height:1.5;">Pay on a sliding scale, and receive a $15/month allowance, plus optional credit packs — plus a say in how it's run.</p>
@@ -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):