mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
feat: define interface for adding captcha
This commit is contained in:
@@ -33,7 +33,7 @@
|
|||||||
//! connection from pool
|
//! connection from pool
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use libmcaptcha::defense::Level;
|
pub use libmcaptcha::defense::Level;
|
||||||
|
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
pub mod ops;
|
pub mod ops;
|
||||||
@@ -136,6 +136,14 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
|||||||
|
|
||||||
/// create new captcha
|
/// create new captcha
|
||||||
async fn create_captcha(&self, username: &str, p: &CreateCaptcha) -> DBResult<()>;
|
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)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ pub async fn database_works<'a, T: MCDatabase>(
|
|||||||
db: &T,
|
db: &T,
|
||||||
p: &Register<'a>,
|
p: &Register<'a>,
|
||||||
c: &CreateCaptcha<'a>,
|
c: &CreateCaptcha<'a>,
|
||||||
|
l: &[Level],
|
||||||
) {
|
) {
|
||||||
assert!(db.ping().await, "ping test");
|
assert!(db.ping().await, "ping test");
|
||||||
if db.username_exists(p.username).await.unwrap() {
|
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.create_captcha(&p.username, c).await.unwrap();
|
||||||
|
db.add_captcha_levels(p.username, c.key, l).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user