| 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 | require_once __DIR__ . "/rolIdsParaUsuId.php"; |
| 17 | |
| 18 | ejecutaServicio(function () { |
| 19 | |
| 20 | $sesion = protege(); |
| 21 | |
| 22 | if ($sesion->cue !== "") |
| 23 | throw new ProblemDetails( |
| 24 | status: NO_AUTORIZADO, |
| 25 | type: "/error/sesioniniciada.html", |
| 26 | title: "Sesión iniciada.", |
| 27 | detail: "La sesión ya está iniciada.", |
| 28 | ); |
| 29 | |
| 30 | $cue = recuperaTexto("cue"); |
| 31 | $match = recuperaTexto("match"); |
| 32 | |
| 33 | $cue = validaCue($cue); |
| 34 | |
| 35 | if ($match === false) |
| 36 | throw new ProblemDetails( |
| 37 | status: BAD_REQUEST, |
| 38 | title: "Falta el match.", |
| 39 | type: "/error/faltamatch.html", |
| 40 | detail: "La solicitud no tiene el valor de match.", |
| 41 | ); |
| 42 | |
| 43 | if ($match === "") |
| 44 | throw new ProblemDetails( |
| 45 | status: BAD_REQUEST, |
| 46 | title: "Match en blanco.", |
| 47 | type: "/error/matchenblanco.html", |
| 48 | detail: "Pon texto en el campo match.", |
| 49 | ); |
| 50 | |
| 51 | $pdo = Bd::pdo(); |
| 52 | |
| 53 | $usuario = |
| 54 | selectFirst(pdo: $pdo, from: USUARIO, where: [USU_CUE => $cue]); |
| 55 | |
| 56 | if ($usuario === false || !password_verify($match, $usuario[USU_MATCH])) |
| 57 | throw new ProblemDetails( |
| 58 | status: BAD_REQUEST, |
| 59 | type: "/error/datosincorrectos.html", |
| 60 | title: "Datos incorrectos.", |
| 61 | detail: "El cue y/o el match proporcionados son incorrectos.", |
| 62 | ); |
| 63 | |
| 64 | $_SESSION[CUE] = $cue; |
| 65 | $_SESSION[USU_ID] = $usuario[USU_ID]; |
| 66 | |
| 67 | devuelveJson([ |
| 68 | CUE => $cue, |
| 69 | ROL_IDS => rolIdsParaUsuId($usuario[USU_ID]) |
| 70 | ]); |
| 71 | }); |
| 72 | |