b26aaac523
* Added OAUTH2 OIDC support * Fixes and improvements based on review feedback * use derive_new::new instead of TypedBuilder * merge migrations into a single file * fixes based on review feedback * remove unnecessary hostname_ui config * improvement based on review feedback * improvements based on review feedback * delete user oauth accounts at account deletion * fixes and improvements based on review feedback * removed auto_approve_application * support registration application with sso * improvements based on review feedback * making the TokenResponse an internal struct as it should be * remove duplicate struct * prevent oauth linking to unverified accounts * switched to manually entered username and removed the oauth name claim * fix cargo fmt * fix compile error * improvements based on review feedback * fixes and improvements based on review feedback --------- Co-authored-by: privacyguard <privacyguard@users.noreply.github.com>
52 lines
1.5 KiB
Rust
52 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,
|
|
)
|
|
.await?;
|
|
|
|
Ok(Json(SuccessResponse::default()))
|
|
}
|