diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-07-31 20:12:07 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-07-31 20:12:07 +0200 |
commit | a1bba63fae68e7e6a680b14b674d9c47dfcf4862 (patch) | |
tree | 6484735d42d923aad111766b6c6a3cf755e92377 /src/controllers | |
parent | 706a887f9b5641d3aa609a0a8b4d3d68b659f653 (diff) | |
download | rocket-blog-a1bba63fae68e7e6a680b14b674d9c47dfcf4862.tar.gz rocket-blog-a1bba63fae68e7e6a680b14b674d9c47dfcf4862.tar.bz2 rocket-blog-a1bba63fae68e7e6a680b14b674d9c47dfcf4862.zip |
Implement deleting users.
Diffstat (limited to 'src/controllers')
-rw-r--r-- | src/controllers/users_controller.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/controllers/users_controller.rs b/src/controllers/users_controller.rs index b2ba308..87a0b16 100644 --- a/src/controllers/users_controller.rs +++ b/src/controllers/users_controller.rs @@ -22,6 +22,20 @@ fn index(flash: Option<rocket::request::FlashMessage>, conn: utils::DbConn) -> u } } +#[get("/<id>/delete")] +fn delete(id: i32, route: &rocket::Route, conn: utils::DbConn) -> Flash<Redirect> { + match ::models::User::delete(id, conn) { + Ok(user) => Flash::success( + Redirect::to(route.base.path()), + format!("User {} was successfully deleted.", user.username) + ), + Err(msg) => Flash::error( + Redirect::to(route.base.path()), + format!("Error deleting user: {}", msg) + ) + } +} + #[derive(BartDisplay)] #[template = "templates/new_user.html"] pub struct NewUserTemplate { @@ -80,5 +94,5 @@ fn create(user: Form<RegisterUserForm>, route: &rocket::Route, conn: utils::DbCo } pub fn routes() -> Vec<rocket::Route> { - routes![index, new, create] + routes![index, new, create, delete] } |