pub struct SessionUser {
pub id: String,
pub account: String,
pub label: String,
pub is_admin: bool,
pub sequence_number: Option<i64>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}Expand description
User information stored in the session.
This struct represents authenticated user data that is stored in the session and retrieved during authentication checks. It contains essential user identity and permission information needed for the application.
Fields§
§id: StringUnique identifier for the user
account: StringUser account name or login identifier
label: StringDisplay name or label for the user
is_admin: boolWhether the user has administrative privileges
sequence_number: Option<i64>Database-assigned sequence number (primary key), None for users not yet persisted
created_at: DateTime<Utc>When the user account was created
updated_at: DateTime<Utc>When the user account was last updated
Implementations§
Source§impl User
impl User
Sourcepub fn has_admin_privileges(&self) -> bool
pub fn has_admin_privileges(&self) -> bool
Determines if the user has administrative privileges.
A user has admin privileges if:
- They have the
is_adminflag set to true, OR - They are the first user in the system (sequence_number = 1)
This method provides consistent admin privilege checking across the codebase and ensures the first user always has admin access regardless of the is_admin flag.
§Returns
trueif the user has administrative privilegesfalseotherwise
§Examples
use oauth2_passkey::SessionUser as User;
use chrono::Utc;
// Regular admin user
let admin_user = User {
id: "user1".to_string(),
account: "admin@example.com".to_string(),
label: "Admin User".to_string(),
is_admin: true,
sequence_number: Some(5),
created_at: Utc::now(),
updated_at: Utc::now(),
};
assert!(admin_user.has_admin_privileges());
// First user (always admin)
let first_user = User {
id: "user1".to_string(),
account: "first@example.com".to_string(),
label: "First User".to_string(),
is_admin: false,
sequence_number: Some(1),
created_at: Utc::now(),
updated_at: Utc::now(),
};
assert!(first_user.has_admin_privileges());
// Regular user
let regular_user = User {
id: "user1".to_string(),
account: "user@example.com".to_string(),
label: "Regular User".to_string(),
is_admin: false,
sequence_number: Some(2),
created_at: Utc::now(),
updated_at: Utc::now(),
};
assert!(!regular_user.has_admin_privileges());IMPORTANT: This logic must stay in sync with DbUser::has_admin_privileges() and AuthUser::has_admin_privileges() implementations.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for User
impl<'de> Deserialize<'de> for User
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for User
impl RefUnwindSafe for User
impl Send for User
impl Sync for User
impl Unpin for User
impl UnsafeUnpin for User
impl UnwindSafe for User
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
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> 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>
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