From 5f5534f597f64ee2b274e7036a5a29c601aaa5ac Mon Sep 17 00:00:00 2001 From: antifallobst Date: Thu, 17 Aug 2023 02:17:11 +0200 Subject: [PATCH] feat(api): fully implemented the delete endpoint --- src/api/account/handlers.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/api/account/handlers.rs b/src/api/account/handlers.rs index 018b61b..1869d9a 100644 --- a/src/api/account/handlers.rs +++ b/src/api/account/handlers.rs @@ -33,7 +33,9 @@ pub async fn register( 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) { return Ok(data::RegisterResponse::MalformedEmail); @@ -133,7 +135,18 @@ pub async fn delete(pool: &MySqlPool, token: String) -> Result 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) }