Check for duplicate email

This commit is contained in:
2023-05-25 09:42:43 +02:00
parent bce6a85536
commit 4ba4d10fce
2 changed files with 25 additions and 2 deletions

View File

@ -29,9 +29,20 @@ pub async fn create_account(
return Ok(HttpResponse::BadRequest().json("Size constraints were not respected!"));
}
// TODO : check the mail address
// Check if email is already attached to an account
match users_service::exists_email(&req.email).await {
Ok(false) => {}
Ok(true) => {
return Ok(HttpResponse::Conflict()
.json("An account with the same email address already exists!"));
}
Err(e) => {
log::error!("Failed to check email existence! {}", e);
return Err(ErrorInternalServerError(e));
}
}
// Create the account
// Create the account
let user_id = users_service::create_account(&req.name, &req.email)
.await
.map_err(|e| {