nom-nom-nix-gc/src/models/mod.rs
zimbatm d44dea33c9 xxx
2022-12-25 08:55:14 +01:00

50 lines
1.2 KiB
Rust

use url::Url;
use std::sync::{Arc};
use tokio::sync::{Mutex};
use webauthn_rs::prelude::Uuid;
use webauthn_rs::{Webauthn, WebauthnBuilder};
pub type Db = Arc<Mutex<Database>>;
pub struct Database {
pub users: Vec<User>
}
pub struct User {
pub uuid: Uuid,
pub user_name: String,
pub display_name: String,
pub creation_challenge_response: Option<webauthn_rs::prelude::CreationChallengeResponse>,
}
pub struct AppState {
pub webauthn: Arc<Webauthn>,
pub db: Db
}
impl AppState {
fn new() -> Self {
let rp = "localhost";
let rp_origin = Url::parse("http://localhost:8000").expect("Invalid URL");
let builder = WebauthnBuilder::new(rp, &rp_origin).expect("Invalid configuration");
let builder = builder.rp_name("LocalHost");
let webauthn = Arc::new(builder.build().expect("Invalid configuration"));
let user: User = User {
uuid: Uuid::new_v4(),
user_name: "felix".to_string(),
display_name: "Félix".to_string(),
creation_challenge_response: None,
};
let db: Db = Arc::new(Mutex::new(Database {
users: Vec::from([user])
}));
AppState {
webauthn,
db,
}
}
}