Changed dtos and domain object to accept credential + CredentialTypes instead of eamil

This commit is contained in:
Franklin 2022-08-26 13:36:25 -04:00
parent c4da3ee570
commit 684024b555
4 changed files with 45 additions and 7 deletions

View File

@ -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")
}
}
}

View File

@ -1,2 +1,3 @@
pub mod token; pub mod token;
pub mod user; pub mod user;
pub mod credential_type;

View File

@ -11,7 +11,8 @@ pub struct User{
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub last_updated: Option<NaiveDateTime>, pub last_updated: Option<NaiveDateTime>,
pub app: String, pub app: String,
pub email: String, pub credential: String,
pub credential_type: String,
pub name: String, pub name: String,
#[serde(skip_serializing)] #[serde(skip_serializing)]
pub password: String, pub password: String,
@ -24,7 +25,8 @@ impl User {
time_created: None, // This will be automatically generated from the database time_created: None, // This will be automatically generated from the database
last_updated: None, // This will be automatically generated from the database last_updated: None, // This will be automatically generated from the database
app: "".to_string(), app: "".to_string(),
email: "".to_string(), credential: "".to_string(),
credential_type: "".to_string(),
name:"".to_string(), name:"".to_string(),
password:"".to_string(), password:"".to_string(),
salt: "".to_string() } salt: "".to_string() }
@ -34,7 +36,8 @@ impl User {
time_created: None, // This will be automatically generated from the database time_created: None, // This will be automatically generated from the database
last_updated: 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(), 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(), name: incoming_user.name.to_string(),
password: incoming_user.password.to_string(), password: incoming_user.password.to_string(),
salt: "".to_string() } salt: "".to_string() }

View File

@ -1,10 +1,13 @@
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use crate::domain::user::credential_type::CredentialType;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct UserForCreationDto{ pub struct UserForCreationDto{
#[serde(default = "get_default_app")] #[serde(default = "get_default_app")]
pub app: String, pub app: String,
pub email: String, pub credential: String,
pub credential_type: CredentialType,
pub password: String, pub password: String,
pub name: String pub name: String
} }
@ -12,14 +15,15 @@ pub struct UserForCreationDto{
pub struct UserForLoginDto{ pub struct UserForLoginDto{
#[serde(default = "get_default_app")] #[serde(default = "get_default_app")]
pub app: String, pub app: String,
pub email: String, pub credential: String,
pub credential_type: CredentialType,
pub password: String pub password: String
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct UserForAuthenticationDto{ pub struct UserForAuthenticationDto{
#[serde(default = "get_default_app")] #[serde(default = "get_default_app")]
pub app: String, pub app: String,
pub email: String, pub id: String,
pub token: String pub token: String
} }