aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/forms/Captcha.php
blob: c01b702815e4ce46b12b566ecaa4377c92a29ba7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php

namespace Studip\Forms;

use CaptchaChallenge;

/**
 * The Text class represents a part of a form that displays a captcha.
 */
class Captcha extends Fieldset
{
    private CaptchaInput $captcha_input;

    public function __construct()
    {
        parent::__construct(_('Bitte bestätigen Sie, dass Sie kein Roboter sind'));

        $captchaInput = new CaptchaInput('altcha', $this->legend, null);
        $captchaInput->setStoringFunction(function (string $payload) {
            $json = CaptchaChallenge::decodePayload($payload);

            CaptchaChallenge::create([
                'salt'   => $json['salt'],
                'number' => $json['number'],
            ]);
        });
        $this->addInput($captchaInput);
    }
}