From 253018580a6d31c740a257890f7baf169246775d Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 28 Apr 2023 19:59:07 +0200 Subject: [PATCH] send flash msg to /admin view --- src/rest/admin/user.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) 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")]