feat(api): fully implemented the delete endpoint
This commit is contained in:
parent
3049b68ef4
commit
5f5534f597
|
@ -33,7 +33,9 @@ pub async fn register(
|
||||||
return Ok(data::RegisterResponse::Blocked);
|
return Ok(data::RegisterResponse::Blocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
let email_regex = regex::Regex::new(r"^([a-z0-9_+]([a-z0-9_+.]*[a-z0-9_+])?)@([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6})")?;
|
let email_regex = regex::Regex::new(
|
||||||
|
r"^([a-z0-9_+]([a-z0-9_+.]*[a-z0-9_+])?)@([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6})",
|
||||||
|
)?;
|
||||||
|
|
||||||
if !email_regex.is_match(&request.email) {
|
if !email_regex.is_match(&request.email) {
|
||||||
return Ok(data::RegisterResponse::MalformedEmail);
|
return Ok(data::RegisterResponse::MalformedEmail);
|
||||||
|
@ -133,7 +135,18 @@ pub async fn delete(pool: &MySqlPool, token: String) -> Result<data::DeleteRespo
|
||||||
return Ok(data::DeleteResponse::Blocked);
|
return Ok(data::DeleteResponse::Blocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let token = match AuthToken::check(pool, token).await? {
|
||||||
|
Some(t) => t,
|
||||||
|
None => return Ok(data::DeleteResponse::Unauthorized),
|
||||||
|
};
|
||||||
|
|
||||||
|
sqlx::query!(r#"DELETE FROM AuthTokens WHERE account = ?;"#, token.account)
|
||||||
|
.execute(pool)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
sqlx::query!(r#"DELETE FROM Accounts WHERE id = ?;"#, token.account)
|
||||||
|
.execute(pool)
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(data::DeleteResponse::Success)
|
Ok(data::DeleteResponse::Success)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue