pub struct Identity { /* private fields */ }Expand description
A handle to the current visitor’s identity.
Extract it in any handler. It is always available: an anonymous visitor
simply has no id. Every method operates on the session, so
the changes are persisted by the session plugin on the way out.
Implementations§
Source§impl Identity
impl Identity
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Whether anyone is logged in.
Sourcepub fn login(&self, id: impl Into<String>)
pub fn login(&self, id: impl Into<String>)
Record id as the logged-in visitor.
The session identifier is rotated first (see Session::rotate), so a
server-side store mints a fresh record rather than promoting one an
attacker may have planted. Session contents other than the identity are
preserved, which is what keeps a pre-login cart or locale across the
boundary. Call logout first if you would rather
start empty.
Sourcepub fn logout(&self)
pub fn logout(&self)
Log the visitor out and drop the whole session.
Everything goes, not just the identity keys: anything put in the session while signed in was put there for a signed-in visitor.
With a client-side store this clears the visitor’s copy but cannot revoke a copy taken beforehand, which stays valid until its signed deadline. Revocation needs server-side state.
Sourcepub fn logged_in_at(&self) -> Option<i64>
pub fn logged_in_at(&self) -> Option<i64>
When the visitor logged in, as Unix seconds.
Sourcepub fn last_seen_at(&self) -> Option<i64>
pub fn last_seen_at(&self) -> Option<i64>
When the visitor was last seen, as Unix seconds.
Only maintained when Identities::visit_deadline is set, and only
written periodically rather than on every request. See that method for
why.