add: invite codes

This commit is contained in:
trisua 2025-06-22 13:03:02 -04:00
parent d1a074eaeb
commit 626c6711ef
19 changed files with 410 additions and 10 deletions

View file

@ -49,6 +49,9 @@ pub struct User {
/// A list of the IDs of all accounts the user has signed into through the UI.
#[serde(default)]
pub associated: Vec<usize>,
/// The ID of the [`InviteCode`] this user provided during registration.
#[serde(default)]
pub invite_code: usize,
}
pub type UserConnections =
@ -283,6 +286,7 @@ impl User {
stripe_id: String::new(),
grants: Vec::new(),
associated: Vec::new(),
invite_code: 0,
}
}
@ -591,3 +595,25 @@ impl UserWarning {
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct InviteCode {
pub id: usize,
pub created: usize,
pub owner: usize,
pub code: String,
pub is_used: bool,
}
impl InviteCode {
/// Create a new [`InviteCode`].
pub fn new(owner: usize) -> Self {
Self {
id: Snowflake::new().to_string().parse::<usize>().unwrap(),
created: unix_epoch_timestamp(),
owner,
code: salt(),
is_used: false,
}
}
}