2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 person::{PasswordReset, PasswordResetResponse},
5 utils::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 = LocalUserView::find_by_email(context.pool(), &email)
27 .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_that_username_or_email"))?;
29 // Email the pure token to the user.
30 send_password_reset_email(&local_user_view, context.pool(), context.settings()).await?;
31 Ok(PasswordResetResponse {})