mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-06-05 21:56:46 +00:00
feat: implement interface to add user's traffic pattern sqlx postgres
This commit is contained in:
parent
2132ab5791
commit
dacdd2cb8e
@ -532,6 +532,35 @@ impl MCDatabase for Database {
|
|||||||
|
|
||||||
Ok(resp.duration)
|
Ok(resp.duration)
|
||||||
}
|
}
|
||||||
|
/// Add traffic configuration
|
||||||
|
async fn add_traffic_pattern(
|
||||||
|
&self,
|
||||||
|
username: &str,
|
||||||
|
captcha_key: &str,
|
||||||
|
pattern: &TrafficPattern,
|
||||||
|
) -> DBResult<()> {
|
||||||
|
sqlx::query!(
|
||||||
|
"INSERT INTO mcaptcha_sitekey_user_provided_avg_traffic (
|
||||||
|
config_id,
|
||||||
|
avg_traffic,
|
||||||
|
peak_sustainable_traffic,
|
||||||
|
broke_my_site_traffic
|
||||||
|
) VALUES (
|
||||||
|
(SELECT config_id FROM mcaptcha_config WHERE key = ($1)
|
||||||
|
AND user_id = (SELECT ID FROM mcaptcha_users WHERE name = $2)
|
||||||
|
), $3, $4, $5)",
|
||||||
|
//payload.avg_traffic,
|
||||||
|
captcha_key,
|
||||||
|
username,
|
||||||
|
pattern.avg_traffic as i32,
|
||||||
|
pattern.peak_sustainable_traffic as i32,
|
||||||
|
pattern.broke_my_site_traffic.as_ref().map(|v| *v as i32),
|
||||||
|
)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(|e| map_row_not_found_err(e, DBError::CaptchaNotFound))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn now_unix_time_stamp() -> i64 {
|
fn now_unix_time_stamp() -> i64 {
|
||||||
|
@ -34,6 +34,13 @@ async fn everyting_works() {
|
|||||||
const CAPTCHA_DESCRIPTION: &str = "postgrescaptchadescription";
|
const CAPTCHA_DESCRIPTION: &str = "postgrescaptchadescription";
|
||||||
const CAPTCHA_DURATION: i32 = 30;
|
const CAPTCHA_DURATION: i32 = 30;
|
||||||
|
|
||||||
|
// easy traffic pattern
|
||||||
|
const TRAFFIC_PATTERN: TrafficPattern = TrafficPattern {
|
||||||
|
avg_traffic: 500,
|
||||||
|
peak_sustainable_traffic: 5_000,
|
||||||
|
broke_my_site_traffic: Some(10_000),
|
||||||
|
};
|
||||||
|
|
||||||
const LEVELS: [Level; 3] = [
|
const LEVELS: [Level; 3] = [
|
||||||
Level {
|
Level {
|
||||||
difficulty_factor: 1,
|
difficulty_factor: 1,
|
||||||
@ -67,5 +74,5 @@ async fn everyting_works() {
|
|||||||
key: CAPTCHA_SECRET,
|
key: CAPTCHA_SECRET,
|
||||||
description: CAPTCHA_DESCRIPTION,
|
description: CAPTCHA_DESCRIPTION,
|
||||||
};
|
};
|
||||||
database_works(&db, &p, &c, &LEVELS).await;
|
database_works(&db, &p, &c, &LEVELS, &TRAFFIC_PATTERN).await;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user