Skip to content

Commit

Permalink
Dont authenticate user after successful password reset #3714 (#3715)
Browse files Browse the repository at this point in the history
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
  • Loading branch information
2 people authored and Nutomic committed Jul 26, 2023
1 parent 51664bc commit d9ae9bf
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions crates/api/src/local_user/change_password_after_reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ use lemmy_api_common::{
person::{LoginResponse, PasswordChangeAfterReset},
utils::password_length_check,
};
use lemmy_db_schema::{
source::{local_user::LocalUser, password_reset_request::PasswordResetRequest},
RegistrationMode,
use lemmy_db_schema::source::{
local_user::LocalUser,
password_reset_request::PasswordResetRequest,
};
use lemmy_db_views::structs::SiteView;
use lemmy_utils::{claims::Claims, error::LemmyError};
use lemmy_utils::error::LemmyError;

#[async_trait::async_trait(?Send)]
impl Perform for PasswordChangeAfterReset {
Expand All @@ -35,29 +34,10 @@ impl Perform for PasswordChangeAfterReset {

// Update the user with the new password
let password = data.password.clone();
let updated_local_user = LocalUser::update_password(context.pool(), local_user_id, &password)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_user"))?;

// Return the jwt if login is allowed
let site_view = SiteView::read_local(context.pool()).await?;
let jwt = if site_view.local_site.registration_mode == RegistrationMode::RequireApplication
&& !updated_local_user.accepted_application
{
None
} else {
Some(
Claims::jwt(
updated_local_user.id.0,
&context.secret().jwt_secret,
&context.settings().hostname,
)?
.into(),
)
};
LocalUser::update_password(context.pool(), local_user_id, &password).await?;

Ok(LoginResponse {
jwt,
jwt: None,
verify_email_sent: false,
registration_created: false,
})
Expand Down

0 comments on commit d9ae9bf

Please sign in to comment.