From 15c655cdd380a9b298a45503984599c96f53dc7d Mon Sep 17 00:00:00 2001 From: Dan <39170265+chillenberger@users.noreply.github.com> Date: Tue, 6 Jun 2023 11:57:57 -0600 Subject: [PATCH 1/2] git user from stored cookie, rename shared state --- pgml-dashboard/src/guards.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/pgml-dashboard/src/guards.rs b/pgml-dashboard/src/guards.rs index c5d1c2479..acfc412d6 100644 --- a/pgml-dashboard/src/guards.rs +++ b/pgml-dashboard/src/guards.rs @@ -6,6 +6,7 @@ use rocket::State; use sqlx::PgPool; use crate::{Clusters, Context}; +use crate::models::User; pub fn default_database_url() -> String { match var("DATABASE_URL") { @@ -46,17 +47,29 @@ impl<'r> FromRequest<'r> for Cluster { None => -1, }; - let shared_state = match request.guard::<&State>().await { + let user_id: i64 = match cookies.get_private("user_id") { + Some(user_id) => match user_id.value().parse::() { + Ok(user_id) => user_id, + Err(_) => -1, + }, + + None => -1, + }; + + let clusters_shared_state = match request.guard::<&State>().await { Outcome::Success(pool) => pool, _ => return Outcome::Forward(()), }; - let pool = shared_state.get(cluster_id); + let pool = clusters_shared_state.get(cluster_id); let context = Context { - user: shared_state.get_context(cluster_id).user, - cluster: shared_state.get_context(cluster_id).cluster, - visible_clusters: shared_state.get_context(cluster_id).visible_clusters, + user: User { + id: user_id, + email: "".to_string(), + }, + cluster: clusters_shared_state.get_context(cluster_id).cluster, + visible_clusters: clusters_shared_state.get_context(cluster_id).visible_clusters, }; Outcome::Success(Cluster { pool, context }) From 974667ea2d5729ba67802c5ed67b9fa3eb37a05c Mon Sep 17 00:00:00 2001 From: Dan <39170265+chillenberger@users.noreply.github.com> Date: Tue, 6 Jun 2023 11:58:44 -0600 Subject: [PATCH 2/2] format --- pgml-dashboard/src/guards.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pgml-dashboard/src/guards.rs b/pgml-dashboard/src/guards.rs index acfc412d6..b3380daab 100644 --- a/pgml-dashboard/src/guards.rs +++ b/pgml-dashboard/src/guards.rs @@ -5,8 +5,8 @@ use rocket::request::{FromRequest, Outcome, Request}; use rocket::State; use sqlx::PgPool; -use crate::{Clusters, Context}; use crate::models::User; +use crate::{Clusters, Context}; pub fn default_database_url() -> String { match var("DATABASE_URL") { @@ -65,11 +65,13 @@ impl<'r> FromRequest<'r> for Cluster { let context = Context { user: User { - id: user_id, + id: user_id, email: "".to_string(), }, cluster: clusters_shared_state.get_context(cluster_id).cluster, - visible_clusters: clusters_shared_state.get_context(cluster_id).visible_clusters, + visible_clusters: clusters_shared_state + .get_context(cluster_id) + .visible_clusters, }; Outcome::Success(Cluster { pool, context }) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy