Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
VerifyUserEmailEndpoint
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 handle
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace Olz\Api\Endpoints;
4
5use Olz\Api\OlzTypedEndpoint;
6use PhpTypeScriptApi\HttpError;
7
8/**
9 * @extends OlzTypedEndpoint<
10 *   ?array{},
11 *   array{
12 *     status: 'OK'|'ERROR',
13 *   }
14 * >
15 */
16class VerifyUserEmailEndpoint extends OlzTypedEndpoint {
17    protected function handle(mixed $input): mixed {
18        $auth_utils = $this->authUtils();
19        $user = $auth_utils->getCurrentUser();
20        if (!$user) {
21            throw new HttpError(401, "Nicht eingeloggt!");
22        }
23
24        $this->emailUtils()->setLogger($this->log());
25        try {
26            $this->emailUtils()->sendEmailVerificationEmail($user);
27        } catch (\Throwable $th) {
28            $this->log()->error("Error verifying email for user (ID:{$user->getId()})", [$th]);
29            return ['status' => 'ERROR'];
30        }
31        $this->entityManager()->flush();
32
33        return [
34            'status' => 'OK',
35        ];
36    }
37}