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
use actix_web::{get, web, HttpRequest, HttpResponse, Responder};

use crate::db::AppData;

use super::base;
use askama::Template;

#[derive(Template)]
#[template(path = "homepage.html")]
struct HomeTemplate {
    // required fields (super::base)
    info: String,
    auth_state: bool,
    bundlrs: String,
    guppy: String,
    site_name: String,
    body_embed: String,
}

#[get("/")]
pub async fn home_request(req: HttpRequest, data: web::Data<AppData>) -> impl Responder {
    // verify auth status
    let (set_cookie, _, token_user) = base::check_auth_status(req.clone(), data.clone()).await;

    // ...
    let base = base::get_base_values(token_user.is_some());
    return HttpResponse::Ok()
        .append_header(("Set-Cookie", set_cookie))
        .append_header(("Content-Type", "text/html"))
        .body(
            HomeTemplate {
                // required fields
                info: base.info,
                auth_state: base.auth_state,
                bundlrs: base.bundlrs,
                guppy: base.guppy,
                site_name: base.site_name,
                body_embed: base.body_embed,
            }
            .render()
            .unwrap(),
        );
}