core/bild.db
core/bild.db
This is a binary file and will not be displayed.
+28
-6
core/src/routes.rs
+28
-6
core/src/routes.rs
···
1
pub mod login {
2
use atrium_api::{
3
agent::{AtpAgent, store::MemorySessionStore},
4
types::string::AtIdentifier,
5
};
6
use atrium_xrpc_client::isahc::IsahcClient;
7
-
use axum::{extract::Form, http::StatusCode, response::IntoResponse};
8
use serde::Deserialize;
9
10
pub async fn get() -> String {
···
17
app_password: String,
18
}
19
20
-
pub async fn post(session: tower_sessions::Session, Form(req): Form<Req>) -> impl IntoResponse {
21
let agent = AtpAgent::new(
22
-
IsahcClient::new("https://dummy.example"),
23
MemorySessionStore::default(),
24
);
25
let res = agent.login(req.handle, req.app_password).await.unwrap();
···
31
}
32
33
pub mod index {
34
use atrium_api::agent::{AtpAgent, store::MemorySessionStore};
35
use atrium_xrpc_client::isahc::IsahcClient;
36
37
-
pub async fn get(session: tower_sessions::Session) -> &'static str {
38
match session
39
.get::<atrium_api::agent::Session>("bild_session")
40
.await
···
42
{
43
None => "no session",
44
Some(s) => {
45
let agent = AtpAgent::new(
46
-
IsahcClient::new("https://dummy.example"),
47
MemorySessionStore::default(),
48
);
49
println!("resuming session of {:?} ({:?})", s.handle, s.did);
···
123
let did = sess.did.clone().into();
124
db.conn
125
.call(|c| {
126
-
c.execute("INSERT INTO keys VALUES (?1, ?2)", [did, req.key])?;
127
Ok(())
128
})
129
.await
···
1
pub mod login {
2
+
use crate::AppState;
3
use atrium_api::{
4
agent::{AtpAgent, store::MemorySessionStore},
5
types::string::AtIdentifier,
6
};
7
use atrium_xrpc_client::isahc::IsahcClient;
8
+
use axum::{
9
+
extract::{Form, State},
10
+
http::StatusCode,
11
+
response::IntoResponse,
12
+
};
13
use serde::Deserialize;
14
15
pub async fn get() -> String {
···
22
app_password: String,
23
}
24
25
+
pub async fn post(
26
+
State(state): State<AppState>,
27
+
session: tower_sessions::Session,
28
+
Form(req): Form<Req>,
29
+
) -> impl IntoResponse {
30
+
let did_doc = state.resolve_did_document(&req.handle).await.unwrap();
31
let agent = AtpAgent::new(
32
+
IsahcClient::new(did_doc.get_pds_endpoint().unwrap()),
33
MemorySessionStore::default(),
34
);
35
let res = agent.login(req.handle, req.app_password).await.unwrap();
···
41
}
42
43
pub mod index {
44
+
use crate::AppState;
45
use atrium_api::agent::{AtpAgent, store::MemorySessionStore};
46
+
use atrium_api::types::string::AtIdentifier;
47
use atrium_xrpc_client::isahc::IsahcClient;
48
+
use axum::extract::State;
49
50
+
pub async fn get(
51
+
session: tower_sessions::Session,
52
+
State(state): State<AppState>,
53
+
) -> &'static str {
54
match session
55
.get::<atrium_api::agent::Session>("bild_session")
56
.await
···
58
{
59
None => "no session",
60
Some(s) => {
61
+
let did_doc = state
62
+
.resolve_did_document(&AtIdentifier::Did(s.did.clone()))
63
+
.await
64
+
.unwrap();
65
let agent = AtpAgent::new(
66
+
IsahcClient::new(did_doc.get_pds_endpoint().unwrap()),
67
MemorySessionStore::default(),
68
);
69
println!("resuming session of {:?} ({:?})", s.handle, s.did);
···
143
let did = sess.did.clone().into();
144
db.conn
145
.call(|c| {
146
+
c.execute("INSERT INTO keys (did, key) VALUES (?1, ?2)", [
147
+
did, req.key,
148
+
])?;
149
Ok(())
150
})
151
.await