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

@ -1,7 +1,7 @@
use std::net::SocketAddr;
/// How many bytes should be taken as the prefix (from the begining of the address).
pub(crate) const IPV6_PREFIX_BYTES: usize = 16;
pub(crate) const IPV6_PREFIX_BYTES: usize = 11;
/// The protocol of a [`RemoteAddr`].
#[derive(Clone, Debug, PartialEq, Eq)]

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,
}
}
}

View file

@ -39,6 +39,7 @@ bitflags! {
const MANAGE_APPS = 1 << 28;
const MANAGE_JOURNALS = 1 << 29;
const MANAGE_NOTES = 1 << 30;
const MANAGE_INVITES = 1 << 31;
const _ = !0;
}