2021-07-25 02:51:37 +02:00
|
|
|
//! This is the top level router of the web ui for kanidm. It decides based on the incoming
|
|
|
|
//! request, where to direct this too, and if the requirements for that request have been
|
|
|
|
//! met before rendering. For example, if you land here with an oauth request, but you are
|
|
|
|
//! not atuhenticated, this will determine that and send you to authentication first, then
|
|
|
|
//! will allow you to proceed with the oauth flow.
|
|
|
|
|
2021-12-31 00:11:20 +01:00
|
|
|
use gloo::console;
|
2022-02-20 03:43:38 +01:00
|
|
|
use wasm_bindgen::UnwrapThrowExt;
|
2021-12-31 00:11:20 +01:00
|
|
|
use yew::functional::*;
|
2021-07-25 02:51:37 +02:00
|
|
|
use yew::prelude::*;
|
|
|
|
use yew_router::prelude::*;
|
|
|
|
|
2022-06-05 08:30:08 +02:00
|
|
|
use crate::credential::reset::CredentialResetApp;
|
2021-07-25 02:51:37 +02:00
|
|
|
use crate::login::LoginApp;
|
|
|
|
use crate::oauth2::Oauth2App;
|
2022-02-20 03:43:38 +01:00
|
|
|
use crate::views::{ViewRoute, ViewsApp};
|
|
|
|
use serde::{Deserialize, Serialize};
|
2021-07-25 02:51:37 +02:00
|
|
|
|
|
|
|
// router to decide on state.
|
2022-02-20 03:43:38 +01:00
|
|
|
#[derive(Routable, PartialEq, Clone, Debug, Serialize, Deserialize)]
|
2021-07-25 02:51:37 +02:00
|
|
|
pub enum Route {
|
|
|
|
#[at("/")]
|
|
|
|
Landing,
|
|
|
|
|
2022-02-20 03:43:38 +01:00
|
|
|
#[at("/ui/view/:s")]
|
|
|
|
Views,
|
2021-07-25 02:51:37 +02:00
|
|
|
|
|
|
|
#[at("/ui/login")]
|
|
|
|
Login,
|
|
|
|
|
|
|
|
#[at("/ui/oauth2")]
|
|
|
|
Oauth2,
|
|
|
|
|
2022-06-05 08:30:08 +02:00
|
|
|
#[at("/ui/reset")]
|
|
|
|
CredentialReset,
|
|
|
|
|
2021-07-25 02:51:37 +02:00
|
|
|
#[not_found]
|
2022-06-05 08:30:08 +02:00
|
|
|
#[at("/ui/404")]
|
2021-07-25 02:51:37 +02:00
|
|
|
NotFound,
|
|
|
|
}
|
|
|
|
|
2021-12-31 00:11:20 +01:00
|
|
|
#[function_component(Landing)]
|
|
|
|
fn landing() -> Html {
|
|
|
|
// Do this to allow use_history to work because lol.
|
2022-02-20 03:43:38 +01:00
|
|
|
use_history()
|
|
|
|
.expect_throw("Unable to access history")
|
|
|
|
.push(ViewRoute::Apps);
|
2022-01-09 01:47:21 +01:00
|
|
|
html! { <main></main> }
|
2021-12-31 00:11:20 +01:00
|
|
|
}
|
|
|
|
|
2022-02-20 03:43:38 +01:00
|
|
|
fn switch(route: &Route) -> Html {
|
2021-12-31 00:11:20 +01:00
|
|
|
console::log!("manager::switch");
|
2022-02-20 03:43:38 +01:00
|
|
|
match route {
|
2021-12-31 00:11:20 +01:00
|
|
|
Route::Landing => html! { <Landing /> },
|
2021-07-25 02:51:37 +02:00
|
|
|
Route::Login => html! { <LoginApp /> },
|
|
|
|
Route::Oauth2 => html! { <Oauth2App /> },
|
2022-02-20 03:43:38 +01:00
|
|
|
Route::Views => html! { <ViewsApp /> },
|
2022-06-05 08:30:08 +02:00
|
|
|
Route::CredentialReset => html! { <CredentialResetApp /> },
|
2021-07-25 02:51:37 +02:00
|
|
|
Route::NotFound => {
|
|
|
|
html! {
|
2022-01-09 01:47:21 +01:00
|
|
|
<main>
|
2021-07-25 02:51:37 +02:00
|
|
|
<h1>{ "404" }</h1>
|
2022-02-20 03:43:38 +01:00
|
|
|
<Link<ViewRoute> to={ ViewRoute::Apps }>
|
2021-07-25 02:51:37 +02:00
|
|
|
{ "Home" }
|
2022-02-20 03:43:38 +01:00
|
|
|
</Link<ViewRoute>>
|
2022-01-09 01:47:21 +01:00
|
|
|
</main>
|
2021-07-25 02:51:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-09 01:47:21 +01:00
|
|
|
pub struct ManagerApp {}
|
2021-07-25 02:51:37 +02:00
|
|
|
|
|
|
|
impl Component for ManagerApp {
|
2022-01-09 01:47:21 +01:00
|
|
|
type Message = ();
|
2021-07-25 02:51:37 +02:00
|
|
|
type Properties = ();
|
|
|
|
|
2021-12-31 00:11:20 +01:00
|
|
|
fn create(_ctx: &Context<Self>) -> Self {
|
|
|
|
console::log!("manager::create");
|
2022-01-09 01:47:21 +01:00
|
|
|
ManagerApp {}
|
2021-07-25 02:51:37 +02:00
|
|
|
}
|
|
|
|
|
2021-12-31 00:11:20 +01:00
|
|
|
fn changed(&mut self, _ctx: &Context<Self>) -> bool {
|
|
|
|
console::log!("manager::change");
|
2021-07-25 02:51:37 +02:00
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2022-01-09 01:47:21 +01:00
|
|
|
fn update(&mut self, _ctx: &Context<Self>, _msg: Self::Message) -> bool {
|
2021-12-31 00:11:20 +01:00
|
|
|
console::log!("manager::update");
|
2021-07-25 02:51:37 +02:00
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2022-01-09 01:47:21 +01:00
|
|
|
fn rendered(&mut self, _ctx: &Context<Self>, _first_render: bool) {
|
2021-12-31 00:11:20 +01:00
|
|
|
console::log!("manager::rendered");
|
2022-01-09 01:47:21 +01:00
|
|
|
// Can only access the current_route AFTER it renders.
|
|
|
|
// console::log!(format!("{:?}", yew_router::current_route::<Route>()).as_str())
|
2021-07-25 02:51:37 +02:00
|
|
|
}
|
|
|
|
|
2021-12-31 00:11:20 +01:00
|
|
|
fn view(&self, _ctx: &Context<Self>) -> Html {
|
2021-07-25 02:51:37 +02:00
|
|
|
html! {
|
2022-01-09 01:47:21 +01:00
|
|
|
<BrowserRouter>
|
|
|
|
<Switch<Route> render={ Switch::render(switch) } />
|
|
|
|
</BrowserRouter>
|
2021-07-25 02:51:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|