1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
use uuid::Uuid;
use crate::{
app::App,
clock::RequestedAt,
login::Password,
name::Name,
token::{extract::IdentityCookie, Secret},
};
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 (_, token) = app
.tokens()
.login(name, password, now)
.await
.expect("should succeed given known-valid credentials");
IdentityCookie::new().set(token)
}
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)
}
|