Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
86.49% |
32 / 37 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @file |
| 5 | * Login action: resend validation email for registered user. |
| 6 | */ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | require_once __DIR__.'/../legacy/login/validate.php'; |
| 11 | |
| 12 | /** |
| 13 | * Action callable: resend validation email (GET device, session, username, lang). |
| 14 | * |
| 15 | * Validates session, checks user exists, sends validation mail via legacy send_validation_mail. |
| 16 | * |
| 17 | * @param string $body Request body (unused). |
| 18 | * @param array<string, mixed> $query Query params: device, session, username, lang. |
| 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 for check. |
| 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 | set_time_limit(0); |
| 26 | ignore_user_abort(true); |
| 27 | |
| 28 | $retval = ApplicationError::Success; |
| 29 | $userid = null; |
| 30 | $device = $query['device'] ?? null; |
| 31 | |
| 32 | if (!$device) { |
| 33 | $logger->error("No device provided on URL. Operation cancelled."); |
| 34 | $retval = ApplicationError::Parameters; |
| 35 | } |
| 36 | |
| 37 | if (success($retval)) { |
| 38 | $session = $query['session'] ?? null; |
| 39 | if (!$session) { |
| 40 | $logger->error("No session provided on URL. Operation cancelled."); |
| 41 | $retval = ApplicationError::Parameters; |
| 42 | } else { |
| 43 | $retval = $sessionService->checkSession($conx, $session, $device, $userid); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | if (success($retval)) { |
| 48 | $email = $query['username'] ?? null; |
| 49 | if (!$email) { |
| 50 | $logger->error("Mandatory parameter 'username' not provided on URL. Operation cancelled."); |
| 51 | $retval = ApplicationError::Parameters; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | if (success($retval)) { |
| 56 | $results = []; |
| 57 | $res = $conx->global->query('USER', ['email' => $email], $results); |
| 58 | if ($res && count($results) === 0) { |
| 59 | $logger->error("No user found for email '".$email."'."); |
| 60 | $retval = ApplicationError::NotFound; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | $result = ["errorcode" => $retval]; |
| 65 | $output = json_encode($result); |
| 66 | |
| 67 | if (success($retval)) { |
| 68 | $lang = $query['lang'] ?? 'EN'; |
| 69 | if (!send_validation_mail($conx, $lang, $email)) { |
| 70 | $retval = ApplicationError::Generic; |
| 71 | $result = ["errorcode" => $retval]; |
| 72 | $output = json_encode($result); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | return ['output' => $output, 'contentType' => 'application/json; charset=utf-8']; |
| 77 | }; |