1 use crate::PerformCrud;
2 use actix_web::web::Data;
4 use lemmy_api_common::{blocking, get_local_user_view_from_jwt, person::*};
5 use lemmy_db_schema::source::{comment::Comment, person::Person, post::Post};
6 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
7 use lemmy_websocket::LemmyContext;
9 #[async_trait::async_trait(?Send)]
10 impl PerformCrud for DeleteAccount {
11 type Response = LoginResponse;
15 context: &Data<LemmyContext>,
16 _websocket_id: Option<ConnectionId>,
17 ) -> Result<LoginResponse, LemmyError> {
18 let data: &DeleteAccount = self;
20 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
22 // Verify the password
23 let valid: bool = verify(
25 &local_user_view.local_user.password_encrypted,
29 return Err(ApiError::err_plain("password_incorrect").into());
33 let person_id = local_user_view.person.id;
34 let permadelete = move |conn: &'_ _| Comment::permadelete_for_creator(conn, person_id);
35 blocking(context.pool(), permadelete)
37 .map_err(|e| ApiError::err("couldnt_update_comment", e))?;
40 let permadelete = move |conn: &'_ _| Post::permadelete_for_creator(conn, person_id);
41 blocking(context.pool(), permadelete)
43 .map_err(|e| ApiError::err("couldnt_update_post", e))?;
45 blocking(context.pool(), move |conn| {
46 Person::delete_account(conn, person_id)
51 jwt: data.auth.to_owned(),