#
mcaptcha/pages/panel/sitekey/
add.rs

    1// Copyright (C) 2022  Aravinth Manivannan <realaravinth@batsense.net>
    2// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
    3//
    4// SPDX-License-Identifier: AGPL-3.0-or-later
    5
    6use actix_web::{HttpResponse, Responder};
    7use lazy_static::lazy_static;
    8use sailfish::TemplateOnce;
    9
    10const PAGE: &str = "Add Sitekey";
    11
    12lazy_static! {
    13    static ref ADVANCE_INDEX: String =
    14        AdvanceIndexPage::default().render_once().unwrap();
    15    static ref EASY_INDEX: String = EasyIndexPage::default().render_once().unwrap();
    16}
    17
    18#[derive(TemplateOnce, Clone)]
    19#[template(path = "panel/sitekey/add/advance/index.html")]
    20pub struct AdvanceIndexPage<'a> {
    21    pub levels: usize,
    22    pub form_title: &'a str,
    23    pub form_description: &'a str,
    24    pub form_duration: usize,
    25}
    26
    27impl<'a> Default for AdvanceIndexPage<'a> {
    28    fn default() -> Self {
    29        Self {
    30            levels: 1,
    31            form_description: "",
    32            form_title: PAGE,
    33            form_duration: 30,
    34        }
    35    }
    36}
    37
    38#[my_codegen::get(
    39    path = "crate::PAGES.panel.sitekey.add_advance",
    40    wrap = "crate::pages::get_middleware()"
    41)]
    42pub async fn advance() -> impl Responder {
    43    HttpResponse::Ok()
    44        .content_type("text/html; charset=utf-8")
    45        .body(&**ADVANCE_INDEX)
    46}
    47
    48#[derive(TemplateOnce, Clone)]
    49#[template(path = "panel/sitekey/add/novice/index.html")]
    50pub struct EasyIndexPage<'a> {
    51    pub form_description: &'a str,
    52    pub form_title: &'a str,
    53    pub peak_sustainable_traffic: Option<usize>,
    54    pub avg_traffic: Option<usize>,
    55    pub broke_my_site_traffic: Option<usize>,
    56}
    57
    58impl<'a> Default for EasyIndexPage<'a> {
    59    fn default() -> Self {
    60        Self {
    61            form_description: "",
    62            peak_sustainable_traffic: None,
    63            avg_traffic: None,
    64            broke_my_site_traffic: None,
    65            form_title: PAGE,
    66        }
    67    }
    68}
    69
    70#[my_codegen::get(
    71    path = "crate::PAGES.panel.sitekey.add_easy",
    72    wrap = "crate::pages::get_middleware()"
    73)]
    74pub async fn easy() -> impl Responder {
    75    HttpResponse::Ok()
    76        .content_type("text/html; charset=utf-8")
    77        .body(&**EASY_INDEX)
    78}