aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/forms/CaptchaInput.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/classes/forms/CaptchaInput.php')
-rw-r--r--lib/classes/forms/CaptchaInput.php38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/classes/forms/CaptchaInput.php b/lib/classes/forms/CaptchaInput.php
new file mode 100644
index 0000000..6476f87
--- /dev/null
+++ b/lib/classes/forms/CaptchaInput.php
@@ -0,0 +1,38 @@
+<?php
+
+namespace Studip\Forms;
+
+use CaptchaChallenge;
+use URLHelper;
+
+/**
+ * The Text class represents a part of a form that displays a captcha.
+ */
+final class CaptchaInput extends Input
+{
+ public function hasValidation(): bool
+ {
+ return true;
+ }
+
+ public function getValidationCallback(): callable
+ {
+ return fn($value) => \CaptchaChallenge::validatePayload($value);
+ }
+
+ public function render(): string
+ {
+ return sprintf(
+ '<captcha-input challenge-url="%s" v-model="%s" auto="onload"></captcha-input>',
+ URLHelper::getLink('dispatch.php/captcha/challenge', [], true),
+ htmlReady($this->name)
+ );
+ }
+
+ public function renderWithCondition(): string
+ {
+ return $this->render();
+ }
+
+
+}