Guest-invite form: keep a name field, optional and clearly labelled
Final operator preference: the standard form is the guest's email (required) plus an OPTIONAL display name, labelled 'Their name (optional)'. The name passes through to provisioning as the initial display name (the Cloudron path fills only empty names and never overwrites one the guest sets at setup); an empty name is never derived from the email.
This commit is contained in:
1 parent
d6d960324a
commit
575338a577
1 file changed
+21
-14
+21
-14
@@ -201,22 +201,24 @@ async def api_set_credits(request: Request):
|
||||
async def api_provision_guest(request: Request):
|
||||
"""Provision a guest account via the portal's /admin/provision-guest.
|
||||
|
||||
The standard guest-invite form: ONE field (the guest's email). No name is
|
||||
collected and none is derived — the guest chooses their own display name
|
||||
and username during Cloudron account setup, and the invitation greets
|
||||
neutrally. The portal records the co-op's ADMIN account as the inviter —
|
||||
admins are not bound by the member's one-per-30-days cap, and the
|
||||
recipient-side guards (one guest per recipient ever, no existing portal
|
||||
row) still run there. A refusal is surfaced to the operator as-is.
|
||||
The standard guest-invite form: the guest's email (required) plus an
|
||||
OPTIONAL display name — passed through as the guest's initial display
|
||||
name; when empty, nothing is derived (the guest chooses their own name
|
||||
at Cloudron setup and the invitation greets neutrally). The portal
|
||||
records the co-op's ADMIN account as the inviter — admins are not bound
|
||||
by the member's one-per-30-days cap, and the recipient-side guards (one
|
||||
guest per recipient ever, no existing portal row) still run there. A
|
||||
refusal is surfaced to the operator as-is.
|
||||
"""
|
||||
if not is_admin(request):
|
||||
return JSONResponse({"error": "forbidden"}, status_code=403)
|
||||
body = await request.json()
|
||||
email = (body.get("email") or "").strip().lower()
|
||||
name = (body.get("name") or "").strip()
|
||||
if not email or "@" not in email:
|
||||
return JSONResponse({"error": "A valid recipient email is required"}, status_code=400)
|
||||
try:
|
||||
return await portal_post("/admin/provision-guest", {"email": email})
|
||||
return await portal_post("/admin/provision-guest", {"email": email, "name": name})
|
||||
except HTTPException as e:
|
||||
return JSONResponse({"error": e.detail}, status_code=e.status_code)
|
||||
|
||||
@@ -492,6 +494,8 @@ PAGE_HTML = """<!DOCTYPE html>
|
||||
<form class="guest-invite-form" id="guest-invite-form" onsubmit="sendGuestAccess(event)">
|
||||
<label class="guest-invite-label" for="guest-email">Their email</label>
|
||||
<input id="guest-email" type="email" required placeholder="friend@example.com" autocomplete="off" inputmode="email" maxlength="254" />
|
||||
<label class="guest-invite-label" for="guest-name">Their name (optional)</label>
|
||||
<input id="guest-name" type="text" maxlength="80" autocomplete="off" placeholder="Only if you know it" />
|
||||
<button type="submit" class="guest-invite-btn" id="guest-send">Send invite</button>
|
||||
</form>
|
||||
</div>
|
||||
@@ -1475,26 +1479,29 @@ async function addBalance(email) {
|
||||
}
|
||||
|
||||
// Guest action: provision a $5 guest account — the standard guest-invite form
|
||||
// (ONE field: the guest's email). The inviter is always the co-op's ADMIN
|
||||
// account, recorded by the portal; admins have no monthly cap. The portal
|
||||
// enforces the recipient-side guards (one guest per recipient ever, no
|
||||
// existing portal row) and reports a clear refusal.
|
||||
// (the guest's email, required, plus an OPTIONAL display name; if left empty
|
||||
// the guest sets their own at Cloudron setup and the invitation greets
|
||||
// neutrally). The inviter is always the co-op's ADMIN account, recorded by
|
||||
// the portal; admins have no monthly cap. The portal enforces the
|
||||
// recipient-side guards (one guest per recipient ever, no existing portal
|
||||
// row) and reports a clear refusal.
|
||||
async function sendGuestAccess(ev) {
|
||||
if (ev) ev.preventDefault();
|
||||
const email = ($('guest-email').value || '').trim();
|
||||
const name = ($('guest-name').value || '').trim();
|
||||
const btn = $('guest-send');
|
||||
if (!email || email.indexOf('@') < 1) { flash("Enter the guest's email", false); return; }
|
||||
btn.disabled = true; btn.textContent = "Sending…";
|
||||
try {
|
||||
const r = await fetch('/api/provision-guest', {
|
||||
method: 'POST', headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({ email })
|
||||
body: JSON.stringify({ email, name })
|
||||
});
|
||||
const d = await r.json().catch(() => ({}));
|
||||
if (!r.ok || d.error) { flash(d.error || ('Could not send guest access (' + r.status + ')'), false); return; }
|
||||
flash('Invite sent — ' + email + ' has $5 of credits (expires in ' + (d.expires_in_days || 60) +
|
||||
' days). The welcome email is on its way.', true);
|
||||
$('guest-email').value = '';
|
||||
$('guest-email').value = ''; $('guest-name').value = '';
|
||||
load();
|
||||
} catch (e) { flash('Guest access failed: ' + e.message, false); }
|
||||
finally { btn.disabled = false; btn.textContent = 'Send invite'; }
|
||||
|
||||
Reference in new issue
Block a user