app: Fix password reset

This commit is contained in:
Valentin Tolmer 2022-04-15 19:43:12 +02:00 committed by nitnelave
parent b6dd1ed512
commit 0ccedc6717
2 changed files with 10 additions and 7 deletions

View File

@ -6,7 +6,10 @@ use crate::{
}, },
}; };
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use lldap_auth::*; use lldap_auth::{
opaque::client::registration as opaque_registration,
password_reset::ServerPasswordResetResponse, registration,
};
use validator_derive::Validate; use validator_derive::Validate;
use yew::prelude::*; use yew::prelude::*;
use yew_form::Form; use yew_form::Form;
@ -29,7 +32,7 @@ pub struct ResetPasswordStep2Form {
common: CommonComponentParts<Self>, common: CommonComponentParts<Self>,
form: Form<FormModel>, form: Form<FormModel>,
username: Option<String>, username: Option<String>,
opaque_data: Option<opaque::client::registration::ClientRegistration>, opaque_data: Option<opaque_registration::ClientRegistration>,
route_dispatcher: RouteAgentDispatcher, route_dispatcher: RouteAgentDispatcher,
} }
@ -39,7 +42,7 @@ pub struct Props {
} }
pub enum Msg { pub enum Msg {
ValidateTokenResponse(Result<String>), ValidateTokenResponse(Result<ServerPasswordResetResponse>),
FormUpdate, FormUpdate,
Submit, Submit,
RegistrationStartResponse(Result<Box<registration::ServerRegistrationStartResponse>>), RegistrationStartResponse(Result<Box<registration::ServerRegistrationStartResponse>>),
@ -50,7 +53,7 @@ impl CommonComponent<ResetPasswordStep2Form> for ResetPasswordStep2Form {
fn handle_msg(&mut self, msg: <Self as Component>::Message) -> Result<bool> { fn handle_msg(&mut self, msg: <Self as Component>::Message) -> Result<bool> {
match msg { match msg {
Msg::ValidateTokenResponse(response) => { Msg::ValidateTokenResponse(response) => {
self.username = Some(response?); self.username = Some(response?.user_id);
self.common.cancel_task(); self.common.cancel_task();
Ok(true) Ok(true)
} }
@ -62,7 +65,7 @@ impl CommonComponent<ResetPasswordStep2Form> for ResetPasswordStep2Form {
let mut rng = rand::rngs::OsRng; let mut rng = rand::rngs::OsRng;
let new_password = self.form.model().password; let new_password = self.form.model().password;
let registration_start_request = let registration_start_request =
opaque::client::registration::start_registration(&new_password, &mut rng) opaque_registration::start_registration(&new_password, &mut rng)
.context("Could not initiate password change")?; .context("Could not initiate password change")?;
let req = registration::ClientRegistrationStartRequest { let req = registration::ClientRegistrationStartRequest {
username: self.username.clone().unwrap(), username: self.username.clone().unwrap(),
@ -80,7 +83,7 @@ impl CommonComponent<ResetPasswordStep2Form> for ResetPasswordStep2Form {
let res = res.context("Could not initiate password change")?; let res = res.context("Could not initiate password change")?;
let registration = self.opaque_data.take().expect("Missing registration data"); let registration = self.opaque_data.take().expect("Missing registration data");
let mut rng = rand::rngs::OsRng; let mut rng = rand::rngs::OsRng;
let registration_finish = opaque::client::registration::finish_registration( let registration_finish = opaque_registration::finish_registration(
registration, registration,
res.registration_response, res.registration_response,
&mut rng, &mut rng,

View File

@ -251,7 +251,7 @@ impl HostService {
pub fn reset_password_step2( pub fn reset_password_step2(
token: &str, token: &str,
callback: Callback<Result<String>>, callback: Callback<Result<lldap_auth::password_reset::ServerPasswordResetResponse>>,
) -> Result<FetchTask> { ) -> Result<FetchTask> {
call_server_json_with_error_message( call_server_json_with_error_message(
&format!("/auth/reset/step2/{}", token), &format!("/auth/reset/step2/{}", token),