diff --git a/Cargo.lock b/Cargo.lock index 63f3e87..7e08b98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2545,6 +2545,7 @@ dependencies = [ "lldap_domain", "lldap_domain_handlers", "lldap_domain_model", + "lldap_frontend_options", "lldap_validation", "log", "mockall", @@ -2598,6 +2599,7 @@ dependencies = [ "indexmap 1.6.2", "jwt 0.13.0", "lldap_auth", + "lldap_frontend_options", "lldap_validation", "rand 0.8.5", "serde", @@ -2690,6 +2692,13 @@ dependencies = [ "uuid 1.11.0", ] +[[package]] +name = "lldap_frontend_options" +version = "0.1.0" +dependencies = [ + "serde", +] + [[package]] name = "lldap_migration_tool" version = "0.4.2" diff --git a/Cargo.toml b/Cargo.toml index cb21a15..c140df6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ members = [ "crates/domain", "crates/domain-model", "crates/domain-handlers", + "crates/frontend-options", "crates/validation", "server", "app", @@ -27,3 +28,6 @@ git = 'https://github.com/inejge/ldap3/' [workspace.dependencies.sea-orm] version = "1.1.8" default-features = false + +[workspace.dependencies.serde] +version = "1" diff --git a/app/Cargo.toml b/app/Cargo.toml index 3ad6ffd..648e987 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -19,7 +19,6 @@ graphql_client = "0.10" http = "0.2" jwt = "0.13" rand = "0.8" -serde = "1" serde_json = "1" url-escape = "0.1.1" validator = "0.14" @@ -60,6 +59,9 @@ features = [ path = "../crates/auth" features = [ "opaque_client" ] +[dependencies.lldap_frontend_options] +path = "../crates/frontend-options" + [dependencies.lldap_validation] path = "../crates/validation" @@ -68,6 +70,9 @@ features = ["jpeg"] default-features = false version = "0.24" +[dependencies.serde] +workspace = true + [dependencies.yew_form] git = "https://github.com/jfbilodeau/yew_form" rev = "4b9fabffb63393ec7626a4477fd36de12a07fac9" diff --git a/app/src/components/app.rs b/app/src/components/app.rs index 988d3bd..78f89eb 100644 --- a/app/src/components/app.rs +++ b/app/src/components/app.rs @@ -21,6 +21,7 @@ use crate::{ }; use gloo_console::error; +use lldap_frontend_options::Options; use yew::{ function_component, html::Scope, @@ -51,7 +52,7 @@ pub struct App { pub enum Msg { Login((String, bool)), Logout, - PasswordResetProbeFinished(anyhow::Result), + SettingsReceived(anyhow::Result), } impl Component for App { @@ -76,9 +77,8 @@ impl Component for App { redirect_to: Self::get_redirect_route(ctx), password_reset_enabled: None, }; - ctx.link().send_future(async move { - Msg::PasswordResetProbeFinished(HostService::probe_password_reset().await) - }); + ctx.link() + .send_future(async move { Msg::SettingsReceived(HostService::get_settings().await) }); app.apply_initial_redirections(ctx); app } @@ -103,14 +103,11 @@ impl Component for App { self.redirect_to = None; history.push(AppRoute::Login); } - Msg::PasswordResetProbeFinished(Ok(enabled)) => { - self.password_reset_enabled = Some(enabled); + Msg::SettingsReceived(Ok(settings)) => { + self.password_reset_enabled = Some(settings.password_reset_enabled); } - Msg::PasswordResetProbeFinished(Err(err)) => { - self.password_reset_enabled = Some(false); - error!(&format!( - "Could not probe for password reset support: {err:#}" - )); + Msg::SettingsReceived(Err(err)) => { + error!(err.to_string()); } } true diff --git a/app/src/infra/api.rs b/app/src/infra/api.rs index 22d477d..0c40b27 100644 --- a/app/src/infra/api.rs +++ b/app/src/infra/api.rs @@ -4,6 +4,7 @@ use gloo_net::http::{Method, RequestBuilder}; use graphql_client::GraphQLQuery; use lldap_auth::{login, registration, JWTClaims}; +use lldap_frontend_options::Options; use serde::{de::DeserializeOwned, Serialize}; use web_sys::RequestCredentials; @@ -137,6 +138,15 @@ impl HostService { .and_then(set_cookies_from_jwt) } + pub async fn get_settings() -> Result { + call_server_json_with_error_message::( + &(base_url() + "/settings"), + GET_REQUEST, + "Could not fetch settings: ", + ) + .await + } + pub async fn register_start( request: registration::ClientRegistrationStartRequest, ) -> Result> { @@ -202,15 +212,4 @@ impl HostService { ) .await } - - pub async fn probe_password_reset() -> Result { - Ok(gloo_net::http::Request::post( - &(base_url() + "/auth/reset/step1/lldap_unlikely_very_long_user_name"), - ) - .header("Content-Type", "application/json") - .send() - .await? - .status() - != http::StatusCode::NOT_FOUND) - } } diff --git a/crates/auth/Cargo.toml b/crates/auth/Cargo.toml index d4e753b..dc6c729 100644 --- a/crates/auth/Cargo.toml +++ b/crates/auth/Cargo.toml @@ -22,7 +22,6 @@ curve25519-dalek = "3" digest = "0.9" generic-array = "0.14" rand = "0.8" -serde = "*" sha2 = "0.9" thiserror = "*" @@ -43,6 +42,9 @@ workspace = true features = ["macros"] optional = true +[dependencies.serde] +workspace = true + # For WASM targets, use the JS getrandom. [target.'cfg(not(target_arch = "wasm32"))'.dependencies.getrandom] version = "0.2" diff --git a/crates/domain-handlers/Cargo.toml b/crates/domain-handlers/Cargo.toml index 5b89df0..2b0a344 100644 --- a/crates/domain-handlers/Cargo.toml +++ b/crates/domain-handlers/Cargo.toml @@ -11,7 +11,6 @@ test = [] async-trait = "0.1" base64 = "0.21" ldap3_proto = "0.6.0" -serde = "1" serde_bytes = "0.11" [dev-dependencies] @@ -36,6 +35,9 @@ path = "../domain" [dependencies.lldap_domain_model] path = "../domain-model" +[dependencies.serde] +workspace = true + [dependencies.uuid] features = ["v1", "v3"] version = "1" diff --git a/crates/domain-model/Cargo.toml b/crates/domain-model/Cargo.toml index 10ecb34..77bc5a7 100644 --- a/crates/domain-model/Cargo.toml +++ b/crates/domain-model/Cargo.toml @@ -11,7 +11,6 @@ test = [] base64 = "0.21" bincode = "1.3" orion = "0.17" -serde = "1" serde_bytes = "0.11" thiserror = "1" @@ -44,6 +43,9 @@ features = [ "runtime-actix-rustls", ] +[dependencies.serde] +workspace = true + [dependencies.uuid] features = ["v1", "v3"] version = "1" diff --git a/crates/domain/Cargo.toml b/crates/domain/Cargo.toml index 826cf0a..136b1cf 100644 --- a/crates/domain/Cargo.toml +++ b/crates/domain/Cargo.toml @@ -15,7 +15,6 @@ anyhow = "*" base64 = "0.21" bincode = "1.3" juniper = "0.15" -serde = "*" serde_bytes = "0.11" [dev-dependencies] @@ -49,6 +48,9 @@ features = [ "runtime-actix-rustls", ] +[dependencies.serde] +workspace = true + [dependencies.strum] features = ["derive"] version = "0.25" diff --git a/crates/frontend-options/Cargo.toml b/crates/frontend-options/Cargo.toml new file mode 100644 index 0000000..a42d5a3 --- /dev/null +++ b/crates/frontend-options/Cargo.toml @@ -0,0 +1,12 @@ +[package] +authors = ["Valentin Tolmer ( ) } +async fn get_settings(data: web::Data>) -> HttpResponse { + HttpResponse::Ok().json(lldap_frontend_options::Options { + password_reset_enabled: data.mail_options.enable_password_reset, + }) +} + fn http_config( cfg: &mut web::ServiceConfig, backend_handler: Backend, @@ -132,6 +138,7 @@ fn http_config( "/health", web::get().to(|| async { HttpResponse::Ok().finish() }), ) + .route("/settings", web::get().to(get_settings::)) .service( web::scope("/auth") .configure(|cfg| auth_service::configure_server::(cfg, enable_password_reset)), diff --git a/set-password/Cargo.toml b/set-password/Cargo.toml index 6bbe464..0cfc294 100644 --- a/set-password/Cargo.toml +++ b/set-password/Cargo.toml @@ -13,7 +13,6 @@ version = "0.1.0" [dependencies] anyhow = "*" rand = "0.8" -serde = "1" serde_json = "1" [dependencies.clap] @@ -28,3 +27,6 @@ features = ["opaque_client"] version = "*" default-features = false features = ["json", "blocking", "rustls-tls"] + +[dependencies.serde] +workspace = true