pub struct UserStore { /* private fields */ }Expand description
In-memory user + session store backed by a JSON file.
Implementations§
Source§impl UserStore
impl UserStore
Sourcepub fn new(file_path: PathBuf, config: SessionConfig) -> Self
pub fn new(file_path: PathBuf, config: SessionConfig) -> Self
Load from JSON file or create empty store.
Sourcepub fn save(&self) -> Result<(), String>
pub fn save(&self) -> Result<(), String>
Save users to JSON file (atomic write via temp file + rename).
Sourcepub fn create_user(
&mut self,
username: &str,
password: &str,
display_name: &str,
email: &str,
role: &str,
) -> Result<StoredUser, String>
pub fn create_user( &mut self, username: &str, password: &str, display_name: &str, email: &str, role: &str, ) -> Result<StoredUser, String>
Create a new user with argon2 password hashing.
Sourcepub fn verify_password(
&self,
username: &str,
password: &str,
) -> Result<StoredUser, String>
pub fn verify_password( &self, username: &str, password: &str, ) -> Result<StoredUser, String>
Verify a username/password combination. Returns the user on success.
Sourcepub fn create_session(&mut self, user: &StoredUser) -> SessionRecord
pub fn create_session(&mut self, user: &StoredUser) -> SessionRecord
Create a new session for a user. Evicts oldest session if max exceeded.
Sourcepub fn validate_session(&mut self, session_id: &str) -> Option<&SessionRecord>
pub fn validate_session(&mut self, session_id: &str) -> Option<&SessionRecord>
Validate a session: check idle + absolute timeout, update last_activity.
Sourcepub fn needs_renewal(&self, session_id: &str) -> bool
pub fn needs_renewal(&self, session_id: &str) -> bool
Check if a session is within the renewal window (close to expiry).
Sourcepub fn revoke_session(&mut self, session_id: &str) -> bool
pub fn revoke_session(&mut self, session_id: &str) -> bool
Revoke a single session.
Sourcepub fn revoke_all_user_sessions(&mut self, user_id: &str) -> usize
pub fn revoke_all_user_sessions(&mut self, user_id: &str) -> usize
Revoke all sessions for a user.
Sourcepub fn cleanup_expired(&mut self) -> usize
pub fn cleanup_expired(&mut self) -> usize
Remove expired sessions (called periodically).
Sourcepub fn list_users(&self) -> Vec<UserSummary>
pub fn list_users(&self) -> Vec<UserSummary>
List all users (without password hashes).
Sourcepub fn get_user(&self, username: &str) -> Option<&StoredUser>
pub fn get_user(&self, username: &str) -> Option<&StoredUser>
Get a user by username.
Sourcepub fn get_user_by_id(&self, user_id: &str) -> Option<&StoredUser>
pub fn get_user_by_id(&self, user_id: &str) -> Option<&StoredUser>
Get a user by ID.
Sourcepub fn update_user(
&mut self,
user_id: &str,
display_name: Option<&str>,
email: Option<&str>,
role: Option<&str>,
disabled: Option<bool>,
) -> Result<StoredUser, String>
pub fn update_user( &mut self, user_id: &str, display_name: Option<&str>, email: Option<&str>, role: Option<&str>, disabled: Option<bool>, ) -> Result<StoredUser, String>
Update a user’s details (admin operation).
Sourcepub fn change_password(
&mut self,
user_id: &str,
new_password: &str,
) -> Result<(), String>
pub fn change_password( &mut self, user_id: &str, new_password: &str, ) -> Result<(), String>
Change a user’s password.
Sourcepub const fn session_config(&self) -> &SessionConfig
pub const fn session_config(&self) -> &SessionConfig
Get session config (for JWT TTL).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for UserStore
impl RefUnwindSafe for UserStore
impl Send for UserStore
impl Sync for UserStore
impl Unpin for UserStore
impl UnsafeUnpin for UserStore
impl UnwindSafe for UserStore
Blanket Implementations§
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> 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