Improved SessionService.
This commit is contained in:
1 parent
1b94784c7f
commit
f2c6c8d65c
2 files changed
+5
-14
No files matched your search
@@ -6,11 +6,11 @@ use cookie::{Cookie, CookieJar, Key};
|
|||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct SessionService {
|
pub struct SessionService<'a> {
|
||||||
key: Key,
|
key: &'a Key,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SessionService {
|
impl SessionService<'_> {
|
||||||
|
|
||||||
pub fn get_key(conn: &mut Connection) -> CustomResult<Key> {
|
pub fn get_key(conn: &mut Connection) -> CustomResult<Key> {
|
||||||
let tx = conn.transaction().map_err(Error::SqlError)?;
|
let tx = conn.transaction().map_err(Error::SqlError)?;
|
||||||
@@ -18,16 +18,7 @@ impl SessionService {
|
|||||||
Ok(Key::derive_from(&secret))
|
Ok(Key::derive_from(&secret))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_conn(conn: &mut Connection) -> CustomResult<SessionService> {
|
pub fn from_key(key: &Key) -> SessionService {
|
||||||
let tx = conn.transaction().map_err(Error::SqlError)?;
|
|
||||||
let secret = LedgerInternal::new().get_cookie_secret(&tx)?;
|
|
||||||
let ret = SessionService {
|
|
||||||
key: Key::derive_from(&secret),
|
|
||||||
};
|
|
||||||
Ok(ret)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_key(key: Key) -> SessionService{
|
|
||||||
SessionService{key}
|
SessionService{key}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ impl ServicesFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_authentication_service(&self) -> Result<SessionService> {
|
pub fn get_authentication_service(&self) -> Result<SessionService> {
|
||||||
Ok(SessionService::from_key(self.cache.session_service_key.clone()))
|
Ok(SessionService::from_key(& self.cache.session_service_key))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_user_service<'a>(
|
pub fn get_user_service<'a>(
|
||||||
|
|||||||
Reference in new issue
Block a user