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::{ConnectionId, LemmyError};
7 use lemmy_websocket::LemmyContext;
9 #[async_trait::async_trait(?Send)]
10 impl PerformCrud for DeleteAccount {
11 type Response = DeleteAccountResponse;
13 #[tracing::instrument(skip(self, context, _websocket_id))]
16 context: &Data<LemmyContext>,
17 _websocket_id: Option<ConnectionId>,
18 ) -> Result<Self::Response, LemmyError> {
21 get_local_user_view_from_jwt(data.auth.as_ref(), context.pool(), context.secret()).await?;
23 // Verify the password
24 let valid: bool = verify(
26 &local_user_view.local_user.password_encrypted,
30 return Err(LemmyError::from_message("password_incorrect"));
34 let person_id = local_user_view.person.id;
35 let permadelete = move |conn: &'_ _| Comment::permadelete_for_creator(conn, person_id);
36 blocking(context.pool(), permadelete)
38 .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
41 let permadelete = move |conn: &'_ _| Post::permadelete_for_creator(conn, person_id);
42 blocking(context.pool(), permadelete)
44 .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_post"))?;
46 blocking(context.pool(), move |conn| {
47 Person::delete_account(conn, person_id)
51 Ok(DeleteAccountResponse {})