🔒️ (user): Refuerza la seguridad de las cuentas

- Límite de solicitudes por dirección IP para registros, recuperaciones
  de contraseña y cambios de email (`max_ip_requests`).
- Avisa del cambio de contraseña, propio o de un administrador.
- El email propio se cambia en /user/email con la contraseña actual y no
  se aplica hasta confirmarlo desde un enlace ligado a esa dirección.
- Cambiar el email o la contraseña anula los enlaces antiguos, y los
  fallos de la contraseña actual cuentan para el bloqueo de la cuenta.
- `Referrer-Policy: no-referrer` en las páginas con token en la URL.
This commit is contained in:
Manuel Cillero 2026-10-31 22:16:45 +01:00
parent d7caf724dd
commit 15a96a8310
25 changed files with 1850 additions and 196 deletions

View file

@ -60,6 +60,9 @@ impl Component for UserForm {
};
let username_readonly =
*self.mode() == UserFormMode::Profile && !*self.allow_username_field();
// El propio usuario cambia su email en otra pantalla, que pide su contraseña y confirma la
// nueva dirección antes de aplicarla.
let email_readonly = *self.mode() == UserFormMode::Profile;
let action = self.waypoint().append_to(cx.route(action));
let mut form = Form::new()
@ -87,7 +90,13 @@ impl Component for UserForm {
.with_name("email")
.with_value(self.email())
.with_label(Lc::t("field-email", &LOCALES_USER))
.with_help_text(if email_readonly {
Lc::t("help-email-readonly", &LOCALES_USER)
} else {
Lc::none()
})
.with_required(true)
.with_readonly(email_readonly)
.with_maxlength(EMAIL_MAX_CHARS),
)
.with_child(

View file

@ -0,0 +1,86 @@
//! Formulario para que el usuario autenticado cambie su propia dirección de email.
use pagetop::prelude::*;
use crate::{EMAIL_PATH, LOCALES_USER};
use crate::component::error_banner;
use crate::identity::EMAIL_MAX_CHARS;
/// Pide la nueva dirección y la contraseña actual. Si ya hay un cambio pendiente de confirmar, lo
/// indica: pedir otro lo sustituye.
#[derive(AutoDefault, Clone, Debug, Getters)]
pub(crate) struct ChangeEmailForm {
error: Option<Lc>,
email: String,
pending_email: Option<String>,
}
#[async_trait]
impl Component for ChangeEmailForm {
fn new() -> Self {
Self::default()
}
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
let mut form = Form::new()
.with_id("user-change-email-form")
.with_action(cx.route(EMAIL_PATH))
.with_method(form::Method::Post)
.with_child(error_banner(self.error().cloned()));
if let Some(pending) = self.pending_email().cloned() {
form = form.with_child(Html::with(move |cx| {
html! {
p {
(Lc::t("msg-email-change-pending", &LOCALES_USER)
.with_arg("email", pending.clone())
.using(cx))
}
}
}));
}
form = form
.with_child(
form::input::Field::email()
.with_name("email")
.with_value(self.email())
.with_label(Lc::t("field-new-email", &LOCALES_USER))
.with_autocomplete(Some(form::Autocomplete::email()))
.with_required(true)
.with_maxlength(EMAIL_MAX_CHARS),
)
.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(
Button::submit(Lc::t("btn-change-email", &LOCALES_USER))
.with_style(button::Style::Solid(Intent::Primary)),
);
Ok(form.render(cx).await)
}
}
#[builder_impl]
impl ChangeEmailForm {
// **< ChangeEmailForm BUILDER >****************************************************************
pub(crate) fn with_error(mut self, error: impl Into<Option<Lc>>) -> Self {
self.error = error.into();
self
}
pub(crate) fn with_email(mut self, email: impl Into<String>) -> Self {
self.email = email.into();
self
}
pub(crate) fn with_pending_email(mut self, pending_email: impl Into<Option<String>>) -> Self {
self.pending_email = pending_email.into();
self
}
}