You've already forked lldap
mirror of
https://github.com/lldap/lldap.git
synced 2026-04-05 12:32:57 +01: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_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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
+6
-1
@@ -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"
|
||||
|
||||
@@ -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<bool>),
|
||||
SettingsReceived(anyhow::Result<Options>),
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
+10
-11
@@ -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<Options> {
|
||||
call_server_json_with_error_message::<Options, _>(
|
||||
&(base_url() + "/settings"),
|
||||
GET_REQUEST,
|
||||
"Could not fetch settings: ",
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn register_start(
|
||||
request: registration::ClientRegistrationStartRequest,
|
||||
) -> Result<Box<registration::ServerRegistrationStartResponse>> {
|
||||
@@ -202,15 +212,4 @@ impl HostService {
|
||||
)
|
||||
.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"
|
||||
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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
rand = "0.8"
|
||||
requestty = "0.4.1"
|
||||
serde = "1"
|
||||
serde_json = "1"
|
||||
smallvec = "*"
|
||||
|
||||
@@ -35,3 +34,6 @@ features = ["json", "blocking", "rustls-tls"]
|
||||
version = "*"
|
||||
default-features = false
|
||||
features = ["sync", "tls-rustls"]
|
||||
|
||||
[dependencies.serde]
|
||||
workspace = true
|
||||
|
||||
+6
-1
@@ -39,7 +39,6 @@ log = "*"
|
||||
orion = "0.17"
|
||||
rand_chacha = "0.3"
|
||||
rustls-pemfile = "1"
|
||||
serde = "*"
|
||||
serde_json = "1"
|
||||
sha2 = "0.10"
|
||||
thiserror = "*"
|
||||
@@ -97,6 +96,9 @@ path = "../crates/domain-model"
|
||||
[dependencies.lldap_domain_handlers]
|
||||
path = "../crates/domain-handlers"
|
||||
|
||||
[dependencies.lldap_frontend_options]
|
||||
path = "../crates/frontend-options"
|
||||
|
||||
[dependencies.lldap_validation]
|
||||
path = "../crates/validation"
|
||||
|
||||
@@ -111,6 +113,9 @@ version = "0.8"
|
||||
features = ["serde"]
|
||||
version = "*"
|
||||
|
||||
[dependencies.serde]
|
||||
workspace = true
|
||||
|
||||
[dependencies.strum]
|
||||
features = ["derive"]
|
||||
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>(
|
||||
cfg: &mut web::ServiceConfig,
|
||||
backend_handler: Backend,
|
||||
@@ -132,6 +138,7 @@ fn http_config<Backend>(
|
||||
"/health",
|
||||
web::get().to(|| async { HttpResponse::Ok().finish() }),
|
||||
)
|
||||
.route("/settings", web::get().to(get_settings::<Backend>))
|
||||
.service(
|
||||
web::scope("/auth")
|
||||
.configure(|cfg| auth_service::configure_server::<Backend>(cfg, enable_password_reset)),
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user