mcaptcha/pages/panel/
mod.rs1use actix_identity::Identity;
7use actix_web::{HttpResponse, Responder};
8use sailfish::TemplateOnce;
9
10mod notifications;
11mod settings;
12pub mod sitekey;
13mod utils;
14
15use db_core::Captcha;
16
17use crate::errors::PageResult;
18use crate::AppData;
19
20#[derive(TemplateOnce, Clone)]
21#[template(path = "panel/index.html")]
22pub struct IndexPage {
23 sitekeys: Vec<Captcha>,
24}
25
26impl IndexPage {
27 fn new(sitekeys: Vec<Captcha>) -> Self {
28 IndexPage { sitekeys }
29 }
30}
31
32const PAGE: &str = "Dashboard";
33
34#[my_codegen::get(
35 path = "crate::PAGES.panel.home",
36 wrap = "crate::pages::get_middleware()"
37)]
38async fn panel(data: AppData, id: Identity) -> PageResult<impl Responder> {
39 let username = id.identity().unwrap();
40 let sitekeys = data.db.get_all_user_captchas(&username).await?;
41 let body = IndexPage::new(sitekeys).render_once().unwrap();
42 Ok(HttpResponse::Ok()
43 .content_type("text/html; charset=utf-8")
44 .body(body))
45}
46
47pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
48 cfg.service(panel);
49 settings::services(cfg);
50 sitekey::services(cfg);
51 utils::services(cfg);
52 cfg.service(notifications::notifications);
53}
54
55pub mod routes {
56 use super::settings::routes::Settings;
57 use super::sitekey::routes::Sitekey;
58 use super::utils::routes::Utils;
59
60 pub struct Panel {
61 pub home: &'static str,
62 pub sitekey: Sitekey,
63 pub notifications: &'static str,
64 pub settings: Settings,
65 pub utils: Utils,
66 }
67
68 impl Panel {
69 pub const fn new() -> Self {
70 Panel {
71 home: "/",
72 sitekey: Sitekey::new(),
73 notifications: "/notifications",
74 settings: Settings::new(),
75 utils: Utils::new(),
76 }
77 }
78
79 pub const fn get_sitemap() -> [&'static str; 6] {
80 const PANEL: Panel = Panel::new();
81 const S: [&str; 2] = Sitekey::get_sitemap();
82
83 [
84 PANEL.home,
85 PANEL.notifications,
86 S[0],
87 S[1],
88 Settings::get_sitemap()[0],
89 Utils::get_sitemap()[0],
90 ]
91 }
92 }
93}