Skip to content

Commit

Permalink
Limpiando código
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanpgr committed Apr 2, 2024
1 parent 76a872d commit 708700d
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 28 deletions.
2 changes: 1 addition & 1 deletion api-rest/index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

require_once 'routes/api.php';
require_once 'src/routes/api.php';

?>
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require_once '../api-rest/data/DatabaseJsonResponse.php';
require_once '../api-rest/src/data/DatabaseJsonResponse.php';

class UserController {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

include_once '../api-rest/config/EnvironmentVariables.php';
include_once '../api-rest/src/config/EnvironmentVariables.php';
require 'vendor/autoload.php';

// Clase para realizar conexión con patron singleton
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

include_once 'DatabaseConexion.php';
include_once '../api-rest/config/EnvironmentVariables.php';
include_once '../api-rest/config/constants.php';
include_once '../api-rest/src/config/EnvironmentVariables.php';
include_once '../api-rest/src/config/constants.php';
include_once 'Queries.php';

use \Firebase\JWT\JWT;
Expand Down Expand Up @@ -32,35 +32,22 @@ public function loginUser($email, $password) {
/* Si mi contador de filas obtenidas es diferente de cero verifico
si la contraseña recibida es la misma con la que esta en la db */
if ($rowCount != 0) {
$data = $query->fetch();
$passw_db = $data['passw_user'];
$dataUser = $query->fetch();
$passw_db = $dataUser['passw_user'];
// Metodo password_verify descodifica la contraseña traida de la db y la compara con la recibida
if (password_verify($password, $passw_db)) {
// Prepara el token con la información requerida
$token = array(
"iss" => ISS,
"aud" => AUD,
"iat" => IAT,
"nbf" => NBF,
"exp" => EXP,

"user" => array(
"id" => $data['id_user'],
"nombre" => $data['nomb_user'],
"apellido" => $data['apell_user'],
"email" => $data['email_user']
));

// Codifica el token
$jwt = JWT::encode($token, $this->envVariables->getKeyJwt(), $this->envVariables->getAlgJwt());

$token = $this->buildToken($dataUser); // Prepara el token pasando el usuario($dataUser)
$jwt = JWT::encode($token, $this->envVariables->getKeyJwt(), $this->envVariables->getAlgJwt()); // Codifica el token

return array(
"message" => "Inicio de sesión satisfactorio.",
"token" => $jwt,
"status" => 'OK'
);

} else {
return array("message" => 'Inicio de sesión fallido.',
return array("message" => 'Contraseña Incorrecta.',
"status" => 'error');
}
}
Expand Down Expand Up @@ -121,6 +108,24 @@ public function getUsers($headers) {

}

// Construye y retorna el token con la información y el usuario($data) requeridos
private function buildToken($dataUser) {

return array(
"iss" => ISS,
"aud" => AUD,
"iat" => IAT,
"nbf" => NBF,
"exp" => EXP,

"user" => array(
"id" => $dataUser['id_user'],
"nombre" => $dataUser['nomb_user'],
"apellido" => $dataUser['apell_user'],
"email" => $dataUser['email_user']
));
}

// Función para obtener token y retornar decodeado
private function getToken($headers) {
if (isset($headers["Authorization"])) {
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions api-rest/routes/api.php → api-rest/src/routes/api.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

require_once '../api-rest/controllers/UserController.php';
require_once '../api-rest/models/User.php';
include_once '../api-rest/config/constants.php';
require_once '../api-rest/src/controllers/UserController.php';
require_once '../api-rest/src/models/User.php';
include_once '../api-rest/src/config/constants.php';

require 'vendor/autoload.php';

Expand Down

0 comments on commit 708700d

Please sign in to comment.