pub struct Guard { /* private fields */ }Expand description
Logging in and out, on top of one session.
Implementations§
Source§impl Guard
impl Guard
pub fn new(session: SessionHandle) -> Self
Sourcepub fn login(&self, user: &impl Authenticatable) -> String
pub fn login(&self, user: &impl Authenticatable) -> String
Log a user in, returning the session’s new id.
The session id is rotated first. See crate::Session::regenerate: a
session id that was known before the login must not still be valid
after it, or an attacker who planted the cookie inherits the login.
Sourcepub fn login_using_id(&self, id: impl Into<String>) -> String
pub fn login_using_id(&self, id: impl Into<String>) -> String
Log in by identifier, for a “log in as” or “remember me” flow that already knows the key without loading the user.
Sourcepub fn logout(&self) -> String
pub fn logout(&self) -> String
Log out: empty the session and rotate its id.
Everything goes, not just the identifier. A cart, a half-filled form, a flashed message — all of it belonged to the person who just left, and on a shared machine the next person must not find any of it.
pub fn check(&self) -> bool
pub fn guest(&self) -> bool
Sourcepub fn remember_intended(&self, path: impl Into<String>)
pub fn remember_intended(&self, path: impl Into<String>)
Remember where the visitor was heading before being sent to log in.
Stored rather than flashed: the visitor sees the login form, submits it, and only then is the destination needed — two requests later, by which time flash data would already be gone.
Sourcepub fn intended(&self, fallback: &str) -> String
pub fn intended(&self, fallback: &str) -> String
Take back that destination, or fallback if there is none.
Consumed on read, so a second login does not bounce the visitor to a page they asked for hours ago.