From 5d28707e181bf637f17fb542367afe7eda27599c Mon Sep 17 00:00:00 2001 From: Dietrich Date: Tue, 9 Feb 2021 08:01:32 +0100 Subject: [PATCH] Adding Dangerzone and deletion of links closes #9 --- src/main.rs | 6 ++++++ src/views.rs | 13 +++++++++++++ static/admin.css | 23 +++++++++++++++++------ templates/edit_link.html | 8 +++++++- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6ba6c43..c7f33e3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -151,6 +151,12 @@ async fn main() -> std::io::Result<()> { ), ), ) + .service( + web::scope("/delete").service( + web::scope("/link") + .route("/{redirect_id}", web::get().to(views::process_link_delete)), + ), + ) .service( web::scope("/download") .route("/png/{redirect_id}", web::get().to(views::download_png)), diff --git a/src/views.rs b/src/views.rs index 6abc618..fc1af5b 100644 --- a/src/views.rs +++ b/src/views.rs @@ -446,3 +446,16 @@ pub(crate) async fn process_link_edit( } Ok(redirect_builder("/admin/login/")) } + +pub(crate) async fn process_link_delete( + id: Identity, + link_id: web::Path, +) -> Result { + if let Some(_id) = id.identity() { + use super::schema::links::dsl::{code, links}; + let connection = establish_connection()?; + diesel::delete(links.filter(code.eq(&link_id.0))).execute(&connection)?; + return Ok(redirect_builder("/admin/index/")); + } + Ok(redirect_builder("/admin/login/")) +} diff --git a/static/admin.css b/static/admin.css index 18a9095..579d1f3 100644 --- a/static/admin.css +++ b/static/admin.css @@ -66,17 +66,28 @@ svg { } div.actions { - width: 400px; - height: 400px; + margin-left:5px; display: flex; - flex-direction: column; - justify-content: center; + width:100%; align-items: center; - padding: 30px; + padding: 10px; color: #333; + flex-flow: row wrap; + justify-content: center; } -a.button { +div.danger { + background-color: rgb(235, 127, 77); + font-size: smaller; + border: 2px solid crimson; +} + +div.danger h3 { + width:100%; +} + +a.button, div.actions input { + width: 150px; display:block; padding: 15px; text-align: center; diff --git a/templates/edit_link.html b/templates/edit_link.html index a523b76..ea9b19f 100644 --- a/templates/edit_link.html +++ b/templates/edit_link.html @@ -15,6 +15,12 @@ - +
+

Achtung!

+

Werden schon veröffentlichte Links gelöscht oder editiert sind die Links z.B. aus einem Buch + nicht mehr gültig! UNBEDINGT VERMEIDEN!

+ + Delete +
{% endblock %} \ No newline at end of file