use std::collections::HashMap; use super::{ oauth::AuthGrant, permissions::{FinePermission, SecondaryPermission}, }; use serde::{Deserialize, Serialize}; use totp_rs::TOTP; use tetratto_shared::{ hash::{hash_salted, salt}, snow::Snowflake, unix_epoch_timestamp, }; /// `(ip, token, creation timestamp)` pub type Token = (String, String, usize); #[derive(Clone, Debug, Serialize, Deserialize)] pub struct User { pub id: usize, pub created: usize, pub username: String, pub password: String, pub salt: String, pub settings: UserSettings, pub tokens: Vec, pub permissions: FinePermission, pub is_verified: bool, pub notification_count: usize, pub follower_count: usize, pub following_count: usize, pub last_seen: usize, /// The TOTP secret for this profile. An empty value means the user has TOTP disabled. #[serde(default)] pub totp: String, /// The TOTP recovery codes for this profile. #[serde(default)] pub recovery_codes: Vec, #[serde(default)] pub post_count: usize, #[serde(default)] pub request_count: usize, /// External service connection details. #[serde(default)] pub connections: UserConnections, /// The user's Stripe customer ID. #[serde(default)] pub stripe_id: String, /// The grants associated with the user's account. #[serde(default)] pub grants: Vec, /// A list of the IDs of all accounts the user has signed into through the UI. #[serde(default)] pub associated: Vec, /// The ID of the [`InviteCode`] this user provided during registration. #[serde(default)] pub invite_code: usize, /// Secondary permissions because the regular permissions struct ran out of possible bits. #[serde(default)] pub secondary_permissions: SecondaryPermission, /// Users collect achievements through little actions across the site. #[serde(default)] pub achievements: Vec, /// If the account was registered as a "bought" account, the user should not /// be allowed to actually use the account if they haven't paid for supporter yet. #[serde(default)] pub awaiting_purchase: bool, /// This value cannot be changed after account creation. This value is used to /// lock the user's account again if the subscription is cancelled and they haven't /// used an invite code. #[serde(default)] pub was_purchased: bool, /// This value is updated for every **new** littleweb browser session. /// /// This means the user can only have one of these sessions open at once /// (unless this token is stored somewhere with a way to say we already have one, /// but this does not happen yet). /// /// Without this token, the user can still use the browser, they just cannot /// view pages which require authentication (all `$` routes). #[serde(default)] pub browser_session: String, /// The reason the user was banned. #[serde(default)] pub ban_reason: String, /// IDs of channels the user has muted. #[serde(default)] pub channel_mutes: Vec, /// If the user is deactivated. Deactivated users act almost like deleted /// users, but their data is not wiped. #[serde(default)] pub is_deactivated: bool, /// The time at which the user's ban will automatically expire. #[serde(default)] pub ban_expire: usize, /// The number of coins the user has. #[serde(default)] pub coins: i32, /// The IDs of Stripe checkout sessions that this user has successfully completed. /// /// This should be checked BEFORE applying purchases to ensure that the user hasn't /// already applied this purchase. #[serde(default)] pub checkouts: Vec, /// The IDs of products to be applied to the user's profile. #[serde(default)] pub applied_configurations: Vec<(AppliedConfigType, usize)>, /// The time in which the user last consented to the site's policies. #[serde(default)] pub last_policy_consent: usize, } pub type UserConnections = HashMap; #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] pub enum AppliedConfigType { /// An HTML `