2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 person::{PasswordReset, PasswordResetResponse},
5 utils::{blocking, send_password_reset_email},
7 use lemmy_db_views::structs::LocalUserView;
8 use lemmy_utils::{error::LemmyError, ConnectionId};
9 use lemmy_websocket::LemmyContext;
11 #[async_trait::async_trait(?Send)]
12 impl Perform for PasswordReset {
13 type Response = PasswordResetResponse;
15 #[tracing::instrument(skip(self, context, _websocket_id))]
18 context: &Data<LemmyContext>,
19 _websocket_id: Option<ConnectionId>,
20 ) -> Result<PasswordResetResponse, LemmyError> {
21 let data: &PasswordReset = self;
24 let email = data.email.to_lowercase();
25 let local_user_view = blocking(context.pool(), move |conn| {
26 LocalUserView::find_by_email(conn, &email)
29 .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_that_username_or_email"))?;
31 // Email the pure token to the user.
32 send_password_reset_email(&local_user_view, context.pool(), context.settings()).await?;
33 Ok(PasswordResetResponse {})