You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
782 B
43 lines
782 B
//! Session for each connected user
|
|
use super::*;
|
|
|
|
id_type!(SessionID; "A unique session ID, not bound to a user.");
|
|
|
|
impl SessionID
|
|
{
|
|
/// Generate a random session ID.
|
|
#[inline] fn generate() -> Self
|
|
{
|
|
Self::id_new()
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct Session
|
|
{
|
|
id: SessionID,
|
|
user: user::User,
|
|
}
|
|
|
|
impl Session
|
|
{
|
|
/// Create a new session object
|
|
pub fn create(user: user::User) -> Self
|
|
{
|
|
Self {
|
|
user,
|
|
id: SessionID::generate(),
|
|
}
|
|
}
|
|
/// The randomly generated ID of this session, irrespective of the user of this session.
|
|
#[inline] pub fn session_id(&self) -> &SessionID
|
|
{
|
|
&self.id
|
|
}
|
|
/// The unique user ID of this session
|
|
pub fn user_id(&self) -> user::UserID
|
|
{
|
|
self.user.id_for_session(self)
|
|
}
|
|
}
|