diff --git a/src/domain/user/credential_type.rs b/src/domain/user/credential_type.rs new file mode 100644 index 0000000..bfcf47e --- /dev/null +++ b/src/domain/user/credential_type.rs @@ -0,0 +1,30 @@ +use std::fmt::Display; +use serde::{Serialize, Deserialize}; + +#[derive(Serialize, Deserialize, Debug)] +pub enum CredentialType { + PhoneNumber, + Email +} +impl CredentialType { + pub fn get_max_length(&self) -> i32 { + match self { + CredentialType::PhoneNumber => 10, + CredentialType::Email => 255, + } + } + pub fn get_regex_pattern(&self) -> &str { + match self { + CredentialType::PhoneNumber => "REGEX PATTERN FOR PHONE NUMBER", + CredentialType::Email => "REGEX PATTERN FOR EMAIL", + } + } +} +impl Display for CredentialType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + CredentialType::Email => f.write_str("Email"), + CredentialType::PhoneNumber => f.write_str("PhoneNumber") + } + } +} \ No newline at end of file diff --git a/src/domain/user/mod.rs b/src/domain/user/mod.rs index 05e678b..baa2b4c 100644 --- a/src/domain/user/mod.rs +++ b/src/domain/user/mod.rs @@ -1,2 +1,3 @@ pub mod token; -pub mod user; \ No newline at end of file +pub mod user; +pub mod credential_type; \ No newline at end of file diff --git a/src/domain/user/user.rs b/src/domain/user/user.rs index 0417d4d..6351e80 100644 --- a/src/domain/user/user.rs +++ b/src/domain/user/user.rs @@ -11,7 +11,8 @@ pub struct User{ #[serde(skip_serializing_if = "Option::is_none")] pub last_updated: Option, pub app: String, - pub email: String, + pub credential: String, + pub credential_type: String, pub name: String, #[serde(skip_serializing)] pub password: String, @@ -24,7 +25,8 @@ impl User { time_created: None, // This will be automatically generated from the database last_updated: None, // This will be automatically generated from the database app: "".to_string(), - email: "".to_string(), + credential: "".to_string(), + credential_type: "".to_string(), name:"".to_string(), password:"".to_string(), salt: "".to_string() } @@ -34,7 +36,8 @@ impl User { time_created: None, // This will be automatically generated from the database last_updated: None, // This will be automatically generated from the database app: incoming_user.app.to_string(), - email: incoming_user.email.to_string(), + credential: incoming_user.credential.to_string(), + credential_type: incoming_user.credential_type.to_string(), name: incoming_user.name.to_string(), password: incoming_user.password.to_string(), salt: "".to_string() } diff --git a/src/dtos/user/user_dtos.rs b/src/dtos/user/user_dtos.rs index dbf2475..3cd4e60 100644 --- a/src/dtos/user/user_dtos.rs +++ b/src/dtos/user/user_dtos.rs @@ -1,10 +1,13 @@ use serde::{Serialize, Deserialize}; +use crate::domain::user::credential_type::CredentialType; + #[derive(Serialize, Deserialize, Debug)] pub struct UserForCreationDto{ #[serde(default = "get_default_app")] pub app: String, - pub email: String, + pub credential: String, + pub credential_type: CredentialType, pub password: String, pub name: String } @@ -12,14 +15,15 @@ pub struct UserForCreationDto{ pub struct UserForLoginDto{ #[serde(default = "get_default_app")] pub app: String, - pub email: String, + pub credential: String, + pub credential_type: CredentialType, pub password: String } #[derive(Serialize, Deserialize, Debug)] pub struct UserForAuthenticationDto{ #[serde(default = "get_default_app")] pub app: String, - pub email: String, + pub id: String, pub token: String }