|
|
@ -6,7 +6,7 @@ use std::ops::Add; |
|
|
|
use std::time::{Duration, Instant}; |
|
|
|
use std::time::{Duration, Instant}; |
|
|
|
|
|
|
|
|
|
|
|
use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard}; |
|
|
|
use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard}; |
|
|
|
use rand::{rngs::OsRng, Rng}; |
|
|
|
use rand::{rngs::OsRng, Rng, TryRngCore}; |
|
|
|
use rocket::{ |
|
|
|
use rocket::{ |
|
|
|
fairing::{self, Fairing, Info}, |
|
|
|
fairing::{self, Fairing, Info}, |
|
|
|
http::{Cookie, Status}, |
|
|
|
http::{Cookie, Status}, |
|
|
@ -126,7 +126,9 @@ where |
|
|
|
{ |
|
|
|
{ |
|
|
|
type Error = (); |
|
|
|
type Error = (); |
|
|
|
|
|
|
|
|
|
|
|
async fn from_request(request: &'r Request<'_>) -> Outcome<Self, (Status, Self::Error), ()> { |
|
|
|
async fn from_request( |
|
|
|
|
|
|
|
request: &'r Request<'_>, |
|
|
|
|
|
|
|
) -> Outcome<Self, (Status, Self::Error), Status> { |
|
|
|
let store = request.guard::<&State<SessionStore<D>>>().await.unwrap(); |
|
|
|
let store = request.guard::<&State<SessionStore<D>>>().await.unwrap(); |
|
|
|
Outcome::Success(Session { |
|
|
|
Outcome::Success(Session { |
|
|
|
id: request.local_cache(|| { |
|
|
|
id: request.local_cache(|| { |
|
|
@ -177,7 +179,8 @@ where |
|
|
|
// Find a new unique ID - we are still safely inside the write guard
|
|
|
|
// Find a new unique ID - we are still safely inside the write guard
|
|
|
|
let new_id = SessionID(loop { |
|
|
|
let new_id = SessionID(loop { |
|
|
|
let token: String = OsRng |
|
|
|
let token: String = OsRng |
|
|
|
.sample_iter(&rand::distributions::Alphanumeric) |
|
|
|
.unwrap_err() |
|
|
|
|
|
|
|
.sample_iter(&rand::distr::Alphanumeric) |
|
|
|
.take(store.config.cookie_len) |
|
|
|
.take(store.config.cookie_len) |
|
|
|
.map(char::from) |
|
|
|
.map(char::from) |
|
|
|
.collect(); |
|
|
|
.collect(); |
|
|
@ -321,9 +324,9 @@ where |
|
|
|
|
|
|
|
|
|
|
|
if !session.0.is_empty() { |
|
|
|
if !session.0.is_empty() { |
|
|
|
response.adjoin_header( |
|
|
|
response.adjoin_header( |
|
|
|
Cookie::build(self.config.cookie_name.clone(), session.to_string()) |
|
|
|
Cookie::build((self.config.cookie_name.clone(), session.to_string())) |
|
|
|
.path("/") |
|
|
|
.path("/") |
|
|
|
.finish(), |
|
|
|
.build(), |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|