2024-02-10 11:45:18 +01:00
|
|
|
use secrecy::SecretString;
|
2024-02-10 11:45:38 +01:00
|
|
|
use serde::Deserialize;
|
2024-02-10 12:06:53 +01:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use tokio::sync::Mutex;
|
2024-02-10 11:20:35 +01:00
|
|
|
use tracing::instrument;
|
2024-02-10 11:10:58 +01:00
|
|
|
|
2024-02-10 12:11:36 +01:00
|
|
|
use crate::db::{Database, SqliteDatabase};
|
2024-02-10 11:45:38 +01:00
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
2024-02-10 11:10:58 +01:00
|
|
|
pub struct Password(pub SecretString);
|
2024-02-10 12:30:04 +01:00
|
|
|
impl From<String> for Password {
|
|
|
|
fn from(value: String) -> Self {
|
|
|
|
Self(SecretString::new(value))
|
|
|
|
}
|
|
|
|
}
|
2024-02-10 11:10:58 +01:00
|
|
|
|
2024-02-10 11:45:38 +01:00
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
2024-02-10 11:10:58 +01:00
|
|
|
pub struct UserToken(pub SecretString);
|
2024-02-10 12:30:04 +01:00
|
|
|
impl From<String> for UserToken {
|
|
|
|
fn from(value: String) -> Self {
|
|
|
|
Self(SecretString::new(value))
|
|
|
|
}
|
|
|
|
}
|
2024-02-10 11:10:58 +01:00
|
|
|
|
2024-02-10 11:20:35 +01:00
|
|
|
#[derive(Debug)]
|
2024-02-10 12:11:36 +01:00
|
|
|
pub struct Authenticator<DB: Database> {
|
|
|
|
db: Arc<Mutex<DB>>,
|
2024-02-10 10:51:56 +01:00
|
|
|
}
|
|
|
|
|
2024-02-10 12:11:36 +01:00
|
|
|
impl Authenticator<SqliteDatabase> {
|
2024-02-10 12:06:53 +01:00
|
|
|
pub fn new(db: Arc<Mutex<SqliteDatabase>>) -> Self {
|
|
|
|
Self { db }
|
2024-02-10 10:51:56 +01:00
|
|
|
}
|
|
|
|
|
2024-02-10 11:20:35 +01:00
|
|
|
#[instrument]
|
2024-02-10 12:06:53 +01:00
|
|
|
pub async fn create_user_token(&mut self, username: &str, password: &Password) -> UserToken {
|
2024-02-10 11:11:46 +01:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2024-02-10 11:20:35 +01:00
|
|
|
#[instrument]
|
2024-02-10 12:06:53 +01:00
|
|
|
pub async fn verify_user_token(&self, token: &UserToken) -> bool {
|
2024-02-10 10:51:56 +01:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|