summaryrefslogtreecommitdiff
path: root/src/public/pages.rs
blob: a7789b237bb7b864d95f42020201c45ea71553b2 (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
73
74
75
76
77
78
79
80
81
82
use axum::{
    response::{IntoResponse, Redirect, Response},
    routing::get,
    Router, middleware,
};

use crate::{
    public::console,
    types::{
        extract::{AuthorizedUser, Log, UserAgent, self},
        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")
}

async fn forgot(UserAgent(agent): UserAgent, _: Log) -> Response {
    if agent.starts_with("curl") {
        return super::serve("/404.html").await;
    }

    Redirect::to("https://www.youtube.com/watch?v=dQw4w9WgXcQ").into_response()
}

pub fn router() -> Router {
    Router::new()
        .route("/", get(root))
        .route("/login", get(login))
        .layer(middleware::from_fn(extract::connect))
        .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))
        .route("/forgot", get(forgot))
}