Feat: Allow Deleting Account via JSON API
This commit is contained in:
parent
5b3a544bbb
commit
ce0c5032ba
3 changed files with 26 additions and 1 deletions
23
src/json_api/users/delete.rs
Normal file
23
src/json_api/users/delete.rs
Normal 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(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
pub mod profile;
|
pub mod profile;
|
||||||
pub mod mii;
|
pub mod mii;
|
||||||
|
pub mod delete;
|
||||||
|
|
@ -151,6 +151,7 @@ async fn launch() -> _ {
|
||||||
json_api::oauth::generate_token::generate_token,
|
json_api::oauth::generate_token::generate_token,
|
||||||
json_api::users::profile::get_own_profile,
|
json_api::users::profile::get_own_profile,
|
||||||
json_api::users::mii::get_mii_data_by_pid,
|
json_api::users::mii::get_mii_data_by_pid,
|
||||||
|
json_api::users::delete::delete_account,
|
||||||
papi::login::login,
|
papi::login::login,
|
||||||
papi::user::get_user,
|
papi::user::get_user,
|
||||||
nnid::people::thing,
|
nnid::people::thing,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue