Nutomic
f858d8cbce
* Remove explicit auth params (ref #3725) Only take auth via header or cookie. This requires a new version of lemmy-js-client for api tests to pass. * rework api_crud * remove remaining auth params, move logic to session middleware * fmt, fix test * update js client * remove auth param from api tests * Pass auth as header * add ! * url vars, setHeader * cleanup * fmt * update * Updating for new lemmy-js-client. --------- Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
43 lines
1.2 KiB
Rust
43 lines
1.2 KiB
Rust
use activitypub_federation::config::Data;
|
|
use actix_web::web::Json;
|
|
use bcrypt::verify;
|
|
use lemmy_api_common::{
|
|
context::LemmyContext,
|
|
person::{DeleteAccount, DeleteAccountResponse},
|
|
send_activity::{ActivityChannel, SendActivityData},
|
|
utils::purge_user_account,
|
|
};
|
|
use lemmy_db_schema::source::person::Person;
|
|
use lemmy_db_views::structs::LocalUserView;
|
|
use lemmy_utils::error::{LemmyError, LemmyErrorType};
|
|
|
|
#[tracing::instrument(skip(context))]
|
|
pub async fn delete_account(
|
|
data: Json<DeleteAccount>,
|
|
context: Data<LemmyContext>,
|
|
local_user_view: LocalUserView,
|
|
) -> Result<Json<DeleteAccountResponse>, LemmyError> {
|
|
// Verify the password
|
|
let valid: bool = verify(
|
|
&data.password,
|
|
&local_user_view.local_user.password_encrypted,
|
|
)
|
|
.unwrap_or(false);
|
|
if !valid {
|
|
Err(LemmyErrorType::IncorrectLogin)?
|
|
}
|
|
|
|
if data.delete_content {
|
|
purge_user_account(local_user_view.person.id, &context).await?;
|
|
} else {
|
|
Person::delete_account(&mut context.pool(), local_user_view.person.id).await?;
|
|
}
|
|
|
|
ActivityChannel::submit_activity(
|
|
SendActivityData::DeleteUser(local_user_view.person, data.delete_content),
|
|
&context,
|
|
)
|
|
.await?;
|
|
|
|
Ok(Json(DeleteAccountResponse {}))
|
|
}
|