summaryrefslogtreecommitdiff
path: root/src/public/pages.rs
blob: 32056b76aaccf3f7aa5d793e1de503759a1f8a5c (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use axum::{
    response::{IntoResponse, Redirect, Response},
    routing::get,
    Router,
};

use crate::{
    public::console,
    types::{
        extract::{AuthorizedUser, Log},
        http::ResponseCode,
    },
};

use super::docs;

async fn root(user: Option<AuthorizedUser>, _: Log) -> Response {
    if user.is_some() {
        Redirect::to("/home").into_response()
    } else {
        Redirect::to("/login").into_response()
    }
}

async fn login(user: Option<AuthorizedUser>, _: Log) -> Response {
    if user.is_some() {
        Redirect::to("/home").into_response()
    } else {
        super::serve("/login.html").await
    }
}

async fn home(_: Log) -> Response {
    super::serve("/home.html").await
}

async fn people(_: Log) -> Response {
    super::serve("/people.html").await
}

async fn profile(_: Log) -> Response {
    super::serve("/profile.html").await
}

async fn console() -> Response {
    console::generate().await
}

async fn admin() -> Response {
    super::serve("/admin.html").await
}

async fn api() -> Response {
    docs::generate().await
}

async fn wordpress(_: Log) -> Response {
    ResponseCode::ImATeapot.text("Hello i am a teapot owo")
}

pub fn router() -> Router {
    Router::new()
        .route("/", get(root))
        .route("/login", get(login))
        .route("/home", get(home))
        .route("/people", get(people))
        .route("/profile", get(profile))
        .route("/console", get(console))
        .route("/wp-admin", get(wordpress))
        .route("/admin", get(admin))
        .route("/docs", get(api))
}