summaryrefslogtreecommitdiff
path: root/server/src/models
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2022-08-22 23:07:51 +0200
committerSanto Cariotti <santo@dcariotti.me>2022-08-22 23:07:51 +0200
commit0dace9fb82953cc91e6d603c4c9970631ac036ad (patch)
tree5ecd0328296871a38d61bef4ab5a6f903877ef29 /server/src/models
parentea2ac88a83b6de15beb8b9727f88d498a56fb5b3 (diff)
Validate into model
Diffstat (limited to 'server/src/models')
-rw-r--r--server/src/models/user.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/server/src/models/user.rs b/server/src/models/user.rs
index 76cb4b5..964f04a 100644
--- a/server/src/models/user.rs
+++ b/server/src/models/user.rs
@@ -39,6 +39,12 @@ impl User {
pub async fn create(user: User) -> Result<UserList, AppError> {
let pool = unsafe { get_client() };
+
+ user.validate()
+ .map_err(|error| AppError::BadRequest(error.to_string()))?;
+
+ let crypted_password = sha256::digest(user.password);
+
let rec = sqlx::query_as!(
UserList,
r#"
@@ -47,7 +53,7 @@ impl User {
RETURNING id, email, is_staff
"#,
user.email,
- sha256::digest(user.password)
+ crypted_password
)
.fetch_one(pool)
.await?;