diff options
Diffstat (limited to 'server/src/models')
-rw-r--r-- | server/src/models/user.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/server/src/models/user.rs b/server/src/models/user.rs index 9545fac..76cb4b5 100644 --- a/server/src/models/user.rs +++ b/server/src/models/user.rs @@ -2,11 +2,14 @@ use crate::db::get_client; use crate::errors::AppError; use serde::{Deserialize, Serialize}; +use validator::Validate; -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Validate)] pub struct User { id: i32, + #[validate(length(min = 1, message = "Can not be empty"))] email: String, + #[validate(length(min = 8, message = "Must be min 8 chars length"))] password: String, is_staff: Option<bool>, } @@ -26,11 +29,10 @@ pub struct UserCreate { impl User { pub fn new(email: String, password: String) -> Self { - let crypted_password = sha256::digest(password); Self { id: 0, email, - password: crypted_password, + password, is_staff: Some(false), } } @@ -45,7 +47,7 @@ impl User { RETURNING id, email, is_staff "#, user.email, - user.password + sha256::digest(user.password) ) .fetch_one(pool) .await?; |