pub struct SessionModel { /* private fields */ }Available on
native and crate feature auth only.Expand description
Session model for database storage
Represents a session stored in the database with expiration information.
This model implements the ORM Model trait when the database feature is enabled.
§Example
use reinhardt_auth::sessions::models::SessionModel;
use chrono::Utc;
use serde_json::json;
// Create a new session model
let session = SessionModel::new(
"abc123".to_string(),
json!({"user_id": 42, "authenticated": true}),
3600,
);
assert_eq!(session.session_key(), "abc123");
assert!(session.is_valid());Implementations§
Source§impl SessionModel
impl SessionModel
Sourcepub fn new(
session_key: String,
session_data: Value,
ttl_seconds: i64,
) -> SessionModel
pub fn new( session_key: String, session_data: Value, ttl_seconds: i64, ) -> SessionModel
Create a new session model
§Arguments
session_key- Unique session identifiersession_data- Session data as JSON valuettl_seconds- Time to live in seconds
§Example
use reinhardt_auth::sessions::models::SessionModel;
use serde_json::json;
let session = SessionModel::new(
"session_123".to_string(),
json!({"cart_total": 99.99}),
7200,
);Sourcepub fn with_expire_date(
session_key: String,
session_data: Value,
expire_date: DateTime<Utc>,
) -> SessionModel
pub fn with_expire_date( session_key: String, session_data: Value, expire_date: DateTime<Utc>, ) -> SessionModel
Create a session model with a specific expiration date
§Example
use reinhardt_auth::sessions::models::SessionModel;
use chrono::{Utc, Duration};
use serde_json::json;
let expire_date = Utc::now() + Duration::hours(2);
let session = SessionModel::with_expire_date(
"session_xyz".to_string(),
json!({"preferences": {"theme": "dark"}}),
expire_date,
);Sourcepub fn session_key(&self) -> &str
pub fn session_key(&self) -> &str
Get the session key
§Example
use reinhardt_auth::sessions::models::SessionModel;
use serde_json::json;
let session = SessionModel::new("key_123".to_string(), json!({}), 3600);
assert_eq!(session.session_key(), "key_123");Sourcepub fn session_data(&self) -> &Value
pub fn session_data(&self) -> &Value
Get the session data
§Example
use reinhardt_auth::sessions::models::SessionModel;
use serde_json::json;
let data = json!({"user": "alice"});
let session = SessionModel::new("key".to_string(), data.clone(), 3600);
assert_eq!(session.session_data(), &data);Sourcepub fn expire_date(&self) -> &DateTime<Utc>
pub fn expire_date(&self) -> &DateTime<Utc>
Get the expiration date
§Example
use reinhardt_auth::sessions::models::SessionModel;
use chrono::Utc;
use serde_json::json;
let session = SessionModel::new("key".to_string(), json!({}), 3600);
assert!(session.expire_date() > &Utc::now());Sourcepub fn set_session_data(&mut self, data: Value)
pub fn set_session_data(&mut self, data: Value)
Set the session data
§Example
use reinhardt_auth::sessions::models::SessionModel;
use serde_json::json;
let mut session = SessionModel::new("key".to_string(), json!({}), 3600);
session.set_session_data(json!({"updated": true}));
assert_eq!(session.session_data()["updated"], true);Sourcepub fn set_expire_date(&mut self, expire_date: DateTime<Utc>)
pub fn set_expire_date(&mut self, expire_date: DateTime<Utc>)
Set the expiration date
§Example
use reinhardt_auth::sessions::models::SessionModel;
use chrono::{Utc, Duration};
use serde_json::json;
let mut session = SessionModel::new("key".to_string(), json!({}), 3600);
let new_expire = Utc::now() + Duration::hours(24);
session.set_expire_date(new_expire);Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Check if the session is still valid (not expired)
§Example
use reinhardt_auth::sessions::models::SessionModel;
use serde_json::json;
let session = SessionModel::new("key".to_string(), json!({}), 3600);
assert!(session.is_valid());
let expired = SessionModel::new("old".to_string(), json!({}), -100);
assert!(!expired.is_valid());Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if the session has expired
§Example
use reinhardt_auth::sessions::models::SessionModel;
use serde_json::json;
let session = SessionModel::new("key".to_string(), json!({}), 3600);
assert!(!session.is_expired());
let expired = SessionModel::new("old".to_string(), json!({}), -100);
assert!(expired.is_expired());Sourcepub fn extend(&mut self, seconds: i64)
pub fn extend(&mut self, seconds: i64)
Extend the session expiration by the given number of seconds
§Example
use reinhardt_auth::sessions::models::SessionModel;
use chrono::Utc;
use serde_json::json;
let mut session = SessionModel::new("key".to_string(), json!({}), 3600);
let old_expire = *session.expire_date();
session.extend(1800);
assert!(session.expire_date() > &old_expire);Sourcepub fn refresh(&mut self, ttl_seconds: i64)
pub fn refresh(&mut self, ttl_seconds: i64)
Refresh the session with a new TTL from now
§Example
use reinhardt_auth::sessions::models::SessionModel;
use chrono::Utc;
use serde_json::json;
let mut session = SessionModel::new("key".to_string(), json!({}), 3600);
session.refresh(7200);
// New expiration should be approximately 7200 seconds from now
let expected = Utc::now() + chrono::Duration::seconds(7200);
assert!(session.expire_date().signed_duration_since(expected).num_seconds().abs() < 2);Trait Implementations§
Source§impl Clone for SessionModel
impl Clone for SessionModel
Source§fn clone(&self) -> SessionModel
fn clone(&self) -> SessionModel
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SessionModel
impl Debug for SessionModel
Source§impl<'de> Deserialize<'de> for SessionModel
impl<'de> Deserialize<'de> for SessionModel
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<SessionModel, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<SessionModel, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Model for SessionModel
Available on crate feature database only.
impl Model for SessionModel
Available on crate feature
database only.Source§type PrimaryKey = String
type PrimaryKey = String
The primary key type
Source§type Fields = SessionModelFields
type Fields = SessionModelFields
Type-safe field selector Read more
Source§fn table_name() -> &'static str
fn table_name() -> &'static str
Get the table name
Source§fn new_fields() -> <SessionModel as Model>::Fields
fn new_fields() -> <SessionModel as Model>::Fields
Create a new field selector instance Read more
Source§fn primary_key_field() -> &'static str
fn primary_key_field() -> &'static str
Get the primary key field name
Source§fn primary_key(&self) -> Option<<SessionModel as Model>::PrimaryKey>
fn primary_key(&self) -> Option<<SessionModel as Model>::PrimaryKey>
Get the primary key value Read more
Source§fn set_primary_key(&mut self, value: <SessionModel as Model>::PrimaryKey)
fn set_primary_key(&mut self, value: <SessionModel as Model>::PrimaryKey)
Set the primary key value
Source§fn composite_primary_key() -> Option<CompositePrimaryKey>
fn composite_primary_key() -> Option<CompositePrimaryKey>
Get composite primary key definition if this model uses composite PK Read more
Source§fn get_composite_pk_values(&self) -> HashMap<String, PkValue>
fn get_composite_pk_values(&self) -> HashMap<String, PkValue>
Get composite primary key values for this instance Read more
Source§fn relationship_metadata() -> Vec<RelationInfo>
fn relationship_metadata() -> Vec<RelationInfo>
Get relationship metadata for inspection Read more
Source§fn constraint_metadata() -> Vec<ConstraintInfo>
fn constraint_metadata() -> Vec<ConstraintInfo>
Get constraint metadata for inspection Read more
Source§fn objects() -> Self::Objectswhere
Self: Sized,
fn objects() -> Self::Objectswhere
Self: Sized,
Django-style objects manager accessor Read more
Source§impl Serialize for SessionModel
impl Serialize for SessionModel
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl Freeze for SessionModel
impl RefUnwindSafe for SessionModel
impl Send for SessionModel
impl Sync for SessionModel
impl Unpin for SessionModel
impl UnsafeUnpin for SessionModel
impl UnwindSafe for SessionModel
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
Causes
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
Causes
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
Causes
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
Causes
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
Causes
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
Causes
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
Causes
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
Causes
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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> ⓘ
Converts
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> ⓘ
Converts
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 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>
Wrap the input message
T in a tonic::RequestSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = Infallible
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
Creates a shared type from an unshared type.
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Pipes by value. This is generally the method you want to use. Read more
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
Borrows
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
Mutably borrows
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
Borrows
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
Mutably borrows
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
Borrows
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<E> ServerFnErrorAssertions<E> for Ewhere
E: Debug,
impl<E> ServerFnErrorAssertions<E> for Ewhere
E: Debug,
Source§fn should_contain_message(&self, expected: &str)where
E: Display,
fn should_contain_message(&self, expected: &str)where
E: Display,
Assert that the error message contains the specified text.
Source§fn should_have_message(&self, expected: &str)where
E: Display,
fn should_have_message(&self, expected: &str)where
E: Display,
Assert that the error message matches exactly.
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Immutable access to the
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
Mutable access to the
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
Immutable access to the
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
Mutable access to the
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Immutable access to the
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Mutable access to the
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
Calls
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
Calls
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
Calls
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
Calls
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
Calls
.tap_deref() only in debug builds, and is erased in release
builds.