mirror of
https://github.com/lldap/lldap.git
synced 2026-07-25 17:58:44 +00:00
app, server: Add an endpoint to fetch the frontend settings
This commit is contained in:
committed by
nitnelave
parent
ba93533790
commit
5afcdbda65
Generated
+9
@@ -2545,6 +2545,7 @@ dependencies = [
|
|||||||
"lldap_domain",
|
"lldap_domain",
|
||||||
"lldap_domain_handlers",
|
"lldap_domain_handlers",
|
||||||
"lldap_domain_model",
|
"lldap_domain_model",
|
||||||
|
"lldap_frontend_options",
|
||||||
"lldap_validation",
|
"lldap_validation",
|
||||||
"log",
|
"log",
|
||||||
"mockall",
|
"mockall",
|
||||||
@@ -2598,6 +2599,7 @@ dependencies = [
|
|||||||
"indexmap 1.6.2",
|
"indexmap 1.6.2",
|
||||||
"jwt 0.13.0",
|
"jwt 0.13.0",
|
||||||
"lldap_auth",
|
"lldap_auth",
|
||||||
|
"lldap_frontend_options",
|
||||||
"lldap_validation",
|
"lldap_validation",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -2690,6 +2692,13 @@ dependencies = [
|
|||||||
"uuid 1.11.0",
|
"uuid 1.11.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lldap_frontend_options"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lldap_migration_tool"
|
name = "lldap_migration_tool"
|
||||||
version = "0.4.2"
|
version = "0.4.2"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ members = [
|
|||||||
"crates/domain",
|
"crates/domain",
|
||||||
"crates/domain-model",
|
"crates/domain-model",
|
||||||
"crates/domain-handlers",
|
"crates/domain-handlers",
|
||||||
|
"crates/frontend-options",
|
||||||
"crates/validation",
|
"crates/validation",
|
||||||
"server",
|
"server",
|
||||||
"app",
|
"app",
|
||||||
@@ -27,3 +28,6 @@ git = 'https://github.com/inejge/ldap3/'
|
|||||||
[workspace.dependencies.sea-orm]
|
[workspace.dependencies.sea-orm]
|
||||||
version = "1.1.8"
|
version = "1.1.8"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
||||||
|
[workspace.dependencies.serde]
|
||||||
|
version = "1"
|
||||||
|
|||||||
+6
-1
@@ -19,7 +19,6 @@ graphql_client = "0.10"
|
|||||||
http = "0.2"
|
http = "0.2"
|
||||||
jwt = "0.13"
|
jwt = "0.13"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
serde = "1"
|
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
url-escape = "0.1.1"
|
url-escape = "0.1.1"
|
||||||
validator = "0.14"
|
validator = "0.14"
|
||||||
@@ -60,6 +59,9 @@ features = [
|
|||||||
path = "../crates/auth"
|
path = "../crates/auth"
|
||||||
features = [ "opaque_client" ]
|
features = [ "opaque_client" ]
|
||||||
|
|
||||||
|
[dependencies.lldap_frontend_options]
|
||||||
|
path = "../crates/frontend-options"
|
||||||
|
|
||||||
[dependencies.lldap_validation]
|
[dependencies.lldap_validation]
|
||||||
path = "../crates/validation"
|
path = "../crates/validation"
|
||||||
|
|
||||||
@@ -68,6 +70,9 @@ features = ["jpeg"]
|
|||||||
default-features = false
|
default-features = false
|
||||||
version = "0.24"
|
version = "0.24"
|
||||||
|
|
||||||
|
[dependencies.serde]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
[dependencies.yew_form]
|
[dependencies.yew_form]
|
||||||
git = "https://github.com/jfbilodeau/yew_form"
|
git = "https://github.com/jfbilodeau/yew_form"
|
||||||
rev = "4b9fabffb63393ec7626a4477fd36de12a07fac9"
|
rev = "4b9fabffb63393ec7626a4477fd36de12a07fac9"
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use gloo_console::error;
|
use gloo_console::error;
|
||||||
|
use lldap_frontend_options::Options;
|
||||||
use yew::{
|
use yew::{
|
||||||
function_component,
|
function_component,
|
||||||
html::Scope,
|
html::Scope,
|
||||||
@@ -51,7 +52,7 @@ pub struct App {
|
|||||||
pub enum Msg {
|
pub enum Msg {
|
||||||
Login((String, bool)),
|
Login((String, bool)),
|
||||||
Logout,
|
Logout,
|
||||||
PasswordResetProbeFinished(anyhow::Result<bool>),
|
SettingsReceived(anyhow::Result<Options>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Component for App {
|
impl Component for App {
|
||||||
@@ -76,9 +77,8 @@ impl Component for App {
|
|||||||
redirect_to: Self::get_redirect_route(ctx),
|
redirect_to: Self::get_redirect_route(ctx),
|
||||||
password_reset_enabled: None,
|
password_reset_enabled: None,
|
||||||
};
|
};
|
||||||
ctx.link().send_future(async move {
|
ctx.link()
|
||||||
Msg::PasswordResetProbeFinished(HostService::probe_password_reset().await)
|
.send_future(async move { Msg::SettingsReceived(HostService::get_settings().await) });
|
||||||
});
|
|
||||||
app.apply_initial_redirections(ctx);
|
app.apply_initial_redirections(ctx);
|
||||||
app
|
app
|
||||||
}
|
}
|
||||||
@@ -103,14 +103,11 @@ impl Component for App {
|
|||||||
self.redirect_to = None;
|
self.redirect_to = None;
|
||||||
history.push(AppRoute::Login);
|
history.push(AppRoute::Login);
|
||||||
}
|
}
|
||||||
Msg::PasswordResetProbeFinished(Ok(enabled)) => {
|
Msg::SettingsReceived(Ok(settings)) => {
|
||||||
self.password_reset_enabled = Some(enabled);
|
self.password_reset_enabled = Some(settings.password_reset_enabled);
|
||||||
}
|
}
|
||||||
Msg::PasswordResetProbeFinished(Err(err)) => {
|
Msg::SettingsReceived(Err(err)) => {
|
||||||
self.password_reset_enabled = Some(false);
|
error!(err.to_string());
|
||||||
error!(&format!(
|
|
||||||
"Could not probe for password reset support: {err:#}"
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
|||||||
+10
-11
@@ -4,6 +4,7 @@ use gloo_net::http::{Method, RequestBuilder};
|
|||||||
use graphql_client::GraphQLQuery;
|
use graphql_client::GraphQLQuery;
|
||||||
use lldap_auth::{login, registration, JWTClaims};
|
use lldap_auth::{login, registration, JWTClaims};
|
||||||
|
|
||||||
|
use lldap_frontend_options::Options;
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
use web_sys::RequestCredentials;
|
use web_sys::RequestCredentials;
|
||||||
|
|
||||||
@@ -137,6 +138,15 @@ impl HostService {
|
|||||||
.and_then(set_cookies_from_jwt)
|
.and_then(set_cookies_from_jwt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_settings() -> Result<Options> {
|
||||||
|
call_server_json_with_error_message::<Options, _>(
|
||||||
|
&(base_url() + "/settings"),
|
||||||
|
GET_REQUEST,
|
||||||
|
"Could not fetch settings: ",
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn register_start(
|
pub async fn register_start(
|
||||||
request: registration::ClientRegistrationStartRequest,
|
request: registration::ClientRegistrationStartRequest,
|
||||||
) -> Result<Box<registration::ServerRegistrationStartResponse>> {
|
) -> Result<Box<registration::ServerRegistrationStartResponse>> {
|
||||||
@@ -202,15 +212,4 @@ impl HostService {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn probe_password_reset() -> Result<bool> {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ curve25519-dalek = "3"
|
|||||||
digest = "0.9"
|
digest = "0.9"
|
||||||
generic-array = "0.14"
|
generic-array = "0.14"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
serde = "*"
|
|
||||||
sha2 = "0.9"
|
sha2 = "0.9"
|
||||||
thiserror = "*"
|
thiserror = "*"
|
||||||
|
|
||||||
@@ -43,6 +42,9 @@ workspace = true
|
|||||||
features = ["macros"]
|
features = ["macros"]
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
|
[dependencies.serde]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
# For WASM targets, use the JS getrandom.
|
# For WASM targets, use the JS getrandom.
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.getrandom]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.getrandom]
|
||||||
version = "0.2"
|
version = "0.2"
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ test = []
|
|||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
base64 = "0.21"
|
base64 = "0.21"
|
||||||
ldap3_proto = "0.6.0"
|
ldap3_proto = "0.6.0"
|
||||||
serde = "1"
|
|
||||||
serde_bytes = "0.11"
|
serde_bytes = "0.11"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
@@ -36,6 +35,9 @@ path = "../domain"
|
|||||||
[dependencies.lldap_domain_model]
|
[dependencies.lldap_domain_model]
|
||||||
path = "../domain-model"
|
path = "../domain-model"
|
||||||
|
|
||||||
|
[dependencies.serde]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
[dependencies.uuid]
|
[dependencies.uuid]
|
||||||
features = ["v1", "v3"]
|
features = ["v1", "v3"]
|
||||||
version = "1"
|
version = "1"
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ test = []
|
|||||||
base64 = "0.21"
|
base64 = "0.21"
|
||||||
bincode = "1.3"
|
bincode = "1.3"
|
||||||
orion = "0.17"
|
orion = "0.17"
|
||||||
serde = "1"
|
|
||||||
serde_bytes = "0.11"
|
serde_bytes = "0.11"
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
|
|
||||||
@@ -44,6 +43,9 @@ features = [
|
|||||||
"runtime-actix-rustls",
|
"runtime-actix-rustls",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[dependencies.serde]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
[dependencies.uuid]
|
[dependencies.uuid]
|
||||||
features = ["v1", "v3"]
|
features = ["v1", "v3"]
|
||||||
version = "1"
|
version = "1"
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ anyhow = "*"
|
|||||||
base64 = "0.21"
|
base64 = "0.21"
|
||||||
bincode = "1.3"
|
bincode = "1.3"
|
||||||
juniper = "0.15"
|
juniper = "0.15"
|
||||||
serde = "*"
|
|
||||||
serde_bytes = "0.11"
|
serde_bytes = "0.11"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
@@ -49,6 +48,9 @@ features = [
|
|||||||
"runtime-actix-rustls",
|
"runtime-actix-rustls",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[dependencies.serde]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
[dependencies.strum]
|
[dependencies.strum]
|
||||||
features = ["derive"]
|
features = ["derive"]
|
||||||
version = "0.25"
|
version = "0.25"
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
authors = ["Valentin Tolmer <valentin@tolmer.fr"]
|
||||||
|
description = "Frontend options for LLDAP"
|
||||||
|
edition = "2024"
|
||||||
|
homepage = "https://github.com/lldap/lldap"
|
||||||
|
license = "GPL-3.0-only"
|
||||||
|
name = "lldap_frontend_options"
|
||||||
|
repository = "https://github.com/lldap/lldap"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[dependencies.serde]
|
||||||
|
workspace = true
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct Options {
|
||||||
|
pub password_reset_enabled: bool,
|
||||||
|
}
|
||||||
@@ -13,7 +13,6 @@ anyhow = "*"
|
|||||||
base64 = "0.13"
|
base64 = "0.13"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
requestty = "0.4.1"
|
requestty = "0.4.1"
|
||||||
serde = "1"
|
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
smallvec = "*"
|
smallvec = "*"
|
||||||
|
|
||||||
@@ -35,3 +34,6 @@ features = ["json", "blocking", "rustls-tls"]
|
|||||||
version = "*"
|
version = "*"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["sync", "tls-rustls"]
|
features = ["sync", "tls-rustls"]
|
||||||
|
|
||||||
|
[dependencies.serde]
|
||||||
|
workspace = true
|
||||||
|
|||||||
+6
-1
@@ -39,7 +39,6 @@ log = "*"
|
|||||||
orion = "0.17"
|
orion = "0.17"
|
||||||
rand_chacha = "0.3"
|
rand_chacha = "0.3"
|
||||||
rustls-pemfile = "1"
|
rustls-pemfile = "1"
|
||||||
serde = "*"
|
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
sha2 = "0.10"
|
sha2 = "0.10"
|
||||||
thiserror = "*"
|
thiserror = "*"
|
||||||
@@ -97,6 +96,9 @@ path = "../crates/domain-model"
|
|||||||
[dependencies.lldap_domain_handlers]
|
[dependencies.lldap_domain_handlers]
|
||||||
path = "../crates/domain-handlers"
|
path = "../crates/domain-handlers"
|
||||||
|
|
||||||
|
[dependencies.lldap_frontend_options]
|
||||||
|
path = "../crates/frontend-options"
|
||||||
|
|
||||||
[dependencies.lldap_validation]
|
[dependencies.lldap_validation]
|
||||||
path = "../crates/validation"
|
path = "../crates/validation"
|
||||||
|
|
||||||
@@ -111,6 +113,9 @@ version = "0.8"
|
|||||||
features = ["serde"]
|
features = ["serde"]
|
||||||
version = "*"
|
version = "*"
|
||||||
|
|
||||||
|
[dependencies.serde]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
[dependencies.strum]
|
[dependencies.strum]
|
||||||
features = ["derive"]
|
features = ["derive"]
|
||||||
version = "0.25"
|
version = "0.25"
|
||||||
|
|||||||
@@ -108,6 +108,12 @@ async fn wasm_handler_compressed<Backend>(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_settings<Backend>(data: web::Data<AppState<Backend>>) -> HttpResponse {
|
||||||
|
HttpResponse::Ok().json(lldap_frontend_options::Options {
|
||||||
|
password_reset_enabled: data.mail_options.enable_password_reset,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn http_config<Backend>(
|
fn http_config<Backend>(
|
||||||
cfg: &mut web::ServiceConfig,
|
cfg: &mut web::ServiceConfig,
|
||||||
backend_handler: Backend,
|
backend_handler: Backend,
|
||||||
@@ -132,6 +138,7 @@ fn http_config<Backend>(
|
|||||||
"/health",
|
"/health",
|
||||||
web::get().to(|| async { HttpResponse::Ok().finish() }),
|
web::get().to(|| async { HttpResponse::Ok().finish() }),
|
||||||
)
|
)
|
||||||
|
.route("/settings", web::get().to(get_settings::<Backend>))
|
||||||
.service(
|
.service(
|
||||||
web::scope("/auth")
|
web::scope("/auth")
|
||||||
.configure(|cfg| auth_service::configure_server::<Backend>(cfg, enable_password_reset)),
|
.configure(|cfg| auth_service::configure_server::<Backend>(cfg, enable_password_reset)),
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ version = "0.1.0"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "*"
|
anyhow = "*"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
serde = "1"
|
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
|
||||||
[dependencies.clap]
|
[dependencies.clap]
|
||||||
@@ -28,3 +27,6 @@ features = ["opaque_client"]
|
|||||||
version = "*"
|
version = "*"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["json", "blocking", "rustls-tls"]
|
features = ["json", "blocking", "rustls-tls"]
|
||||||
|
|
||||||
|
[dependencies.serde]
|
||||||
|
workspace = true
|
||||||
|
|||||||
Reference in New Issue
Block a user