Move session into an extractor minus client listener changes.
This commit is contained in:
parent
bb70cc65e0
commit
4fc050e590
@ -325,7 +325,8 @@ impl Client {
|
|||||||
msg.get_data("doc").unwrap().to_string(),
|
msg.get_data("doc").unwrap().to_string(),
|
||||||
)s
|
)s
|
||||||
*/
|
*/
|
||||||
self.registry.send(&tx_id, initial_msg.reply(MsgType::Document));
|
self.registry
|
||||||
|
.send(&tx_id, initial_msg.reply(MsgType::Document));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ impl MoreThanText {
|
|||||||
let mut msg = Message::new(MsgType::SessionValidate);
|
let mut msg = Message::new(MsgType::SessionValidate);
|
||||||
match session {
|
match session {
|
||||||
Some(id) => msg.add_data("sess_id", id.into()),
|
Some(id) => msg.add_data("sess_id", id.into()),
|
||||||
None => {},
|
None => {}
|
||||||
}
|
}
|
||||||
let rx = self.client_link.send(msg);
|
let rx = self.client_link.send(msg);
|
||||||
let reply = rx.recv().unwrap();
|
let reply = rx.recv().unwrap();
|
||||||
|
30
src/main.rs
30
src/main.rs
@ -4,8 +4,7 @@ use axum::{
|
|||||||
http::request::Parts,
|
http::request::Parts,
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
routing::get,
|
routing::get,
|
||||||
RequestPartsExt,
|
RequestPartsExt, Router,
|
||||||
Router,
|
|
||||||
};
|
};
|
||||||
use axum_extra::extract::cookie::{Cookie, CookieJar};
|
use axum_extra::extract::cookie::{Cookie, CookieJar};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
@ -44,7 +43,16 @@ async fn main() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SessionID;
|
async fn create_app(state: MoreThanText) -> Router {
|
||||||
|
Router::new()
|
||||||
|
.route("/", get(mtt_conn))
|
||||||
|
.layer(CookieManagerLayer::new())
|
||||||
|
.layer(Extension(state.clone()))
|
||||||
|
.with_state(state)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct SessionID(Uuid);
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<S> FromRequestParts<S> for SessionID
|
impl<S> FromRequestParts<S> for SessionID
|
||||||
@ -54,20 +62,22 @@ where
|
|||||||
type Rejection = Infallible;
|
type Rejection = Infallible;
|
||||||
|
|
||||||
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
|
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
|
||||||
let cookies = parts.extract::<Extension<Cookies>>();
|
let Extension(cookies) = parts.extract::<Extension<Cookies>>().await.unwrap();
|
||||||
Ok(Self {})
|
let Extension(mut state) = parts.extract::<Extension<MoreThanText>>().await.unwrap();
|
||||||
|
let sess_id: Option<String> = None;
|
||||||
|
let id = Uuid::nil();
|
||||||
|
//let id = state.validate_session(sess_id);
|
||||||
|
cookies.add(tower_cookies::Cookie::new(SESSION_KEY, id.to_string()));
|
||||||
|
Ok(SessionID(id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_app(state: MoreThanText) -> Router {
|
|
||||||
Router::new().route("/", get(mtt_conn)).with_state(state)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn mtt_conn(
|
async fn mtt_conn(
|
||||||
jar: CookieJar,
|
jar: CookieJar,
|
||||||
sess_id: SessionID,
|
sess_id: SessionID,
|
||||||
state: State<MoreThanText>,
|
state: State<MoreThanText>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
|
/*
|
||||||
let sid = match jar.get(SESSION_KEY) {
|
let sid = match jar.get(SESSION_KEY) {
|
||||||
Some(cookie) => Some(cookie.value().to_string()),
|
Some(cookie) => Some(cookie.value().to_string()),
|
||||||
None => None,
|
None => None,
|
||||||
@ -81,6 +91,8 @@ async fn mtt_conn(
|
|||||||
let cookie = Cookie::build((SESSION_KEY, reply.get_data("sess_id").unwrap().to_string()));
|
let cookie = Cookie::build((SESSION_KEY, reply.get_data("sess_id").unwrap().to_string()));
|
||||||
let cookies = jar.add(cookie);
|
let cookies = jar.add(cookie);
|
||||||
(cookies, reply.get_data("dov").unwrap().to_string())
|
(cookies, reply.get_data("dov").unwrap().to_string())
|
||||||
|
*/
|
||||||
|
("something".to_string(),)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user