pub struct RiSessionManager { /* private fields */ }Expand description
Session manager for handling user sessions.
This struct manages session creation, validation, and cleanup. It limits the number of sessions per user and automatically cleans up expired sessions.
Implementations§
Source§impl RiSessionManager
impl RiSessionManager
Sourcepub async fn create_session(
&self,
user_id: String,
ip_address: Option<String>,
user_agent: Option<String>,
) -> RiResult<String>
pub async fn create_session( &self, user_id: String, ip_address: Option<String>, user_agent: Option<String>, ) -> RiResult<String>
Creates a new session for a user.
§Parameters
user_id: ID of the user to create the session forip_address: Optional client IP addressuser_agent: Optional client user agent
§Returns
The ID of the newly created session
§Notes
- If the user has reached the maximum number of sessions, the oldest session is removed
- Session ID is generated using UUID v4 for security
Sourcepub async fn validate_session_security(
&self,
session_id: &str,
current_ip: Option<&str>,
current_user_agent: Option<&str>,
) -> RiResult<bool>
pub async fn validate_session_security( &self, session_id: &str, current_ip: Option<&str>, current_user_agent: Option<&str>, ) -> RiResult<bool>
Validates session security by checking IP and User-Agent.
§Security
This method helps prevent session hijacking by verifying that the client’s IP address and User-Agent match the original values.
§Parameters
session_id: ID of the session to validatecurrent_ip: Current client IP addresscurrent_user_agent: Current client User-Agent
§Returns
true if the session is valid, false if there’s a mismatch
Sourcepub async fn regenerate_session_id(
&self,
old_session_id: &str,
) -> RiResult<Option<String>>
pub async fn regenerate_session_id( &self, old_session_id: &str, ) -> RiResult<Option<String>>
Regenerates a session ID to prevent session fixation attacks.
§Security
This method should be called after successful authentication to prevent session fixation attacks. It creates a new session ID while preserving the session data.
§Parameters
old_session_id: The current session ID
§Returns
The new session ID, or None if the old session doesn’t exist
Sourcepub async fn update_session(
&self,
session_id: &str,
data: FxHashMap<String, String>,
) -> RiResult<bool>
pub async fn update_session( &self, session_id: &str, data: FxHashMap<String, String>, ) -> RiResult<bool>
Updates a session’s data.
§Parameters
session_id: ID of the session to updatedata: HashMap of key-value pairs to update in the session
§Returns
true if the session was updated successfully, false if the session doesn’t exist or is expired
§Notes
- The session’s last accessed time is updated when modified
Sourcepub async fn extend_session(&self, session_id: &str) -> RiResult<bool>
pub async fn extend_session(&self, session_id: &str) -> RiResult<bool>
Sourcepub async fn destroy_session(&self, session_id: &str) -> RiResult<bool>
pub async fn destroy_session(&self, session_id: &str) -> RiResult<bool>
Sourcepub async fn destroy_user_sessions(&self, user_id: &str) -> RiResult<usize>
pub async fn destroy_user_sessions(&self, user_id: &str) -> RiResult<usize>
Sourcepub async fn cleanup_expired(&self) -> RiResult<usize>
pub async fn cleanup_expired(&self) -> RiResult<usize>
Sourcepub async fn cleanup_all(&self) -> RiResult<()>
pub async fn cleanup_all(&self) -> RiResult<()>
Cleans up all sessions.
This method removes all sessions, regardless of their expiration status.
Sourcepub fn get_timeout(&self) -> u64
pub fn get_timeout(&self) -> u64
Sourcepub fn set_timeout(&mut self, timeout_secs: u64)
pub fn set_timeout(&mut self, timeout_secs: u64)
Trait Implementations§
Source§impl<'py> IntoPyObject<'py> for RiSessionManager
impl<'py> IntoPyObject<'py> for RiSessionManager
Source§type Target = RiSessionManager
type Target = RiSessionManager
Source§type Output = Bound<'py, <RiSessionManager as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <RiSessionManager as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PyClass for RiSessionManager
impl PyClass for RiSessionManager
Source§impl PyClassImpl for RiSessionManager
impl PyClassImpl for RiSessionManager
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = c"Session manager for handling user sessions.\n\nThis struct manages session creation, validation, and cleanup. It limits\nthe number of sessions per user and automatically cleans up expired sessions.\x00"
const RAW_DOC: &'static CStr = c"Session manager for handling user sessions.\n\nThis struct manages session creation, validation, and cleanup. It limits\nthe number of sessions per user and automatically cleans up expired sessions.\x00"
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type ThreadChecker = SendablePyClass<RiSessionManager>
type ThreadChecker = SendablePyClass<RiSessionManager>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyClassNewTextSignature for RiSessionManager
impl PyClassNewTextSignature for RiSessionManager
const TEXT_SIGNATURE: &'static str = "(timeout_secs)"
Source§impl PyMethods<RiSessionManager> for PyClassImplCollector<RiSessionManager>
impl PyMethods<RiSessionManager> for PyClassImplCollector<RiSessionManager>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for RiSessionManager
impl PyTypeInfo for RiSessionManager
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
§fn is_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type or a subclass of this type.§fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type.impl DerefToPyAny for RiSessionManager
impl ExtractPyClassWithClone for RiSessionManager
Auto Trait Implementations§
impl Freeze for RiSessionManager
impl !RefUnwindSafe for RiSessionManager
impl Send for RiSessionManager
impl Sync for RiSessionManager
impl Unpin for RiSessionManager
impl UnsafeUnpin for RiSessionManager
impl !UnwindSafe for RiSessionManager
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FitForCBox for T
impl<T> FitForCBox for T
type CBoxWrapped = Box_<T>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.§fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
self into an owned Python object, dropping type information and unbinding it
from the 'py lifetime.§fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
self into a Python object. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<T> ManuallyDropMut for T
impl<T> ManuallyDropMut for T
type Ret = ManuallyDrop<T>
fn manually_drop_mut<'__>(&'__ mut self) -> &'__ mut ManuallyDrop<T>
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
§impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
§const NAME: &'static str = T::NAME
const NAME: &'static str = T::NAME
Use ::classinfo_object() instead and format the type name at runtime. Note that using built-in cast features is often better than manual PyTypeCheck usage.
§fn type_check(object: &Bound<'_, PyAny>) -> bool
fn type_check(object: &Bound<'_, PyAny>) -> bool
§fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
isinstance and issubclass function. Read more