@@ -5,6 +5,7 @@ use rocket::request::{FromRequest, Outcome, Request};
5
5
use rocket:: State ;
6
6
use sqlx:: PgPool ;
7
7
8
+ use crate :: models:: User ;
8
9
use crate :: { Clusters , Context } ;
9
10
10
11
pub fn default_database_url ( ) -> String {
@@ -46,17 +47,31 @@ impl<'r> FromRequest<'r> for Cluster {
46
47
None => -1 ,
47
48
} ;
48
49
49
- let shared_state = match request. guard :: < & State < Clusters > > ( ) . await {
50
+ let user_id: i64 = match cookies. get_private ( "user_id" ) {
51
+ Some ( user_id) => match user_id. value ( ) . parse :: < i64 > ( ) {
52
+ Ok ( user_id) => user_id,
53
+ Err ( _) => -1 ,
54
+ } ,
55
+
56
+ None => -1 ,
57
+ } ;
58
+
59
+ let clusters_shared_state = match request. guard :: < & State < Clusters > > ( ) . await {
50
60
Outcome :: Success ( pool) => pool,
51
61
_ => return Outcome :: Forward ( ( ) ) ,
52
62
} ;
53
63
54
- let pool = shared_state . get ( cluster_id) ;
64
+ let pool = clusters_shared_state . get ( cluster_id) ;
55
65
56
66
let context = Context {
57
- user : shared_state. get_context ( cluster_id) . user ,
58
- cluster : shared_state. get_context ( cluster_id) . cluster ,
59
- visible_clusters : shared_state. get_context ( cluster_id) . visible_clusters ,
67
+ user : User {
68
+ id : user_id,
69
+ email : "" . to_string ( ) ,
70
+ } ,
71
+ cluster : clusters_shared_state. get_context ( cluster_id) . cluster ,
72
+ visible_clusters : clusters_shared_state
73
+ . get_context ( cluster_id)
74
+ . visible_clusters ,
60
75
} ;
61
76
62
77
Outcome :: Success ( Cluster { pool, context } )
0 commit comments