+2
Cargo.lock
+2
Cargo.lock
+2
Cargo.toml
+2
Cargo.toml
-3
migrations_bells_and_whistles/.keep
-3
migrations_bells_and_whistles/.keep
+16
-4
src/xrpc/helpers.rs
+16
-4
src/xrpc/helpers.rs
···
1
use axum::body::{Body, to_bytes};
2
use axum::extract::Request;
3
-
use axum::http::{HeaderMap, Method, StatusCode, Uri};
4
use axum::http::header::CONTENT_TYPE;
5
use axum::response::{IntoResponse, Response};
6
use serde::de::DeserializeOwned;
7
use tracing::error;
8
-
9
-
use crate::AppState;
10
11
/// The result of a proxied call that attempts to parse JSON.
12
pub enum ProxiedResult<T> {
···
125
}
126
}
127
128
-
129
/// Build a JSON error response with the required Content-Type header
130
/// Content-Type: application/json;charset=utf-8
131
/// Body shape: { "error": string, "message": string }
···
148
.body(Body::from(body_str))
149
.map_err(|_| StatusCode::BAD_REQUEST)
150
}
···
1
+
use crate::AppState;
2
use axum::body::{Body, to_bytes};
3
use axum::extract::Request;
4
use axum::http::header::CONTENT_TYPE;
5
+
use axum::http::{HeaderMap, Method, StatusCode, Uri};
6
use axum::response::{IntoResponse, Response};
7
+
use rand::distr::{Alphanumeric, SampleString};
8
use serde::de::DeserializeOwned;
9
+
use sqlx::SqlitePool;
10
+
use sqlx::sqlite::SqliteError;
11
use tracing::error;
12
13
/// The result of a proxied call that attempts to parse JSON.
14
pub enum ProxiedResult<T> {
···
127
}
128
}
129
130
/// Build a JSON error response with the required Content-Type header
131
/// Content-Type: application/json;charset=utf-8
132
/// Body shape: { "error": string, "message": string }
···
149
.body(Body::from(body_str))
150
.map_err(|_| StatusCode::BAD_REQUEST)
151
}
152
+
153
+
pub fn get_random_token() -> String {
154
+
let full_code = Alphanumeric.sample_string(&mut rand::rng(), 10);
155
+
//The PDS implementation creates in lowercase, then converts to uppercase.
156
+
//Just going a head and doing uppercase here.
157
+
let slice_one = &full_code[0..5].to_ascii_uppercase();
158
+
let slice_two = &full_code[5..10].to_ascii_uppercase();
159
+
format!("{}-{}", slice_one, slice_two)
160
+
}
161
+
162
+
pub fn create_two_factor_token(account_db: &SqlitePool, did: String) -> anyhow::Result<String> {}