Commit dc787fd2 authored by Dominik Hebeler's avatar Dominik Hebeler

Added Prometheus statistic for captcha

parent 515c89c5
......@@ -33,7 +33,7 @@ class HumanVerification extends Controller
}
if ($request->getMethod() == 'POST') {
\App\PrometheusExporter::CaptchaAnswered();
$lockedKey = $user["lockedKey"];
$key = $request->input('captcha');
$key = strtolower($key);
......@@ -42,7 +42,7 @@ class HumanVerification extends Controller
$captcha = Captcha::create("default", true);
$user["lockedKey"] = $captcha["key"];
HumanVerification::saveUser($user);
\App\PrometheusExporter::CaptchaShown();
return view('humanverification.captcha')->with('title', 'Bestätigung notwendig')
->with('uid', $user["uid"])
->with('id', $id)
......@@ -50,6 +50,7 @@ class HumanVerification extends Controller
->with('image', $captcha["img"])
->with('errorMessage', 'Fehler: Falsche Eingabe!');
} else {
\App\PrometheusExporter::CaptchaCorrect();
# If we can unlock the Account of this user we will redirect him to the result page
if ($user !== null && $user["locked"]) {
# The Captcha was correct. We can remove the key from the user
......@@ -67,7 +68,7 @@ class HumanVerification extends Controller
$captcha = Captcha::create("default", true);
$user["lockedKey"] = $captcha["key"];
HumanVerification::saveUser($user);
\App\PrometheusExporter::CaptchaShown();
return view('humanverification.captcha')->with('title', 'Bestätigung notwendig')
->with('uid', $user["uid"])
->with('id', $id)
......
......@@ -102,6 +102,7 @@ class HumanVerification
if ($user["locked"]) {
$captcha = Captcha::create("default", true);
$user["lockedKey"] = $captcha["key"];
\App\PrometheusExporter::CaptchaShown();
return
new Response(
view('humanverification.captcha')
......
<?php
namespace App;
class PrometheusExporter {
public static function CaptchaShown() {
$registry = \Prometheus\CollectorRegistry::getDefault();
$counter = $registry->getOrRegisterCounter('metager', 'captcha_shown', 'counts how often the captcha was shown', []);
$counter->inc();
}
public static function CaptchaCorrect() {
$registry = \Prometheus\CollectorRegistry::getDefault();
$counter = $registry->getOrRegisterCounter('metager', 'captcha_correct', 'counts how often the captcha was solved correctly', []);
$counter->inc();
}
public static function CaptchaAnswered() {
$registry = \Prometheus\CollectorRegistry::getDefault();
$counter = $registry->getOrRegisterCounter('metager', 'captcha_answered', 'counts how often the captcha was answered', []);
$counter->inc();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment