summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/models/user.rs8
-rw-r--r--server/src/routes/user.rs3
2 files changed, 7 insertions, 4 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?;
diff --git a/server/src/routes/user.rs b/server/src/routes/user.rs
index c15b5aa..15a67be 100644
--- a/server/src/routes/user.rs
+++ b/server/src/routes/user.rs
@@ -1,7 +1,6 @@
use crate::errors::AppError;
use crate::models::user::{User, UserCreate, UserList};
use axum::{routing::get, Json, Router};
-use validator::Validate;
pub fn create_route() -> Router {
Router::new().route("/", get(list_users).post(create_user))
@@ -15,8 +14,6 @@ async fn list_users() -> Result<Json<Vec<UserList>>, AppError> {
async fn create_user(Json(payload): Json<UserCreate>) -> Result<Json<UserList>, AppError> {
let user = User::new(payload.email, payload.password);
- user.validate()
- .map_err(|error| AppError::BadRequest(error.to_string()))?;
let user_new = User::create(user).await?;
Ok(Json(user_new))