Invitation-only sign-up, invitation e-mails and waitlist
- SIGNUP_MODE=invite (default): a new account needs an open invitation for its address, or the invitation link (then any Google account will do) - admin page "Meghívók": invite many addresses at once, personal message, resend (max 3, 24 h apart), revoke, copy link, mail preview and test copy, waitlist - invitation e-mail in HTML and plain text; Message-ID on the sender's domain, List-Unsubscribe with one-click POST, opt-out list (hashes only) - e-mail texts moved to a shared crate (crates/email-templates) - login page shows the invitation; waitlist for uninvited visitors; unsubscribe page; privacy policy updated - docs/levelkuldes.md: Brevo, DNS (SPF, DKIM, DMARC) and the SMTP setup Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -113,16 +113,28 @@ async fn consume_token(conn: &mut PgConnection, token: &str, purpose: &str) -> R
|
||||
row.map(|(id,)| id).ok_or(ApiError::InvalidToken)
|
||||
}
|
||||
|
||||
/// Queues an e-mail for the worker.
|
||||
/// Queues an e-mail to a user for the worker.
|
||||
pub async fn queue_email(conn: &mut PgConnection, user: &User, template: &str, payload: Value) -> Result<(), ApiError> {
|
||||
queue_email_to(conn, Some(user.id), &user.email, template, &user.locale, payload).await
|
||||
}
|
||||
|
||||
/// Queues an e-mail to any address (e.g. an invitation) for the worker.
|
||||
pub async fn queue_email_to(
|
||||
conn: &mut PgConnection,
|
||||
user_id: Option<Uuid>,
|
||||
to: &str,
|
||||
template: &str,
|
||||
locale: &str,
|
||||
payload: Value,
|
||||
) -> Result<(), ApiError> {
|
||||
sqlx::query(
|
||||
"INSERT INTO email_outbox (id, user_id, to_email, template, locale, payload) VALUES ($1, $2, $3, $4, $5, $6)",
|
||||
)
|
||||
.bind(Uuid::now_v7())
|
||||
.bind(user.id)
|
||||
.bind(&user.email)
|
||||
.bind(user_id)
|
||||
.bind(to)
|
||||
.bind(template)
|
||||
.bind(&user.locale)
|
||||
.bind(locale)
|
||||
.bind(payload)
|
||||
.execute(conn)
|
||||
.await?;
|
||||
@@ -156,6 +168,8 @@ pub struct RegisterRequest {
|
||||
password: String,
|
||||
display_name: Option<String>,
|
||||
locale: Option<String>,
|
||||
/// The invitation link's token, while sign-up needs an invitation.
|
||||
invite_token: Option<String>,
|
||||
}
|
||||
|
||||
/// Password endpoints answer 403 while `PASSWORD_LOGIN` is off.
|
||||
@@ -185,6 +199,7 @@ pub async fn register(
|
||||
if exists.is_some() {
|
||||
return Err(ApiError::conflict("email_taken", "an account with this e-mail address already exists"));
|
||||
}
|
||||
super::invitations::admit(&state, &mut tx, &email, req.invite_token.as_deref()).await?;
|
||||
let user_id = Uuid::now_v7();
|
||||
sqlx::query("INSERT INTO users (id, email, display_name, locale) VALUES ($1, $2, $3, $4)")
|
||||
.bind(user_id)
|
||||
@@ -201,6 +216,7 @@ pub async fn register(
|
||||
.bind(&email)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
super::invitations::mark_accepted(&mut tx, user_id, &email, req.invite_token.as_deref()).await?;
|
||||
let mut user = load_user(&mut tx, user_id).await?;
|
||||
apply_bootstrap_admin(&state, &mut tx, &mut user).await?;
|
||||
queue_verification(&state, &mut tx, &user).await?;
|
||||
@@ -266,6 +282,8 @@ pub async fn login(
|
||||
pub struct GoogleRequest {
|
||||
/// ID token (JWT) from Google Identity Services.
|
||||
id_token: String,
|
||||
/// The invitation link's token, while sign-up needs an invitation.
|
||||
invite_token: Option<String>,
|
||||
}
|
||||
|
||||
/// Logs in with Google. An unknown Google account is linked to the existing
|
||||
@@ -311,6 +329,7 @@ pub async fn google(
|
||||
(id, false)
|
||||
}
|
||||
None => {
|
||||
super::invitations::admit(&state, &mut tx, &email, req.invite_token.as_deref()).await?;
|
||||
let id = Uuid::now_v7();
|
||||
let locale = claims
|
||||
.locale
|
||||
@@ -328,6 +347,7 @@ pub async fn google(
|
||||
.bind(locale)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
super::invitations::mark_accepted(&mut tx, id, &email, req.invite_token.as_deref()).await?;
|
||||
(id, true)
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user