🗝
summary refs log tree commit diff
path: root/src/server/panel.rs
blob: addb0d845726146b40d810b25b6ebe8f048e8c39 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use axum::{extract::State, response::Response, routing::get, Router};
use axum_extra::extract::CookieJar;
use maud::html;
use tap::Pipe;

use crate::server::{store::Store, Nevermind};

use super::{account_auth, render_html, ApiState};

pub fn bind(app: Router<ApiState>) -> Router<ApiState> {
    app.route("/", get(get_panel))
}

#[axum::debug_handler(state = ApiState)]
async fn get_panel(jar: CookieJar, State(store): State<Store>) -> Result<Response, Response> {
    Ok(account_auth(&jar, &store)
        .await
        .prompt_login()?
        .pipe(render_normal_panel))
}

fn render_normal_panel(name: String) -> Response {
    render_html(
        html!(title { "dissociate" }),
        html! {
            p { "currently logged in as " (name) }
            a href="/logout" { button { "log out" } }
        },
    )
}