captcha stats

This commit is contained in:
realaravinth
2021-07-27 15:28:21 +05:30
parent 9bc11f3518
commit 1d759fcb25
18 changed files with 249 additions and 159 deletions

View File

@@ -66,7 +66,6 @@ pub mod routes {
pub sitekey: Sitekey,
pub notifications: &'static str,
pub settings: Settings,
pub stats: &'static str,
}
impl Panel {
@@ -76,11 +75,10 @@ pub mod routes {
sitekey: Sitekey::new(),
notifications: "/notifications",
settings: Settings::new(),
stats: "/stats",
}
}
pub const fn get_sitemap() -> [&'static str; 6] {
pub const fn get_sitemap() -> [&'static str; 5] {
const PANEL: Panel = Panel::new();
const S: [&str; 2] = Sitekey::get_sitemap();
@@ -90,7 +88,6 @@ pub mod routes {
S[0],
S[1],
Settings::get_sitemap()[0],
PANEL.stats,
]
}
}

View File

@@ -1,19 +1,19 @@
/*
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use actix_identity::Identity;
use actix_web::{HttpResponse, Responder};

View File

@@ -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()

View File

@@ -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))