You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-07 17:03:01 +03:00
Implement the password change form
This commit is contained in:
@@ -1056,6 +1056,76 @@ impl TemplateContext for RecoveryProgressContext {
|
||||
}
|
||||
}
|
||||
|
||||
/// Fields of the account recovery finish form
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum RecoveryFinishFormField {
|
||||
/// The new password
|
||||
NewPassword,
|
||||
|
||||
/// The new password confirmation
|
||||
NewPasswordConfirm,
|
||||
}
|
||||
|
||||
impl FormField for RecoveryFinishFormField {
|
||||
fn keep(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Context used by the `pages/recovery/finish.html` template
|
||||
#[derive(Serialize)]
|
||||
pub struct RecoveryFinishContext {
|
||||
user: User,
|
||||
form: FormState<RecoveryFinishFormField>,
|
||||
}
|
||||
|
||||
impl RecoveryFinishContext {
|
||||
/// Constructs a context for the recovery finish page
|
||||
#[must_use]
|
||||
pub fn new(user: User) -> Self {
|
||||
Self {
|
||||
user,
|
||||
form: FormState::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the form state
|
||||
#[must_use]
|
||||
pub fn with_form_state(mut self, form: FormState<RecoveryFinishFormField>) -> Self {
|
||||
self.form = form;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl TemplateContext for RecoveryFinishContext {
|
||||
fn sample(now: chrono::DateTime<Utc>, rng: &mut impl Rng) -> Vec<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
User::samples(now, rng)
|
||||
.into_iter()
|
||||
.flat_map(|user| {
|
||||
vec![
|
||||
Self::new(user.clone()),
|
||||
Self::new(user.clone()).with_form_state(
|
||||
FormState::default().with_error_on_field(
|
||||
RecoveryFinishFormField::NewPassword,
|
||||
FieldError::Invalid,
|
||||
),
|
||||
),
|
||||
Self::new(user.clone()).with_form_state(
|
||||
FormState::default().with_error_on_field(
|
||||
RecoveryFinishFormField::NewPasswordConfirm,
|
||||
FieldError::Invalid,
|
||||
),
|
||||
),
|
||||
]
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// Context used by the `pages/upstream_oauth2/{link_mismatch,do_login}.html`
|
||||
/// templates
|
||||
#[derive(Serialize)]
|
||||
|
@@ -36,6 +36,9 @@ pub enum FieldError {
|
||||
/// Invalid value for this field
|
||||
Invalid,
|
||||
|
||||
/// The password confirmation doesn't match the password
|
||||
PasswordMismatch,
|
||||
|
||||
/// That value already exists
|
||||
Exists,
|
||||
|
||||
|
@@ -46,11 +46,12 @@ pub use self::{
|
||||
DeviceLinkFormField, EmailAddContext, EmailRecoveryContext, EmailVerificationContext,
|
||||
EmailVerificationPageContext, EmptyContext, ErrorContext, FormPostContext, IndexContext,
|
||||
LoginContext, LoginFormField, NotFoundContext, PolicyViolationContext, PostAuthContext,
|
||||
PostAuthContextInner, ReauthContext, ReauthFormField, RecoveryProgressContext,
|
||||
RecoveryStartContext, RecoveryStartFormField, RegisterContext, RegisterFormField,
|
||||
SiteBranding, SiteConfigExt, SiteFeatures, TemplateContext, UpstreamExistingLinkContext,
|
||||
UpstreamRegister, UpstreamRegisterFormField, UpstreamSuggestLink, WithCaptcha, WithCsrf,
|
||||
WithLanguage, WithOptionalSession, WithSession,
|
||||
PostAuthContextInner, ReauthContext, ReauthFormField, RecoveryFinishContext,
|
||||
RecoveryFinishFormField, RecoveryProgressContext, RecoveryStartContext,
|
||||
RecoveryStartFormField, RegisterContext, RegisterFormField, SiteBranding, SiteConfigExt,
|
||||
SiteFeatures, TemplateContext, UpstreamExistingLinkContext, UpstreamRegister,
|
||||
UpstreamRegisterFormField, UpstreamSuggestLink, WithCaptcha, WithCsrf, WithLanguage,
|
||||
WithOptionalSession, WithSession,
|
||||
},
|
||||
forms::{FieldError, FormError, FormField, FormState, ToFormState},
|
||||
};
|
||||
@@ -353,6 +354,8 @@ register_templates! {
|
||||
/// Render the account recovery start page
|
||||
pub fn render_recovery_progress(WithLanguage<WithCsrf<RecoveryProgressContext>>) { "pages/recovery/progress.html" }
|
||||
|
||||
/// Render the account recovery finish page
|
||||
pub fn render_recovery_finish(WithLanguage<WithCsrf<RecoveryFinishContext>>) { "pages/recovery/finish.html" }
|
||||
|
||||
/// Render the re-authentication form
|
||||
pub fn render_reauth(WithLanguage<WithCsrf<WithSession<ReauthContext>>>) { "pages/reauth.html" }
|
||||
@@ -421,6 +424,7 @@ impl Templates {
|
||||
check::render_account_verify_email(self, now, rng)?;
|
||||
check::render_recovery_start(self, now, rng)?;
|
||||
check::render_recovery_progress(self, now, rng)?;
|
||||
check::render_recovery_finish(self, now, rng)?;
|
||||
check::render_reauth(self, now, rng)?;
|
||||
check::render_form_post::<EmptyContext>(self, now, rng)?;
|
||||
check::render_error(self, now, rng)?;
|
||||
|
Reference in New Issue
Block a user