Skip to content

Commit

Permalink
Check user accepted before sending jwt in password reset (fixes #2591)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Nov 30, 2022
1 parent 41d4852 commit 56e5390
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions crates/api/src/local_user/change_password_after_reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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, ConnectionId};
use lemmy_websocket::LemmyContext;

Expand Down Expand Up @@ -42,16 +43,24 @@ impl Perform for PasswordChangeAfterReset {
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_user"))?;

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

Ok(LoginResponse {
jwt: Some(
Claims::jwt(
updated_local_user.id.0,
&context.secret().jwt_secret,
&context.settings().hostname,
)?
.into(),
),
jwt,
verify_email_sent: false,
registration_created: false,
})
Expand Down

0 comments on commit 56e5390

Please sign in to comment.