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 {
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 {
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 {
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(),
);
}