1 | <?php |
2 | |
3 | require_once __DIR__ . "/../lib/php/ejecutaServicio.php"; |
4 | require_once __DIR__ . "/../lib/php/ProblemDetails.php"; |
5 | require_once __DIR__ . "/../lib/php/leeTexto.php"; |
6 | require_once __DIR__ . "/const/CUE.php"; |
7 | require_once __DIR__ . "/const/ROL_IDS.php"; |
8 | require_once __DIR__ . "/modelo/Rol.php"; |
9 | require_once __DIR__ . "/bd/usuarioVerifica.php"; |
10 | require_once __DIR__ . "/protege.php"; |
11 | |
12 | ejecutaServicio(function () { |
13 | $sesion = protege(); |
14 | if ($sesion->cue !== "") { |
15 | throw new ProblemDetails( |
16 | status: NO_AUTORIZADO, |
17 | type: "/error/sesioniniciada.html", |
18 | title: "Sesión iniciada.", |
19 | detail: "La sesión ya está iniciada.", |
20 | ); |
21 | } |
22 | $cue = leeTexto("cue"); |
23 | $match = leeTexto("match"); |
24 | if ($cue === null || $cue === "") |
25 | throw new ProblemDetails( |
26 | status: ProblemDetails::BadRequest, |
27 | type: "/error/faltacue.html", |
28 | title: "Falta el cue.", |
29 | ); |
30 | |
31 | if ($match === null || $match === "") |
32 | throw new ProblemDetails( |
33 | status: ProblemDetails::BadRequest, |
34 | type: "/error/faltamatch.html", |
35 | title: "Falta el match.", |
36 | ); |
37 | |
38 | $usuario = usuarioVerifica(trim($cue), trim($match)); |
39 | if ($usuario === false) { |
40 | throw new ProblemDetails( |
41 | status: ProblemDetails::BadRequest, |
42 | type: "/error/datosincorrectos.html", |
43 | title: "Datos incorrectos.", |
44 | detail: "El cue y/o el match proporcionados son incorrectos.", |
45 | ); |
46 | } else { |
47 | $rolIds = []; |
48 | foreach ($usuario->roles as $rol) { |
49 | $rolIds[] = $rol->id; |
50 | } |
51 | $_SESSION[CUE] = $cue; |
52 | $_SESSION[ROL_IDS] = $rolIds; |
53 | return [ |
54 | CUE => $cue, |
55 | ROL_IDS => $rolIds |
56 | ]; |
57 | } |
58 | }); |
59 | |