From de3707983af4d8f7d5979fc0d7d0135d16f63b39 Mon Sep 17 00:00:00 2001 From: Bat Date: Sun, 9 Sep 2018 20:49:24 +0100 Subject: [PATCH] Account deletion Fixes #182 --- src/main.rs | 1 + src/routes/user.rs | 17 ++++++++++++++++- static/css/main.css | 10 ++++++++++ templates/users/edit.html.tera | 10 +++++++++- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4b74a582..932e6e5f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -123,6 +123,7 @@ fn main() { routes::user::edit, routes::user::edit_auth, routes::user::update, + routes::user::delete, routes::user::follow, routes::user::follow_auth, routes::user::activity_details, diff --git a/src/routes/user.rs b/src/routes/user.rs index 7963256a..be61d7ee 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -7,7 +7,7 @@ use atom_syndication::{Entry, FeedBuilder}; use rocket::{ request::LenientForm, response::{Redirect, Flash, Content}, - http::ContentType + http::{ContentType, Cookies} }; use rocket_contrib::Template; use serde_json; @@ -224,6 +224,21 @@ fn update(_name: String, conn: DbConn, user: User, data: LenientForm/delete")] +fn delete(name: String, conn: DbConn, user: User, mut cookies: Cookies) -> Redirect { + let account = User::find_by_fqn(&*conn, name.clone()).unwrap(); + if user.id == account.id { + account.delete(&*conn); + + let cookie = cookies.get_private(AUTH_COOKIE).unwrap(); + cookies.remove_private(cookie); + + Redirect::to(uri!(super::instance::index)) + } else { + Redirect::to(uri!(edit: name = name)) + } +} + #[derive(FromForm, Serialize, Validate)] #[validate(schema(function = "passwords_match", skip_on_field_errors = "false", message = "Passwords are not matching"))] struct NewUserForm { diff --git a/static/css/main.css b/static/css/main.css index 29551e17..e94d312e 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -494,6 +494,16 @@ main .article-meta .tags li a { color: white; } +.button.destructive { + color: #ef767a; + border-color: #ef767a; +} + +.button.destructive:hover { + background: #ef767a99; + color: white; +} + /* Errors */ p.error { diff --git a/templates/users/edit.html.tera b/templates/users/edit.html.tera index a61b195e..980d2ba1 100644 --- a/templates/users/edit.html.tera +++ b/templates/users/edit.html.tera @@ -8,7 +8,7 @@

{{ "Your Profile" | _ }}

- + @@ -21,4 +21,12 @@
+ +

{{ "Danger zone" | _ }}

+

{{ "Be very careful, any action taken here can't be cancelled." | _ }} +{% if not account.is_admin %} +

{{ "Delete your account" | _ }}

+{% else %} +

{{ "Sorry, but as an admin, you can't leave your instance." | _ }}

+{% endif %} {% endblock content %}