From c4b8621e2ac09bfc5dbca9315ca3a9c54545c6b4 Mon Sep 17 00:00:00 2001 From: Austin Alvarado Date: Thu, 30 Mar 2023 09:47:41 -0600 Subject: [PATCH] app: Fix password reset redirection (#513) * Fix password reset redirection * Add password reset enable flag --- app/src/components/app.rs | 8 +++++++- server/src/infra/auth_service.rs | 3 ++- server/src/infra/cli.rs | 4 ++++ server/src/infra/configuration.rs | 3 +++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/components/app.rs b/app/src/components/app.rs index 36a6308..3d03afb 100644 --- a/app/src/components/app.rs +++ b/app/src/components/app.rs @@ -177,7 +177,13 @@ impl App { Some(AppRoute::StartResetPassword | AppRoute::FinishResetPassword { token: _ }), _, _, - ) if self.password_reset_enabled == Some(false) => Some(AppRoute::Login), + ) => { + if self.password_reset_enabled == Some(false) { + Some(AppRoute::Login) + } else { + None + } + } (None, _, _) | (_, None, _) => Some(AppRoute::Login), // User is logged in, a URL was given, don't redirect. (_, Some(_), Some(_)) => None, diff --git a/server/src/infra/auth_service.rs b/server/src/infra/auth_service.rs index 558af2b..4f7581b 100644 --- a/server/src/infra/auth_service.rs +++ b/server/src/infra/auth_service.rs @@ -18,7 +18,7 @@ use hmac::Hmac; use jwt::{SignWithKey, VerifyWithKey}; use sha2::Sha512; use time::ext::NumericalDuration; -use tracing::{debug, instrument, warn}; +use tracing::{debug, info, instrument, warn}; use lldap_auth::{login, password_reset, registration, JWTClaims}; @@ -183,6 +183,7 @@ where .await { warn!("Error sending email: {:#?}", e); + info!("Reset token: {}", token); return Err(TcpError::InternalServerError(format!( "Could not send email: {}", e diff --git a/server/src/infra/cli.rs b/server/src/infra/cli.rs index 1ee6a99..0a3b94d 100644 --- a/server/src/infra/cli.rs +++ b/server/src/infra/cli.rs @@ -132,6 +132,10 @@ pub enum SmtpEncryption { #[derive(Debug, Parser, Clone)] #[clap(next_help_heading = Some("SMTP"))] pub struct SmtpOpts { + /// Enable password reset. + #[clap(long, env = "LLDAP_SMTP_OPTIONS__ENABLE_PASSWORD_RESET")] + pub smtp_enable_password_reset: Option, + /// Sender email address. #[clap(long, env = "LLDAP_SMTP_OPTIONS__FROM")] pub smtp_from: Option, diff --git a/server/src/infra/configuration.rs b/server/src/infra/configuration.rs index 6426a1c..bf806d3 100644 --- a/server/src/infra/configuration.rs +++ b/server/src/infra/configuration.rs @@ -276,6 +276,9 @@ impl ConfigOverrider for SmtpOpts { if let Some(tls_required) = self.smtp_tls_required { config.smtp_options.tls_required = Some(tls_required); } + if let Some(enable_password_reset) = self.smtp_enable_password_reset { + config.smtp_options.enable_password_reset = enable_password_reset; + } } }