Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reset_password API to always return success #5284

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions crates/api/src/local_user/reset_password.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,31 @@ use lemmy_api_common::{
SuccessResponse,
};
use lemmy_db_views::structs::{LocalUserView, SiteView};
use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
use lemmy_utils::error::LemmyResult;
use tracing::error;

#[tracing::instrument(skip(context))]
pub async fn reset_password(
data: Json<PasswordReset>,
context: Data<LemmyContext>,
) -> LemmyResult<Json<SuccessResponse>> {
// Fetch that email
let email = data.email.to_lowercase();
let local_user_view = LocalUserView::find_by_email(&mut context.pool(), &email)
.await
.with_lemmy_type(LemmyErrorType::IncorrectLogin)?;
// For security, errors are not returned.
// https://github.com/LemmyNet/lemmy/issues/5277
let _ = try_reset_password(&email, &context).await;
dessalines marked this conversation as resolved.
Show resolved Hide resolved
dullbananas marked this conversation as resolved.
Show resolved Hide resolved
Ok(Json(SuccessResponse::default()))
}

async fn try_reset_password(email: &str, context: &LemmyContext) -> LemmyResult<()> {
Copy link
Member

@dessalines dessalines Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be moved to utils like all the other helper functions. And you should add a function comment that it always returns Ok, and probably link to the issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a little better to keep the reset_password and try_reset_password functions together

let local_user_view = LocalUserView::find_by_email(&mut context.pool(), email).await?;
let site_view = SiteView::read_local(&mut context.pool()).await?;

check_email_verified(&local_user_view, &site_view)?;
if let Err(e) =
send_password_reset_email(&local_user_view, &mut context.pool(), context.settings()).await
{
error!("Failed to send password reset email: {}", e);
}

// Email the pure token to the user.
send_password_reset_email(&local_user_view, &mut context.pool(), context.settings()).await?;
Ok(Json(SuccessResponse::default()))
Ok(())
}