use templates generated from website.git
This commit is contained in:
parent
f7f9785d8b
commit
21c8b35bba
6 changed files with 104 additions and 25 deletions
35
src/app.rs
35
src/app.rs
|
@ -9,6 +9,7 @@ use actix_session::Session;
|
|||
use actix_web::{
|
||||
get,
|
||||
http::header::{ContentType, LOCATION},
|
||||
routes,
|
||||
web::{self, ServiceConfig},
|
||||
HttpResponse, Responder,
|
||||
};
|
||||
|
@ -51,7 +52,7 @@ impl<T: Template> DynTemplate for PhantomData<T> {
|
|||
macro_rules! templates {
|
||||
(
|
||||
$(
|
||||
#[text = $text:literal]
|
||||
#[text = $text:expr]
|
||||
$(#[$meta:meta])*
|
||||
$vis:vis struct $name:ident $fields:tt
|
||||
)*
|
||||
|
@ -76,28 +77,12 @@ pub struct SubscriptionLoggedOutTemplateProviders {
|
|||
}
|
||||
|
||||
templates! {
|
||||
#[text = r#"<head><title>Subscription</title></head>
|
||||
<body>
|
||||
<h1>Register or Sign In:</h1>
|
||||
As an anti-spam measure, you need to register using a 3rd-party account:
|
||||
<ul>
|
||||
{{- for provider in providers -}}
|
||||
<li><a href="{provider.url}">{provider.pretty_name}</a></li>
|
||||
{{- endfor -}}
|
||||
</ul>
|
||||
</body>"#]
|
||||
#[text = include_str!(concat!(env!("OUT_DIR"), "/templates/SubscriptionLoggedOut.txt"))]
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct SubscriptionLoggedOutTemplate {
|
||||
pub providers: Vec<SubscriptionLoggedOutTemplateProviders>,
|
||||
}
|
||||
#[text = r#"<head><title>Subscription</title></head>
|
||||
<body>
|
||||
<p>Signed in as {email}</p>
|
||||
<ul>
|
||||
<li><a href="/subscription/logout">Logout</a></li>
|
||||
<li><b><a href="/subscription/unsubscribe">Unsubscribe and Delete Account</a></b></li>
|
||||
</ul>
|
||||
</body>"#]
|
||||
#[text = include_str!(concat!(env!("OUT_DIR"), "/templates/SubscriptionLoggedIn.txt"))]
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct SubscriptionLoggedInTemplate {
|
||||
pub email: EndUserEmail,
|
||||
|
@ -363,7 +348,10 @@ pub async fn unsubscribe(session: Session, db: web::Data<DbThread>) -> impl Resp
|
|||
resp
|
||||
}
|
||||
|
||||
#[routes]
|
||||
#[get("/subscription")]
|
||||
#[get("/subscription/")]
|
||||
#[get("/subscription/index.html")]
|
||||
pub async fn subscription(
|
||||
config: web::Data<Config>,
|
||||
session: Session,
|
||||
|
@ -391,13 +379,20 @@ pub async fn subscription(
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn page_not_found() -> impl Responder {
|
||||
HttpResponse::NotFound()
|
||||
.content_type(ContentType::html())
|
||||
.body(include_str!(concat!(env!("OUT_DIR"), "/website/404.html")))
|
||||
}
|
||||
|
||||
pub fn all_services(cfg: &mut ServiceConfig) {
|
||||
cfg.service(subscription)
|
||||
.service(login)
|
||||
.service(callback)
|
||||
.service(logout)
|
||||
.service(unsubscribe)
|
||||
.service(email_unsubscribe);
|
||||
.service(email_unsubscribe)
|
||||
.default_service(web::to(page_not_found));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue