From 67d50a3d80876ada14dd3341d676fc50daa02bae Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Tue, 24 Jan 2023 23:26:51 +0530 Subject: [PATCH] feat: rm gift and port about page to tera --- src/pages/panel/campaigns/about.rs | 65 ++++++++++----- templates/index.html | 125 ++++++++++------------------- 2 files changed, 90 insertions(+), 100 deletions(-) diff --git a/src/pages/panel/campaigns/about.rs b/src/pages/panel/campaigns/about.rs index a54966a..3a5baa6 100644 --- a/src/pages/panel/campaigns/about.rs +++ b/src/pages/panel/campaigns/about.rs @@ -14,41 +14,68 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +use std::cell::RefCell; use std::str::FromStr; +use actix_web::http::header::ContentType; use actix_web::{web, HttpResponse, Responder}; -use my_codegen::get; -use sailfish::TemplateOnce; +use tera::Context; use uuid::Uuid; -use crate::errors::*; -use crate::PAGES; +use crate::errors::ServiceError; +use crate::settings::Settings; +use crate::AppData; -#[derive(TemplateOnce)] -#[template(path = "index.html")] -struct Intro<'a> { - uuid: &'a str, +pub use super::*; + +pub struct Intro { + ctx: RefCell, } -const PAGE: &str = "Survey"; +pub const INTRO: TemplateFile = TemplateFile::new("intro", "index.html"); -impl<'a> Intro<'a> { - pub fn new(uuid: &'a str) -> Self { - Self { uuid } +impl CtxError for Intro { + fn with_error(&self, e: &ReadableError) -> String { + self.ctx.borrow_mut().insert(ERROR_KEY, e); + self.render() } } -#[get(path = "PAGES.panel.campaigns.about")] -pub async fn about(path: web::Path) -> PageResult { +impl Intro { + pub fn new(settings: &Settings, payload: Option<&str>) -> Self { + let ctx = RefCell::new(context(settings, "Login")); + if let Some(uuid) = payload { + let payload = crate::PAGES.panel.campaigns.get_bench_route(uuid); + ctx.borrow_mut().insert(PAYLOAD_KEY, &payload); + } + Self { ctx } + } + + pub fn render(&self) -> String { + TEMPLATES.render(INTRO.name, &self.ctx.borrow()).unwrap() + } +} + +#[actix_web_codegen_const_routes::get(path = "PAGES.panel.campaigns.about")] +pub async fn about( + data: AppData, + path: web::Path, +) -> PageResult { let path = path.into_inner(); match Uuid::from_str(&path) { - Err(_) => Err(PageError::PageDoesntExist), + Err(_) => Err(PageError::new( + Intro::new(&data.settings, None), + ServiceError::CampaignDoesntExist, + )), Ok(_) => { - let page = Intro::new(&path).render_once().unwrap(); - Ok(HttpResponse::Ok() - .content_type("text/html; charset=utf-8") - .body(page)) + let about = Intro::new(&data.settings, Some(&path)).render(); + let html = ContentType::html(); + Ok(HttpResponse::Ok().content_type(html).body(about)) } } } + +pub fn services(cfg: &mut actix_web::web::ServiceConfig) { + cfg.service(about); +} diff --git a/templates/index.html b/templates/index.html index 32d2932..196fbd9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,85 +1,48 @@ -<. include!("./components/base/top.html"); .> - -
-

mCaptcha benchmark survey

-
-

Why should I participate

-

- mCaptcha - is a cutting edge, privacy respecting CAPTCHA system. We use a - proof of work - based mechanism to defend against - denial-of-service attacks - which allows for a non-interactive CAPTCHA experience. We require - performance metrics measured on a wide range of devices to fine-tune the - system for optimal user experience, see for yourself! -

-
-
-
-
-
-

What do I get?

-
+{% extends 'base' %} +{% block body %} + +
+

mCaptcha benchmark survey

+
+ {% include "error_comp" %} +

Why should I participate

- We are conducting a lucky draw. Two lucky participants, selected at - random, will win a pair of JBL headsets worth over ₹2,500! Also, you - will be helping us make the internet healthier :) + mCaptcha + is a cutting edge, privacy respecting CAPTCHA system. We use a + proof of work + based mechanism to defend against + denial-of-service attacks + which allows for a non-interactive CAPTCHA experience. We require + performance metrics measured on a wide range of devices to fine-tune the + system for optimal user experience, see for yourself!

- - <.= crate::assets::HEADSETS.name .> -

- Product details - <.= crate::assets::EXTERNAL_LINK.name .> -

-
-
-
+
+
+
+ -
-

Privacy policy

-

This survey collects the following information:

-
    -
  • Device name
  • -
  • Operating system
  • -
  • Processor information
  • -
  • Benchmark results
  • -
- No Personally identifying information is collected -
+
+

Privacy policy

+

This survey collects the following information:

+
    +
  • Device name
  • +
  • Operating system
  • +
  • Processor information
  • +
  • Benchmark results
  • +
+ No Personally identifying information is collected +
-
-

Winner Announcement

-

- The winners will be announed on the organisation website - here on - December 1, 2021. The winning submission IDs will be published and the - winners expected to provide the submission proof to claim their rewards. -

-
- - Get started -
- <. include!("./components/footer/index.html"); .> - - -<. include!("./components/base/bottom.html"); .> + Get started + + + +{% endblock body %}