fedimint_server_ui/
lib.rs

1pub mod dashboard;
2pub mod setup;
3
4use axum::response::{Html, IntoResponse, Redirect};
5use axum_extra::extract::cookie::{Cookie, CookieJar, SameSite};
6use fedimint_core::module::ApiAuth;
7use fedimint_ui_common::{LoginInput, common_head, login_layout};
8use maud::html;
9use serde::Deserialize;
10
11pub(crate) const LOG_UI: &str = "fm::ui";
12
13// Common route constants
14pub const EXPLORER_IDX_ROUTE: &str = "/explorer";
15pub const EXPLORER_ROUTE: &str = "/explorer/{session_idx}";
16pub const DOWNLOAD_BACKUP_ROUTE: &str = "/download-backup";
17pub const CHANGE_PASSWORD_ROUTE: &str = "/change-password";
18
19#[derive(Debug, Deserialize)]
20pub struct PasswordChangeInput {
21    pub current_password: String,
22    pub new_password: String,
23    pub confirm_password: String,
24}
25
26pub(crate) fn login_submit_response(
27    auth: ApiAuth,
28    auth_cookie_name: String,
29    auth_cookie_value: String,
30    jar: CookieJar,
31    input: LoginInput,
32) -> impl IntoResponse {
33    if auth.0 == input.password {
34        let mut cookie = Cookie::new(auth_cookie_name, auth_cookie_value);
35
36        cookie.set_http_only(true);
37        cookie.set_same_site(Some(SameSite::Lax));
38
39        return (jar.add(cookie), Redirect::to("/")).into_response();
40    }
41
42    let content = html! {
43        div class="alert alert-danger" { "The password is invalid" }
44        div class="button-container" {
45            a href="/login" class="btn btn-primary setup-btn" { "Return to Login" }
46        }
47    };
48
49    Html(login_layout("Login Failed", content).into_string()).into_response()
50}