Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
VerifyUserEmailEndpoint
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 1
 handle
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
12
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}