Custom debug for struct with sensitive data

This commit is contained in:
Thani Sheun 2023-05-04 19:47:58 +02:00
parent 1fab7958b3
commit e57b007dd0
3 changed files with 25 additions and 6 deletions

View file

@ -1,15 +1,15 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize)]
pub struct TokenReadDto {
pub token: String,
pub iat: i64,
pub exp: i64,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize)]
pub struct TokenClaimsDto {
pub sub: i32,
pub email: String,
pub iat: i64,
pub exp: i64,
}
}

View file

@ -3,7 +3,7 @@ use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use validator::Validate;
#[derive(Clone, Debug, Serialize, Deserialize, Validate)]
#[derive(Clone, Serialize, Deserialize, Validate)]
pub struct UserLoginDto {
#[validate(email(message = "Email is not valid"))]
pub email: String,
@ -15,7 +15,7 @@ pub struct UserLoginDto {
pub password: String,
}
#[derive(Clone, Debug, Serialize, Deserialize, Validate)]
#[derive(Clone, Serialize, Deserialize, Validate)]
pub struct UserRegisterDto {
#[validate(email(message = "Email is not valid"))]
pub email: String,
@ -61,3 +61,22 @@ impl UserReadDto {
}
}
}
impl std::fmt::Debug for UserLoginDto {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("User")
.field("email", &self.email)
.finish()
}
}
impl std::fmt::Debug for UserRegisterDto {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("User")
.field("first_name", &self.first_name)
.field("last_name", &self.last_name)
.field("user_name", &self.user_name)
.field("email", &self.email)
.finish()
}
}

View file

@ -1,7 +1,7 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize, sqlx::FromRow)]
#[derive(Clone, Deserialize, Serialize, sqlx::FromRow)]
pub struct User {
pub id: i32,
pub first_name: Option<String>,