2 use actix_web::web::Data;
4 use lemmy_api_common::{
6 person::{ChangePassword, LoginResponse},
7 utils::{local_user_view_from_jwt, password_length_check},
9 use lemmy_db_schema::source::local_user::LocalUser;
10 use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId};
12 #[async_trait::async_trait(?Send)]
13 impl Perform for ChangePassword {
14 type Response = LoginResponse;
16 #[tracing::instrument(skip(self, context, _websocket_id))]
19 context: &Data<LemmyContext>,
20 _websocket_id: Option<ConnectionId>,
21 ) -> Result<LoginResponse, LemmyError> {
22 let data: &ChangePassword = self;
23 let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), context).await?;
25 password_length_check(&data.new_password)?;
27 // Make sure passwords match
28 if data.new_password != data.new_password_verify {
29 return Err(LemmyError::from_message("passwords_dont_match"));
32 // Check the old password
33 let valid: bool = verify(
35 &local_user_view.local_user.password_encrypted,
39 return Err(LemmyError::from_message("password_incorrect"));
42 let local_user_id = local_user_view.local_user.id;
43 let new_password = data.new_password.clone();
44 let updated_local_user =
45 LocalUser::update_password(context.pool(), local_user_id, &new_password).await?;
51 updated_local_user.id.0,
52 &context.secret().jwt_secret,
53 &context.settings().hostname,
57 verify_email_sent: false,
58 registration_created: false,