use uuid::Uuid; use crate::{ app::App, clock::RequestedAt, name::Name, password::Password, token::{Secret, extract::IdentityCookie}, }; pub fn not_logged_in() -> IdentityCookie { IdentityCookie::new() } pub async fn logged_in( app: &App, credentials: &(Name, Password), now: &RequestedAt, ) -> IdentityCookie { let (name, password) = credentials; let secret = app .tokens() .login(name, password, now) .await .expect("should succeed given known-valid credentials"); IdentityCookie::new().set(secret) } pub fn secret(identity: &IdentityCookie) -> Secret { identity.secret().expect("identity contained a secret") } pub fn fictitious() -> IdentityCookie { let token = Uuid::new_v4().to_string(); IdentityCookie::new().set(token) }