allow 'deletion' of user

This commit is contained in:
2023-04-28 19:29:20 +02:00
parent c5741e8139
commit 055c330a3e
5 changed files with 36 additions and 6 deletions

View File

@ -32,6 +32,21 @@ async fn resetpw(db: &State<SqlitePool>, _admin: AdminUser, user: i32) -> Flash<
}
}
#[get("/user/<user>/delete")]
async fn delete(db: &State<SqlitePool>, _admin: AdminUser, user: i32) -> Flash<Redirect> {
let user = User::find_by_id(db, user).await;
match user {
Some(user) => {
user.delete(db).await;
Flash::success(
Redirect::to("/admin/user"),
format!("Sucessfully deleted user {}", user.name),
)
}
None => Flash::error(Redirect::to("/admin/user"), "User does not exist"),
}
}
#[derive(FromForm)]
struct UserEditForm {
id: i32,
@ -84,5 +99,5 @@ async fn create(
}
pub fn routes() -> Vec<Route> {
routes![index, resetpw, update, create]
routes![index, resetpw, update, create, delete]
}