Adding Dangerzone and deletion of links

closes #9
This commit is contained in:
Dietrich 2021-02-09 08:01:32 +01:00
parent d451a4f05c
commit 5d28707e18
Signed by: dietrich
GPG Key ID: 9F3C20C0F85DF67C
4 changed files with 43 additions and 7 deletions

View File

@ -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)),

View File

@ -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<String>,
) -> Result<HttpResponse, ServerError> {
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/"))
}

View File

@ -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;

View File

@ -15,6 +15,12 @@
<label for="code">Code:</label>
<input type="text" name="code" value="{{link.code}}">
</div>
<input type="submit" value="Speichern">
<div class="actions danger">
<h2>Achtung!</h2>
<h3>Werden schon veröffentlichte Links gelöscht oder editiert sind die Links z.B. aus einem Buch
nicht mehr gültig! UNBEDINGT VERMEIDEN!</h3>
<input type="submit" value="Speichern">
<a class="button" href="/admin/delete/link/{{link.code}}">Delete</a>
</div>
</form>
{% endblock %}