diff options
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] } |