1 | <?php |
2 | |
3 | require_once __DIR__ . "/../lib/php/BAD_REQUEST.php"; |
4 | require_once __DIR__ . "/../lib/php/ejecutaServicio.php"; |
5 | require_once __DIR__ . "/../lib/php/recuperaTexto.php"; |
6 | require_once __DIR__ . "/../lib/php/validaCue.php"; |
7 | require_once __DIR__ . "/../lib/php/ProblemDetails.php"; |
8 | require_once __DIR__ . "/../lib/php/selectFirst.php"; |
9 | require_once __DIR__ . "/../lib/php/fetchAll.php"; |
10 | require_once __DIR__ . "/../lib/php/devuelveJson.php"; |
11 | require_once __DIR__ . "/CUE.php"; |
12 | require_once __DIR__ . "/ROL_IDS.php"; |
13 | require_once __DIR__ . "/Bd.php"; |
14 | require_once __DIR__ . "/TABLA_USUARIO.php"; |
15 | require_once __DIR__ . "/protege.php"; |
16 | |
17 | ejecutaServicio(function () { |
18 | |
19 | $sesion = protege(); |
20 | |
21 | if ($sesion->cue !== "") |
22 | throw new ProblemDetails( |
23 | status: NO_AUTORIZADO, |
24 | type: "/error/sesioniniciada.html", |
25 | title: "Sesión iniciada.", |
26 | detail: "La sesión ya está iniciada.", |
27 | ); |
28 | |
29 | $cue = recuperaTexto("cue"); |
30 | $match = recuperaTexto("match"); |
31 | |
32 | $cue = validaCue($cue); |
33 | |
34 | if ($match === false) |
35 | throw new ProblemDetails( |
36 | status: BAD_REQUEST, |
37 | title: "Falta el match.", |
38 | type: "/error/faltamatch.html", |
39 | detail: "La solicitud no tiene el valor de match.", |
40 | ); |
41 | |
42 | if ($match === "") |
43 | throw new ProblemDetails( |
44 | status: BAD_REQUEST, |
45 | title: "Match en blanco.", |
46 | type: "/error/matchenblanco.html", |
47 | detail: "Pon texto en el campo match.", |
48 | ); |
49 | |
50 | $pdo = Bd::pdo(); |
51 | |
52 | $usuario = |
53 | selectFirst(pdo: $pdo, from: USUARIO, where: [USU_CUE => $cue]); |
54 | |
55 | if ($usuario === false || !password_verify($match, $usuario[USU_MATCH])) |
56 | throw new ProblemDetails( |
57 | status: BAD_REQUEST, |
58 | type: "/error/datosincorrectos.html", |
59 | title: "Datos incorrectos.", |
60 | detail: "El cue y/o el match proporcionados son incorrectos.", |
61 | ); |
62 | |
63 | $rolIds = fetchAll( |
64 | $pdo->query( |
65 | "SELECT ROL_ID |
66 | FROM USU_ROL |
67 | WHERE USU_ID = :USU_ID |
68 | ORDER BY USU_ID" |
69 | ), |
70 | [":USU_ID" => $usuario[USU_ID]], |
71 | PDO::FETCH_COLUMN |
72 | ); |
73 | |
74 | $_SESSION[CUE] = $cue; |
75 | $_SESSION[ROL_IDS] = $rolIds; |
76 | devuelveJson([ |
77 | CUE => $cue, |
78 | ROL_IDS => $rolIds |
79 | ]); |
80 | }); |
81 | |