//! Formulario para que el usuario autenticado cambie su propia contraseña. use pagetop::prelude::*; use crate::{LOCALES_USER, PROFILE_PASSWORD_PATH}; use crate::component::{PasswordConfirm, error_banner, profile_form_actions}; /// Pide la contraseña actual además de la nueva y su confirmación, a diferencia del /// restablecimiento por un administrador. #[derive(AutoDefault, Clone, Debug, Getters)] pub(crate) struct ChangePasswordForm { error: Option, } #[async_trait] impl Component for ChangePasswordForm { fn new() -> Self { Self::default() } async fn prepare(&self, cx: &mut Context) -> Result { let mut form = Form::new() .with_id("user-change-password-form") .with_action(cx.route(PROFILE_PASSWORD_PATH)) .with_method(form::Method::Post) .with_child(error_banner(self.error().cloned())) .with_child( form::input::Field::password() .with_name("current_password") .with_label(Lc::t("field-current-password", &LOCALES_USER)) .with_autocomplete(Some(form::Autocomplete::current_password())) .with_required(true), ) .with_child( PasswordConfirm::new() .with_password_label(Lc::t("field-new-password", &LOCALES_USER)), ) .with_child(profile_form_actions( Lc::t("btn-set-password", &LOCALES_USER), cx, )); Ok(form.render(cx).await) } } #[builder_impl] impl ChangePasswordForm { // **< ChangePasswordForm BUILDER >************************************************************* pub(crate) fn with_error(mut self, error: impl Into>) -> Self { self.error = error.into(); self } }