use fully_pub::fully_pub; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use sqlx::types::Json; use utils::get_random_human_token; use uuid::Uuid; #[derive(sqlx::Type, Clone, Debug, Serialize, Deserialize, PartialEq)] #[derive(strum_macros::Display)] #[fully_pub] enum UserStatus { Disabled, Invited, Active } #[derive(sqlx::FromRow, Deserialize, Serialize, Debug, Clone)] #[fully_pub] struct User { /// uuid id: String, handle: String, full_name: Option, email: Option, website: Option, avatar_asset_id: Option, password_hash: Option, // argon2 password hash status: UserStatus, roles: Json>, reset_password_token: Option, last_login_at: Option>, created_at: DateTime } impl User { pub fn new( handle: String ) -> User { User { id: Uuid::new_v4().to_string(), handle, full_name: None, email: None, website: None, avatar_asset_id: None, password_hash: None, status: UserStatus::Disabled, roles: Json(Vec::new()), reset_password_token: None, last_login_at: None, created_at: Utc::now() } } pub fn invite(self: &mut Self) { self.reset_password_token = Some(get_random_human_token()); self.status = UserStatus::Invited; } }