From 25161fc8e953c842549c7401ff1784408d9765f7 Mon Sep 17 00:00:00 2001 From: philipp Date: Sun, 18 Aug 2024 21:30:14 +0200 Subject: [PATCH] first draft of sending blog post notifications --- Rocket.toml | 1 + src/tera/mod.rs | 31 +++++++++++++++++++++++++++++++ templates/index.html.tera | 14 ++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/Rocket.toml b/Rocket.toml index b9d5057..9f97381 100644 --- a/Rocket.toml +++ b/Rocket.toml @@ -5,3 +5,4 @@ limits = { file = "10 MiB", data-form = "10 MiB"} smtp_pw = "8kIjlLH79Ky6D3jQ" usage_log_path = "./usage.txt" openweathermap_key = "c8dab8f91b5b815d76e9879cbaecd8d5" +wordpress_key = "KYplHPxd6Gtqjdx4Ruik" diff --git a/src/tera/mod.rs b/src/tera/mod.rs index 27e88dc..982a1b7 100644 --- a/src/tera/mod.rs +++ b/src/tera/mod.rs @@ -118,6 +118,35 @@ fn unauthorized_error(req: &Request) -> Redirect { Redirect::to("/auth") } +#[derive(FromForm, Debug)] +struct NewBlogpostForm<'r> { + article_url: &'r str, + pw: &'r str, +} + +#[post("/", data = "")] +async fn new_blogpost( + db: &State, + blogpost: Form>, + config: &State, +) -> String { + if blogpost.pw == &config.wordpress_key { + let member = Role::find_by_name(&db, "Donau Linz").await.unwrap(); + Notification::create_for_role( + db, + &member, + &format!("auf unserer Website!"), + &format!("Neuer Blogpost"), + Some(blogpost.article_url), + None, + ) + .await; + "ACK".into() + } else { + "WRONG pw".into() + } +} + #[catch(403)] //forbidden fn forbidden_error() -> Flash { Flash::error(Redirect::to("/"), "Keine Berechtigung für diese Aktion. Wenn du der Meinung bist, dass du das machen darfst, melde dich bitte bei it@rudernlinz.at.") @@ -187,6 +216,7 @@ pub struct Config { smtp_pw: String, usage_log_path: String, pub openweathermap_key: String, + wordpress_key: String, } pub fn config(rocket: Rocket) -> Rocket { @@ -194,6 +224,7 @@ pub fn config(rocket: Rocket) -> Rocket { .mount("/", routes![index, steering, impressum]) .mount("/auth", auth::routes()) .mount("/wikiauth", routes![wikiauth]) + .mount("/new-blogpost", routes![new_blogpost]) .mount("/log", log::routes()) .mount("/planned", planned::routes()) .mount("/ergo", ergo::routes()) diff --git a/templates/index.html.tera b/templates/index.html.tera index cca630f..a275d0f 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -33,6 +33,13 @@
{{ notification.message | safe }}
{% endif %} {% endfor %}