Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
MetaGer
Commits
dc787fd2
Commit
dc787fd2
authored
May 05, 2020
by
Dominik Hebeler
Browse files
Added Prometheus statistic for captcha
parent
515c89c5
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/Http/Controllers/HumanVerification.php
View file @
dc787fd2
...
...
@@ -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
)
...
...
app/Http/Middleware/HumanVerification.php
View file @
dc787fd2
...
...
@@ -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'
)
...
...
app/PrometheusExporter.php
0 → 100644
View file @
dc787fd2
<?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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment