mirror of
https://github.com/Xevion/dynamic-preauth.git
synced 2025-12-06 07:14:54 -06:00
Switch cookie id to u32 as well
This commit is contained in:
@@ -41,7 +41,7 @@ const Demo = ({ class: className }: DemoProps) => {
|
|||||||
session.
|
session.
|
||||||
<br />
|
<br />
|
||||||
Your session is{" "}
|
Your session is{" "}
|
||||||
<Emboldened skeletonWidth="0x1234567890ABCDEF" copyable={true}>
|
<Emboldened skeletonWidth="0x12345678" copyable={true}>
|
||||||
{id != null ? toHex(id) : null}
|
{id != null ? toHex(id) : null}
|
||||||
</Emboldened>
|
</Emboldened>
|
||||||
. You have{" "}
|
. You have{" "}
|
||||||
|
|||||||
10
src/main.rs
10
src/main.rs
@@ -29,7 +29,7 @@ async fn session_middleware(req: &mut Request, res: &mut Response, depot: &mut D
|
|||||||
match req.cookie("Session") {
|
match req.cookie("Session") {
|
||||||
Some(cookie) => {
|
Some(cookie) => {
|
||||||
// Check if the session exists
|
// Check if the session exists
|
||||||
match cookie.value().parse::<usize>() {
|
match cookie.value().parse::<u32>() {
|
||||||
Ok(session_id) => {
|
Ok(session_id) => {
|
||||||
let mut store = STORE.lock().await;
|
let mut store = STORE.lock().await;
|
||||||
if !store.sessions.contains_key(&session_id) {
|
if !store.sessions.contains_key(&session_id) {
|
||||||
@@ -75,7 +75,7 @@ async fn connect(req: &mut Request, res: &mut Response, depot: &Depot) -> Result
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_socket(session_id: usize, websocket: WebSocket) {
|
async fn handle_socket(session_id: u32, websocket: WebSocket) {
|
||||||
// Split the socket into a sender and receive of messages.
|
// Split the socket into a sender and receive of messages.
|
||||||
let (socket_tx, mut socket_rx) = websocket.split();
|
let (socket_tx, mut socket_rx) = websocket.split();
|
||||||
|
|
||||||
@@ -220,14 +220,14 @@ pub async fn get_session(req: &mut Request, res: &mut Response, depot: &mut Depo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Acquires the session id from the request, preferring the depot
|
// Acquires the session id from the request, preferring the depot
|
||||||
fn get_session_id(req: &Request, depot: &Depot) -> Option<usize> {
|
fn get_session_id(req: &Request, depot: &Depot) -> Option<u32> {
|
||||||
if depot.contains_key("session_id") {
|
if depot.contains_key("session_id") {
|
||||||
return Some(*depot.get::<usize>("session_id").unwrap());
|
return Some(*depot.get::<u32>("session_id").unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, just use whatever the Cookie might have
|
// Otherwise, just use whatever the Cookie might have
|
||||||
match req.cookie("Session") {
|
match req.cookie("Session") {
|
||||||
Some(cookie) => match cookie.value().parse::<usize>() {
|
Some(cookie) => match cookie.value().parse::<u32>() {
|
||||||
Ok(id) => Some(id),
|
Ok(id) => Some(id),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::utility::search;
|
|||||||
|
|
||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
pub struct Session {
|
pub struct Session {
|
||||||
pub id: usize,
|
pub id: u32,
|
||||||
pub downloads: Vec<SessionDownload>,
|
pub downloads: Vec<SessionDownload>,
|
||||||
|
|
||||||
pub first_seen: chrono::DateTime<chrono::Utc>,
|
pub first_seen: chrono::DateTime<chrono::Utc>,
|
||||||
@@ -89,7 +89,7 @@ pub struct State<'a> {
|
|||||||
// A map of executables, keyed by their type/platform
|
// A map of executables, keyed by their type/platform
|
||||||
pub executables: HashMap<&'a str, Executable>,
|
pub executables: HashMap<&'a str, Executable>,
|
||||||
// A map of sessions, keyed by their identifier (a random number)
|
// A map of sessions, keyed by their identifier (a random number)
|
||||||
pub sessions: HashMap<usize, Session>,
|
pub sessions: HashMap<u32, Session>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> State<'a> {
|
impl<'a> State<'a> {
|
||||||
@@ -126,9 +126,9 @@ impl<'a> State<'a> {
|
|||||||
self.executables.insert(exe_type, exe);
|
self.executables.insert(exe_type, exe);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn new_session(&mut self, res: &mut Response) -> usize {
|
pub async fn new_session(&mut self, res: &mut Response) -> u32 {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let id: usize = rng.gen();
|
let id: u32 = rng.gen();
|
||||||
|
|
||||||
let now = chrono::Utc::now();
|
let now = chrono::Utc::now();
|
||||||
self.sessions.insert(
|
self.sessions.insert(
|
||||||
|
|||||||
Reference in New Issue
Block a user