2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 person::{LoginResponse, PasswordChangeAfterReset},
6 utils::password_length_check,
8 use lemmy_db_schema::source::{
10 password_reset_request::PasswordResetRequest,
12 use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
14 #[async_trait::async_trait(?Send)]
15 impl Perform for PasswordChangeAfterReset {
16 type Response = LoginResponse;
18 #[tracing::instrument(skip(self, context))]
19 async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
20 let data: &PasswordChangeAfterReset = self;
22 // Fetch the user_id from the token
23 let token = data.token.clone();
24 let local_user_id = PasswordResetRequest::read_from_token(&mut context.pool(), &token)
26 .map(|p| p.local_user_id)?;
28 password_length_check(&data.password)?;
30 // Make sure passwords match
31 if data.password != data.password_verify {
32 return Err(LemmyErrorType::PasswordsDoNotMatch)?;
35 // Update the user with the new password
36 let password = data.password.clone();
37 LocalUser::update_password(&mut context.pool(), local_user_id, &password)
39 .with_lemmy_type(LemmyErrorType::CouldntUpdateUser)?;
43 verify_email_sent: false,
44 registration_created: false,