Inviting shown but off until launch; waitlist confirmation; waitlist invites with a package
CI / test (push) Successful in 1m35s
CI / build (push) Successful in 8m7s
CI / deploy (push) Skipped

USER_INVITES (default false) keeps users from inviting others until the
launch: the 'Meghívom' option and a 'Hívd meg, akit szeretsz' card on the
persons page are shown, disabled, with 'Hamarosan'; the backend refuses
with invites_disabled (admins may always).

Joining the waitlist sends one confirmation e-mail (waitlist_joined) with a
link that takes the address off the list and opts it out; at most 10 per
address in 15 minutes. Admins can pick a package for waitlist invitations,
like on the invitation form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-19 11:07:13 +00:00
co-authored by Claude Opus 5.5
parent dad16fe463
commit 8e1205359d
18 changed files with 285 additions and 26 deletions
+35 -5
View File
@@ -587,10 +587,12 @@ pub async fn unsubscribe(
WithRejection(Query(q), _): WithRejection<Query<TokenQuery>, ApiError>,
) -> ApiResult<Json<Value>> {
let mut tx = state.db.begin().await?;
// The link of a site invitation, or of a "how compatible are we?" one a user had us e-mail.
// The link of a site invitation, of a "how compatible are we?" one a user
// had us e-mail, or of the waitlist confirmation.
let email: Option<String> = sqlx::query_scalar(
"SELECT i.email FROM invitation_tokens t JOIN invitations i ON i.id = t.invitation_id WHERE t.token_hash = $1 \
UNION ALL SELECT invitee_email FROM synastry_invites WHERE token_hash = $1 AND invitee_email IS NOT NULL \
UNION ALL SELECT email FROM waitlist WHERE token_hash = $1 \
LIMIT 1",
)
.bind(db::token_hash(q.token.trim()))
@@ -607,6 +609,7 @@ pub async fn unsubscribe(
.bind(&email)
.execute(&mut *tx)
.await?;
sqlx::query("DELETE FROM waitlist WHERE email = $1").bind(&email).execute(&mut *tx).await?;
tx.commit().await?;
Ok(Json(json!({ "unsubscribed": true })))
}
@@ -621,19 +624,46 @@ pub struct WaitlistRequest {
/// Joins the waitlist. Always answers the same, so it does not reveal who has an account.
pub async fn join_waitlist(
State(state): St,
headers: axum::http::HeaderMap,
WithRejection(Json(req), _): Body<WaitlistRequest>,
) -> ApiResult<(StatusCode, Json<Value>)> {
let email = normalize_email(&req.email)?;
let locale = validate_locale(&state, req.locale.as_deref())?;
sqlx::query(
"INSERT INTO waitlist (email, locale) SELECT $1, $2 \
// Every sign-up sends an e-mail: a few per address, so the form cannot be used to flood someone.
let ip = headers
.get("x-forwarded-for")
.and_then(|v| v.to_str().ok())
.and_then(|v| v.split(',').next())
.map(str::trim)
.unwrap_or("unknown");
let key = format!("waitlist:{ip}");
state.login_limiter.check(&key)?;
let token = db::new_token();
let mut tx = state.db.begin().await?;
let added = sqlx::query(
"INSERT INTO waitlist (email, locale, token_hash) SELECT $1, $2, $3 \
WHERE NOT EXISTS (SELECT 1 FROM users WHERE email = $1) \
AND (SELECT count(*) FROM waitlist) < 10000 \
ON CONFLICT DO NOTHING",
)
.bind(&email)
.bind(&locale)
.execute(&state.db)
.await?;
.bind(db::token_hash(&token))
.execute(&mut *tx)
.await?
.rows_affected()
== 1;
// A confirmation, once, unless the address asked for no more mail from us.
if added && !opted_out(&mut tx, &email).await? {
let (_, unsubscribe_url, unsubscribe_post_url) = links(&state, &token);
let payload = json!({
"url": state.config.public_base_url,
"unsubscribe_url": unsubscribe_url,
"unsubscribe_post_url": unsubscribe_post_url,
});
queue_email_to(&mut tx, None, &email, "waitlist_joined", &locale, payload).await?;
state.login_limiter.failed(&key);
}
tx.commit().await?;
Ok((StatusCode::ACCEPTED, Json(json!({ "ok": true }))))
}