Fix docker #3
@@ -82,9 +82,11 @@ pub async fn register_user(
|
||||
None => String::new()
|
||||
};
|
||||
|
||||
println!("Checking if user exists");
|
||||
match repo::user::exists(&pool, &user.username).await {
|
||||
Ok(res) => {
|
||||
if res {
|
||||
println!("Already exists");
|
||||
(
|
||||
StatusCode::BAD_REQUEST,
|
||||
Json(response::Response {
|
||||
@@ -93,16 +95,20 @@ pub async fn register_user(
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
println!("Good to create");
|
||||
println!("Generate salt string");
|
||||
let salt_string = hashing::generate_salt().unwrap();
|
||||
let mut salt = textsender_models::user::Salt::default();
|
||||
let generated_salt = salt_string;
|
||||
salt.salt = generated_salt.to_string();
|
||||
println!("Creating salt");
|
||||
salt.id = repo::salt::insert(&pool, &salt).await.unwrap();
|
||||
user.salt_id = salt.id;
|
||||
let hashed_password =
|
||||
hashing::hash_password(&user.password, &generated_salt).unwrap();
|
||||
user.password = hashed_password;
|
||||
|
||||
println!("Creating user");
|
||||
match repo::user::insert(&pool, &user).await {
|
||||
Ok((id, date_created)) => {
|
||||
user.id = id;
|
||||
|
||||
+2
-2
@@ -134,7 +134,7 @@ pub mod user {
|
||||
let result = InsertedData {
|
||||
id: row.try_get("id").map_err(|_e| sqlx::Error::RowNotFound)?,
|
||||
date_created: row
|
||||
.try_get("date_created")
|
||||
.try_get("created")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)?,
|
||||
};
|
||||
|
||||
@@ -160,7 +160,7 @@ pub mod salt {
|
||||
) -> Result<textsender_models::user::Salt, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
SELECT * FROM "salt" WHERE id = $1
|
||||
SELECT id, salt FROM "salt" WHERE id = $1
|
||||
"#,
|
||||
)
|
||||
.bind(id)
|
||||
|
||||
Reference in New Issue
Block a user