mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-14 03:25:40 +00:00
captcha stats
This commit is contained in:
@@ -16,11 +16,9 @@
|
||||
*/
|
||||
use actix_identity::Identity;
|
||||
use actix_web::{web, HttpResponse, Responder};
|
||||
use futures::{future::TryFutureExt, try_join};
|
||||
use sailfish::TemplateOnce;
|
||||
|
||||
use crate::errors::*;
|
||||
use crate::stats::fetch::Stats;
|
||||
use crate::AppData;
|
||||
|
||||
const PAGE: &str = "SiteKeys";
|
||||
@@ -79,7 +77,7 @@ pub async fn edit_sitekey(
|
||||
.fetch_one(&data.db)
|
||||
.await?;
|
||||
|
||||
let levels_fut = sqlx::query_as!(
|
||||
let levels = sqlx::query_as!(
|
||||
Level,
|
||||
"SELECT
|
||||
difficulty_factor, visitor_threshold
|
||||
@@ -89,9 +87,7 @@ pub async fn edit_sitekey(
|
||||
&config.config_id
|
||||
)
|
||||
.fetch_all(&data.db)
|
||||
.err_into();
|
||||
|
||||
let (_stats, levels) = try_join!(Stats::new(&key, &data.db), levels_fut)?;
|
||||
.await?;
|
||||
|
||||
let body = IndexPage::new(config, levels, key).render_once().unwrap();
|
||||
Ok(HttpResponse::Ok()
|
||||
|
||||
@@ -45,15 +45,22 @@ struct IndexPage {
|
||||
name: String,
|
||||
key: String,
|
||||
levels: Vec<Level>,
|
||||
stats: Stats,
|
||||
}
|
||||
|
||||
impl IndexPage {
|
||||
fn new(config: McaptchaConfig, levels: Vec<Level>, key: String) -> Self {
|
||||
fn new(
|
||||
stats: Stats,
|
||||
config: McaptchaConfig,
|
||||
levels: Vec<Level>,
|
||||
key: String,
|
||||
) -> Self {
|
||||
IndexPage {
|
||||
duration: config.duration as u32,
|
||||
name: config.name,
|
||||
levels,
|
||||
key,
|
||||
stats,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,9 +98,11 @@ pub async fn view_sitekey(
|
||||
.fetch_all(&data.db)
|
||||
.err_into();
|
||||
|
||||
let (_stats, levels) = try_join!(Stats::new(&key, &data.db), levels_fut)?;
|
||||
let (stats, levels) = try_join!(Stats::new(&username, &key, &data.db), levels_fut)?;
|
||||
|
||||
let body = IndexPage::new(config, levels, key).render_once().unwrap();
|
||||
let body = IndexPage::new(stats, config, levels, key)
|
||||
.render_once()
|
||||
.unwrap();
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(body))
|
||||
|
||||
Reference in New Issue
Block a user