mirror of
https://github.com/lldap/lldap.git
synced 2026-03-31 15:07:48 +01:00
app, server: Add an endpoint to fetch the frontend settings
This commit is contained in:
committed by
nitnelave
parent
ba93533790
commit
5afcdbda65
+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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user