feat: ✨ one time password
feat: ✨ json web token feat: ✨ mail template
This commit is contained in:
parent
c7863c806a
commit
bb2b70ccac
16 changed files with 536 additions and 9 deletions
15
src/lib.rs
15
src/lib.rs
|
@ -6,9 +6,17 @@ pub mod routing;
|
|||
pub mod server;
|
||||
pub mod utils;
|
||||
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use feature::auth::OneTimePassword;
|
||||
use sqlx::{Pool, Postgres};
|
||||
use tokio::sync::RwLock;
|
||||
use utils::naive_toml_parser;
|
||||
|
||||
pub static SERVER_CONFIG: LazyLock<ServerConfig> = LazyLock::new(ServerConfig::default);
|
||||
pub static ONE_TIME_PASSWORDS: LazyLock<RwLock<Vec<OneTimePassword>>> =
|
||||
LazyLock::new(OneTimePassword::init);
|
||||
|
||||
const DATABASE_CONFIG_FILE_LOCATION: &str = "./configs/database_config.toml";
|
||||
const SERVER_CONFIG_FILE_LOCATION: &str = "./configs/server_config.toml";
|
||||
|
||||
|
@ -43,15 +51,22 @@ impl Default for DatabaseConfig {
|
|||
#[derive(Debug)]
|
||||
pub struct ServerConfig {
|
||||
pub address: String,
|
||||
pub otp_time_limit: usize,
|
||||
pub login_token_time_limit: usize,
|
||||
pub concurrency_limit: usize,
|
||||
}
|
||||
|
||||
impl Default for ServerConfig {
|
||||
fn default() -> Self {
|
||||
let (header, mut server_configs) = naive_toml_parser(SERVER_CONFIG_FILE_LOCATION);
|
||||
let value_or_max = |value: String| value.parse().map_or(usize::MAX, |value| value);
|
||||
|
||||
if header == "[server_config]" {
|
||||
Self {
|
||||
address: server_configs.pop_front().unwrap().parse().unwrap(),
|
||||
otp_time_limit: value_or_max(server_configs.pop_front().unwrap()),
|
||||
login_token_time_limit: value_or_max(server_configs.pop_front().unwrap()),
|
||||
concurrency_limit: value_or_max(server_configs.pop_front().unwrap()),
|
||||
}
|
||||
} else {
|
||||
panic!("Server Config File Must Include [server_config] at the First Line")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue