From 277d2bb9e5207d5a170fceeca4cb76fe579ec74e Mon Sep 17 00:00:00 2001 From: realaravinth Date: Thu, 12 May 2022 19:09:25 +0530 Subject: [PATCH] feat: define interface for adding captcha --- db/db-core/src/lib.rs | 10 +++++++++- db/db-core/src/tests.rs | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/db/db-core/src/lib.rs b/db/db-core/src/lib.rs index 75770cf8..04016a12 100644 --- a/db/db-core/src/lib.rs +++ b/db/db-core/src/lib.rs @@ -33,7 +33,7 @@ //! connection from pool use serde::{Deserialize, Serialize}; -use libmcaptcha::defense::Level; +pub use libmcaptcha::defense::Level; pub mod errors; pub mod ops; @@ -136,6 +136,14 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase { /// create new captcha async fn create_captcha(&self, username: &str, p: &CreateCaptcha) -> DBResult<()>; + + /// Add levels to captcha + async fn add_captcha_levels( + &self, + username: &str, + captcha_key: &str, + levels: &[Level], + ) -> DBResult<()>; } #[derive(Clone, Debug, Default, Deserialize, Serialize)] diff --git a/db/db-core/src/tests.rs b/db/db-core/src/tests.rs index 58e92bc8..8a5f7c48 100644 --- a/db/db-core/src/tests.rs +++ b/db/db-core/src/tests.rs @@ -22,6 +22,7 @@ pub async fn database_works<'a, T: MCDatabase>( db: &T, p: &Register<'a>, c: &CreateCaptcha<'a>, + l: &[Level], ) { assert!(db.ping().await, "ping test"); if db.username_exists(p.username).await.unwrap() { @@ -131,4 +132,5 @@ pub async fn database_works<'a, T: MCDatabase>( ); db.create_captcha(&p.username, c).await.unwrap(); + db.add_captcha_levels(p.username, c.key, l).await.unwrap(); }