From ccc9b6abb66ebda0b91b4e21f8ec2fb2e87390f7 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 27 Dec 2023 18:33:06 +0100 Subject: add a --dev mode --- src/login/demo_provider.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++ src/login/mod.rs | 1 + 2 files changed, 49 insertions(+) create mode 100644 src/login/demo_provider.rs (limited to 'src/login') diff --git a/src/login/demo_provider.rs b/src/login/demo_provider.rs new file mode 100644 index 0000000..0efb37c --- /dev/null +++ b/src/login/demo_provider.rs @@ -0,0 +1,48 @@ +use crate::login::*; +use crate::storage::*; + +pub struct DemoLoginProvider{ + keys: CryptoKeys, + in_memory_store: in_memory::MemDb, +} + +impl DemoLoginProvider { + pub fn new() -> Self { + Self { + keys: CryptoKeys::init(), + in_memory_store: in_memory::MemDb::new(), + } + } +} + +#[async_trait] +impl LoginProvider for DemoLoginProvider { + async fn login(&self, username: &str, password: &str) -> Result { + tracing::debug!(user=%username, "login"); + + if username != "alice" { + bail!("user does not exist"); + } + + if password != "hunter2" { + bail!("wrong password"); + } + + let storage = self.in_memory_store.builder("alice").await; + let keys = self.keys.clone(); + + Ok(Credentials { storage, keys }) + } + + async fn public_login(&self, email: &str) -> Result { + tracing::debug!(user=%email, "public_login"); + if email != "alice@example.tld" { + bail!("invalid email address"); + } + + let storage = self.in_memory_store.builder("alice").await; + let public_key = self.keys.public.clone(); + + Ok(PublicCredentials { storage, public_key }) + } +} diff --git a/src/login/mod.rs b/src/login/mod.rs index 2926738..6f2ca31 100644 --- a/src/login/mod.rs +++ b/src/login/mod.rs @@ -1,5 +1,6 @@ pub mod ldap_provider; pub mod static_provider; +pub mod demo_provider; use base64::Engine; use std::sync::Arc; -- cgit v1.2.3 From 771c4eac799ec3d9f1e9c41ab1fdc75c1bcb4868 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 29 Dec 2023 17:16:41 +0100 Subject: covering imap commands --- src/login/demo_provider.rs | 13 ++++++++----- src/login/mod.rs | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'src/login') diff --git a/src/login/demo_provider.rs b/src/login/demo_provider.rs index 0efb37c..11c7d54 100644 --- a/src/login/demo_provider.rs +++ b/src/login/demo_provider.rs @@ -1,14 +1,14 @@ use crate::login::*; use crate::storage::*; -pub struct DemoLoginProvider{ +pub struct DemoLoginProvider { keys: CryptoKeys, in_memory_store: in_memory::MemDb, } impl DemoLoginProvider { pub fn new() -> Self { - Self { + Self { keys: CryptoKeys::init(), in_memory_store: in_memory::MemDb::new(), } @@ -26,8 +26,8 @@ impl LoginProvider for DemoLoginProvider { if password != "hunter2" { bail!("wrong password"); - } - + } + let storage = self.in_memory_store.builder("alice").await; let keys = self.keys.clone(); @@ -43,6 +43,9 @@ impl LoginProvider for DemoLoginProvider { let storage = self.in_memory_store.builder("alice").await; let public_key = self.keys.public.clone(); - Ok(PublicCredentials { storage, public_key }) + Ok(PublicCredentials { + storage, + public_key, + }) } } diff --git a/src/login/mod.rs b/src/login/mod.rs index 6f2ca31..4a1dee1 100644 --- a/src/login/mod.rs +++ b/src/login/mod.rs @@ -1,6 +1,6 @@ +pub mod demo_provider; pub mod ldap_provider; pub mod static_provider; -pub mod demo_provider; use base64::Engine; use std::sync::Arc; -- cgit v1.2.3