Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3/**
4 * @file
5 * Login action: check if email is available for registration.
6 */
7
8    declare(strict_types=1);
9
10    require_once __DIR__.'/../legacy/login/validate.php';
11
12    /**
13     * Action callable: check if email is available for registration (GET username).
14     *
15     * Uses check_free_email from legacy validate; returns JSON true/false.
16     *
17     * @param string $body Request body (unused).
18     * @param array<string, mixed> $query Query params: username (email).
19     * @param \ConxHelper $conx Connection helper (from LoginService; uses ->global for central DB).
20     * @param \Psr\Log\LoggerInterface $logger Logger (from LoggerFactory).
21     * @param \UppServices\SessionService $sessionService Session service (unused).
22     * @return array{output: string, contentType: string} JSON output and content type.
23     */
24    return function (string $body, array $query, \ConxHelper $conx, \Psr\Log\LoggerInterface $logger, \UppServices\SessionService $sessionService): array {
25        $mail = $query['username'] ?? null;
26        $result = false;
27        
28        if ($mail) {
29            $result = check_free_email($conx, $mail);
30            if (!$result) {
31                $logger->info("Email address '".$mail."' already in use.");
32            }
33        } 
34        else {
35            $logger->error("Missing 'username' parameter in url request");
36        }
37        
38        $output = json_encode($result);
39        return ['output' => $output, 'contentType' => 'application/json; charset=utf-8'];
40    };