feat: rm gift and port about page to tera

This commit is contained in:
Aravinth Manivannan 2023-01-24 23:26:51 +05:30
parent 9f0d38ab07
commit 67d50a3d80
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
2 changed files with 90 additions and 100 deletions

View file

@ -14,41 +14,68 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
use std::cell::RefCell;
use std::str::FromStr; use std::str::FromStr;
use actix_web::http::header::ContentType;
use actix_web::{web, HttpResponse, Responder}; use actix_web::{web, HttpResponse, Responder};
use my_codegen::get; use tera::Context;
use sailfish::TemplateOnce;
use uuid::Uuid; use uuid::Uuid;
use crate::errors::*; use crate::errors::ServiceError;
use crate::PAGES; use crate::settings::Settings;
use crate::AppData;
#[derive(TemplateOnce)] pub use super::*;
#[template(path = "index.html")]
struct Intro<'a> { pub struct Intro {
uuid: &'a str, ctx: RefCell<Context>,
} }
const PAGE: &str = "Survey"; pub const INTRO: TemplateFile = TemplateFile::new("intro", "index.html");
impl<'a> Intro<'a> { impl CtxError for Intro {
pub fn new(uuid: &'a str) -> Self { fn with_error(&self, e: &ReadableError) -> String {
Self { uuid } self.ctx.borrow_mut().insert(ERROR_KEY, e);
self.render()
} }
} }
#[get(path = "PAGES.panel.campaigns.about")] impl Intro {
pub async fn about(path: web::Path<String>) -> PageResult<impl Responder> { 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<String>,
) -> PageResult<impl Responder, Intro> {
let path = path.into_inner(); let path = path.into_inner();
match Uuid::from_str(&path) { match Uuid::from_str(&path) {
Err(_) => Err(PageError::PageDoesntExist), Err(_) => Err(PageError::new(
Intro::new(&data.settings, None),
ServiceError::CampaignDoesntExist,
)),
Ok(_) => { Ok(_) => {
let page = Intro::new(&path).render_once().unwrap(); let about = Intro::new(&data.settings, Some(&path)).render();
Ok(HttpResponse::Ok() let html = ContentType::html();
.content_type("text/html; charset=utf-8") Ok(HttpResponse::Ok().content_type(html).body(about))
.body(page))
} }
} }
} }
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
cfg.service(about);
}

View file

@ -1,8 +1,10 @@
<. include!("./components/base/top.html"); .> {% extends 'base' %}
{% block body %}
<body class="survey__body"> <body class="survey__body">
<main class="survey__container"> <main class="survey__container">
<h1>mCaptcha benchmark survey</h1> <h1>mCaptcha benchmark survey</h1>
<section> <section>
{% include "error_comp" %}
<h2>Why should I participate</h2> <h2>Why should I participate</h2>
<p> <p>
<a href="https://mcaptcha.org" target="_blank">mCaptcha</a> <a href="https://mcaptcha.org" target="_blank">mCaptcha</a>
@ -22,34 +24,6 @@
<div id="mcaptcha__widget-container" style="width: 304px; height: 78px"></div> <div id="mcaptcha__widget-container" style="width: 304px; height: 78px"></div>
</div> </div>
</section> </section>
<section>
<h2>What do I get?</h2>
<div class="survey__prize-section">
<p>
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 :)
</p>
<a
target="_blank"
class="prize__preview"
href="https://www.amazon.in/JBL-Detachable-Directional-Headphones-Conference/dp/B0948TG7H8"
>
<img
src="<.= crate::assets::HEADSETS.path .>"
alt="<.= crate::assets::HEADSETS.name .>"
class="survey__prize"
/>
<p>
Product details
<img
src="<.= crate::assets::EXTERNAL_LINK.path .>"
alt="<.= crate::assets::EXTERNAL_LINK.name .>"
/>
</p>
</a>
</div>
</section>
<section> <section>
<h2>Privacy policy</h2> <h2>Privacy policy</h2>
@ -63,23 +37,12 @@
<b>No Personally identifying information is collected</b> <b>No Personally identifying information is collected</b>
</section> </section>
<section>
<h2>Winner Announcement</h2>
<p>
The winners will be announed on the organisation website
<a href="https://mcaptcha.org/blog/survey" target="_blank">here</a> on
December 1, 2021. The winning submission IDs will be published and the
winners expected to provide the submission proof to claim their rewards.
</p>
</section>
<a <a
class="link__btn" class="link__btn"
href="<.= crate::PAGES.panel.campaigns.get_bench_route(uuid) .>" href="{{ payload }}"
>Get started</a >Get started</a
> >
</main> </main>
<. include!("./components/footer/index.html"); .>
</body> </body>
<script src="<.= &*crate::GLUE .>./dist/bundle.js"></script> <script src="{{ assets.glue }}"></script>
<. include!("./components/base/bottom.html"); .> {% endblock body %}