Feat: Allow Deleting Account via JSON API

This commit is contained in:
BloxerHD 2025-08-14 18:46:19 +01:00
commit ce0c5032ba
3 changed files with 26 additions and 1 deletions

View file

@ -0,0 +1,23 @@
use crate::Pool;
use crate::account::account::{Auth, User};
use rocket::http::Status;
use rocket::{State, get};
#[get("/api/v2/users/@me/delete")]
pub async fn delete_account(pool: &State<Pool>, auth: Auth<true>) -> Result<(), Status> {
let pool = pool.inner();
let user: User = auth.into();
let result = sqlx::query!(
"DELETE FROM users WHERE username = $1",
user.username
).execute(pool)
.await
.map_err(|_| Status::InternalServerError)?;
if result.rows_affected() == 0 { // Account doesn't exist
Err(Status::NotFound)
} else { // Account existed and was deleted
Ok(())
}
}

View file

@ -1,2 +1,3 @@
pub mod profile;
pub mod mii;
pub mod mii;
pub mod delete;

View file

@ -151,6 +151,7 @@ async fn launch() -> _ {
json_api::oauth::generate_token::generate_token,
json_api::users::profile::get_own_profile,
json_api::users::mii::get_mii_data_by_pid,
json_api::users::delete::delete_account,
papi::login::login,
papi::user::get_user,
nnid::people::thing,