diff --git a/src/rest/admin/user.rs b/src/rest/admin/user.rs index 2c4960e..dd48715 100644 --- a/src/rest/admin/user.rs +++ b/src/rest/admin/user.rs @@ -2,19 +2,29 @@ use crate::model::user::{AdminUser, User}; use rocket::{ form::Form, get, post, + request::FlashMessage, response::{Flash, Redirect}, routes, FromForm, Route, State, }; -use rocket_dyn_templates::{context, Template}; +use rocket_dyn_templates::{tera::Context, Template}; use sqlx::SqlitePool; #[get("/user")] -async fn index(db: &State, admin: AdminUser) -> Template { +async fn index( + db: &State, + admin: AdminUser, + flash: Option>, +) -> Template { let users = User::all(db).await; - Template::render( - "admin/user/index", - context!(users, loggedin_user: admin.user), - ) + + let mut context = Context::new(); + if let Some(msg) = flash { + context.insert("flash", &msg.into_inner()); + } + context.insert("users", &users); + context.insert("loggedin_user", &admin.user); + + Template::render("admin/user/index", context.into_json()) } #[get("/user//reset-pw")]