mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-01-10 00:55:25 +00:00
ad90cd77f9
* add private visibility * filter private communities in post_view.rs * also filter in comment_view * community follower state * remove unused method * sql fmt * add CommunityFollower.approved_by * implement api endpoints * api changes * only admins can create private community for now * add local api tests * fix api tests * follow remote private community * use authorized fetch for content in private community * federate community visibility * dont mark content in private community as public * expose ApprovalRequired in api * also check content fetchable for outbox/featured * address private community content to followers * implement reject activity * fix tests * add files * remove local api tests * dont use delay * is_new_instance * single query for is_new_instance * return subscribed type for pending follow * working * need to catch errors in waitUntil * clippy * fix query * lint for unused async * diesel.toml comment * add comment * avoid db reads * rename approved_by to approver_id * add helper * form init * list pending follows should return items for all communities * clippy * ci * fix down migration * fix api tests * references * rename * run git diff * ci * fix schema check * fix joins * ci * ci * skip_serializing_none * fix test --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
51 lines
1.5 KiB
Rust
51 lines
1.5 KiB
Rust
use activitypub_federation::config::Data;
|
|
use actix_web::web::Json;
|
|
use bcrypt::verify;
|
|
use lemmy_api_common::{
|
|
context::LemmyContext,
|
|
person::DeleteAccount,
|
|
send_activity::{ActivityChannel, SendActivityData},
|
|
utils::purge_user_account,
|
|
SuccessResponse,
|
|
};
|
|
use lemmy_db_schema::source::{
|
|
login_token::LoginToken,
|
|
oauth_account::OAuthAccount,
|
|
person::Person,
|
|
};
|
|
use lemmy_db_views::structs::LocalUserView;
|
|
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
|
|
|
#[tracing::instrument(skip(context))]
|
|
pub async fn delete_account(
|
|
data: Json<DeleteAccount>,
|
|
context: Data<LemmyContext>,
|
|
local_user_view: LocalUserView,
|
|
) -> LemmyResult<Json<SuccessResponse>> {
|
|
// Verify the password
|
|
let valid: bool = local_user_view
|
|
.local_user
|
|
.password_encrypted
|
|
.as_ref()
|
|
.and_then(|password_encrypted| verify(&data.password, password_encrypted).ok())
|
|
.unwrap_or(false);
|
|
if !valid {
|
|
Err(LemmyErrorType::IncorrectLogin)?
|
|
}
|
|
|
|
if data.delete_content {
|
|
purge_user_account(local_user_view.person.id, &context).await?;
|
|
} else {
|
|
OAuthAccount::delete_user_accounts(&mut context.pool(), local_user_view.local_user.id).await?;
|
|
Person::delete_account(&mut context.pool(), local_user_view.person.id).await?;
|
|
}
|
|
|
|
LoginToken::invalidate_all(&mut context.pool(), local_user_view.local_user.id).await?;
|
|
|
|
ActivityChannel::submit_activity(
|
|
SendActivityData::DeleteUser(local_user_view.person, data.delete_content),
|
|
&context,
|
|
)?;
|
|
|
|
Ok(Json(SuccessResponse::default()))
|
|
}
|