use crate::utils::user_data_utils::user_data_url; ///! User information ///! ///! @author Pierre Hubert #[derive(Clone, PartialEq, Eq, Debug)] pub struct UserID(u64); impl UserID { /// Initialize a new user ID object pub fn new(id: u64) -> UserID { UserID(id) } /// Create a new invalid user id pub fn invalid() -> UserID { UserID(0) } /// Get the current ID stored in this structure pub fn id(&self) -> u64 { self.0 } /// Check if the ID currently stored in this structure is valid or not pub fn is_valid(&self) -> bool { self.0 > 0 } /// Turn this `UserID` object as an instance. An invalid user id will become `None` variant pub fn as_option(&self) -> Option { match self.is_valid() { true => Some(self.clone()), false => None, } } } #[derive(Debug, PartialEq)] pub enum UserPageStatus { OPEN, PUBLIC, PRIVATE, } #[derive(Debug, PartialEq)] #[allow(non_camel_case_types)] pub enum AccountImageVisibility { FRIENDS, COMUNIC_USERS, EVERYONE, } #[derive(Debug)] pub struct User { pub id: UserID, pub email: String, pub password: String, pub first_name: String, pub last_name: String, pub status: UserPageStatus, pub virtual_directory: Option, pub account_image_path: Option, pub account_image_visibility: AccountImageVisibility, pub public_friends_list: bool, pub personal_website: Option, pub public_note: Option, pub block_comments_on_his_page: bool, pub allow_posts_from_friends: bool, pub account_creation_time: u64, pub security_question_1: Option, pub security_answer_1: Option, pub security_question_2: Option, pub security_answer_2: Option, } impl User { /// Get the URL pointing to the default account image pub fn default_account_image_url() -> String { user_data_url(crate::constants::DEFAULT_ACCOUNT_IMAGE) } /// Get the URL pointing to the error account image, when the user is not allowed to see user /// account image pub fn error_account_image_url() -> String { user_data_url(crate::constants::ERROR_ACCOUNT_IMAGE) } /// Check if this user has an account image or not pub fn has_account_image(&self) -> bool { self.account_image_path.is_some() } /// Check out whether security questions have been defined for this user or not pub fn has_security_questions(&self) -> bool { self.security_question_1.is_some() && self.security_answer_1.is_some() && self.security_question_2.is_some() && self.security_answer_2.is_some() } }