@@ -123,10 +123,10 @@ discard block |
||
| 123 | 123 | $cookie->set('session_hash', md5(time()), $config['sessions']['user_cookie']['lifetime']); |
| 124 | 124 | |
| 125 | 125 | # Generar la sesión del usuario |
| 126 | - $session->set($cookie->get('session_hash') . '__user_id',(int) $user_data['id_user']); |
|
| 126 | + $session->set($cookie->get('session_hash') . '__user_id', (int) $user_data['id_user']); |
|
| 127 | 127 | |
| 128 | 128 | # Generar data encriptada para prolongar la sesión |
| 129 | - if($config['sessions']['user_cookie']['enable']) { |
|
| 129 | + if ($config['sessions']['user_cookie']['enable']) { |
|
| 130 | 130 | # Generar id encriptado |
| 131 | 131 | $encrypt = Helper\Strings::ocrend_encode($user_data['id_user'], $config['sessions']['user_cookie']['key_encrypt']); |
| 132 | 132 | |
@@ -145,12 +145,12 @@ discard block |
||
| 145 | 145 | * @return bool true: Cuando el inicio de sesión es correcto |
| 146 | 146 | * false: Cuando el inicio de sesión no es correcto |
| 147 | 147 | */ |
| 148 | - private function authentication(string $email,string $pass) : bool { |
|
| 148 | + private function authentication(string $email, string $pass) : bool { |
|
| 149 | 149 | $email = $this->db->scape($email); |
| 150 | - $query = $this->db->select('id_user,pass','users',null, "email='$email'",1); |
|
| 150 | + $query = $this->db->select('id_user,pass', 'users', null, "email='$email'", 1); |
|
| 151 | 151 | |
| 152 | 152 | # Incio de sesión con éxito |
| 153 | - if(false !== $query && Helper\Strings::chash($query[0]['pass'],$pass)) { |
|
| 153 | + if (false !== $query && Helper\Strings::chash($query[0]['pass'], $pass)) { |
|
| 154 | 154 | |
| 155 | 155 | # Restaurar intentos |
| 156 | 156 | $this->restoreAttempts($email); |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | * @return false|array con información del usuario |
| 233 | 233 | */ |
| 234 | 234 | public function getUserById(int $id, string $select = '*') { |
| 235 | - return $this->db->select($select,'users',null,"id_user='$id'",1); |
|
| 235 | + return $this->db->select($select, 'users', null, "id_user='$id'", 1); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | * @return false|array con información de los usuarios |
| 244 | 244 | */ |
| 245 | 245 | public function getUsers(string $select = '*') { |
| 246 | - return $this->db->select($select,'users'); |
|
| 246 | + return $this->db->select($select, 'users'); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
@@ -255,12 +255,12 @@ discard block |
||
| 255 | 255 | * @return array con datos del usuario conectado |
| 256 | 256 | */ |
| 257 | 257 | public function getOwnerUser(string $select = '*') : array { |
| 258 | - if(null !== $this->id_user) { |
|
| 258 | + if (null !== $this->id_user) { |
|
| 259 | 259 | |
| 260 | - $user = $this->db->select($select,'users',null, "id_user='$this->id_user'",1); |
|
| 260 | + $user = $this->db->select($select, 'users', null, "id_user='$this->id_user'", 1); |
|
| 261 | 261 | |
| 262 | 262 | # Si se borra al usuario desde la base de datos y sigue con la sesión activa |
| 263 | - if(false === $user) { |
|
| 263 | + if (false === $user) { |
|
| 264 | 264 | $this->logout(); |
| 265 | 265 | } |
| 266 | 266 | |
@@ -385,18 +385,18 @@ discard block |
||
| 385 | 385 | # Generar token y contraseña |
| 386 | 386 | $token = md5(time()); |
| 387 | 387 | $pass = uniqid(); |
| 388 | - $link = $config['build']['url'] . 'lostpass?token='.$token.'&user='.$user_data[0]['id_user']; |
|
| 388 | + $link = $config['build']['url'] . 'lostpass?token=' . $token . '&user=' . $user_data[0]['id_user']; |
|
| 389 | 389 | |
| 390 | 390 | # Construir mensaje y enviar mensaje |
| 391 | - $HTML = 'Hola <b>'. $user_data[0]['name'] .'</b>, ha solicitado recuperar su contraseña perdida, si no ha realizado esta acción no necesita hacer nada. |
|
| 391 | + $HTML = 'Hola <b>' . $user_data[0]['name'] . '</b>, ha solicitado recuperar su contraseña perdida, si no ha realizado esta acción no necesita hacer nada. |
|
| 392 | 392 | <br /> |
| 393 | 393 | <br /> |
| 394 | - Para cambiar su contraseña por <b>'. $pass .'</b> haga <a href="'. $link .'" target="_blank">clic aquí</a> o en el botón de recuperar.'; |
|
| 394 | + Para cambiar su contraseña por <b>'. $pass . '</b> haga <a href="' . $link . '" target="_blank">clic aquí</a> o en el botón de recuperar.'; |
|
| 395 | 395 | |
| 396 | 396 | # Enviar el correo electrónico |
| 397 | 397 | $dest = array(); |
| 398 | 398 | $dest[$email] = $user_data[0]['name']; |
| 399 | - $email_send = Helper\Emails::send($dest,array( |
|
| 399 | + $email_send = Helper\Emails::send($dest, array( |
|
| 400 | 400 | # Título del mensaje |
| 401 | 401 | '{{title}}' => 'Recuperar contraseña de ' . $config['build']['name'], |
| 402 | 402 | # Url de logo |
@@ -410,23 +410,23 @@ discard block |
||
| 410 | 410 | # Texto del boton |
| 411 | 411 | '{{btn-name}}' => 'Recuperar Contraseña', |
| 412 | 412 | # Copyright |
| 413 | - '{{copyright}}' => '© '.date('Y') .' <a href="'.$config['build']['url'].'">'.$config['build']['name'].'</a> - Todos los derechos reservados.' |
|
| 414 | - ),0); |
|
| 413 | + '{{copyright}}' => '© ' . date('Y') . ' <a href="' . $config['build']['url'] . '">' . $config['build']['name'] . '</a> - Todos los derechos reservados.' |
|
| 414 | + ), 0); |
|
| 415 | 415 | |
| 416 | 416 | # Verificar si hubo algún problema con el envío del correo |
| 417 | - if(false === $email_send) { |
|
| 417 | + if (false === $email_send) { |
|
| 418 | 418 | throw new ModelsException('No se ha podido enviar el correo electrónico.'); |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | # Actualizar datos |
| 422 | 422 | $id_user = $user_data[0]['id_user']; |
| 423 | - $this->db->update('users',array( |
|
| 423 | + $this->db->update('users', array( |
|
| 424 | 424 | 'tmp_pass' => Helper\Strings::hash($pass), |
| 425 | 425 | 'token' => $token |
| 426 | - ),"id_user='$id_user'",1); |
|
| 426 | + ), "id_user='$id_user'", 1); |
|
| 427 | 427 | |
| 428 | 428 | return array('success' => 1, 'message' => 'Se ha enviado un enlace a su correo electrónico.'); |
| 429 | - } catch(ModelsException $e) { |
|
| 429 | + } catch (ModelsException $e) { |
|
| 430 | 430 | return array('success' => 0, 'message' => $e->getMessage()); |
| 431 | 431 | } |
| 432 | 432 | } |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | global $session, $cookie; |
| 441 | 441 | |
| 442 | 442 | $session->remove($cookie->get('session_hash') . '__user_id'); |
| 443 | - foreach($cookie->all() as $name => $value) { |
|
| 443 | + foreach ($cookie->all() as $name => $value) { |
|
| 444 | 444 | $cookie->remove($name); |
| 445 | 445 | } |
| 446 | 446 | |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | public static function resolveDriver(string $motor) : Driver { |
| 32 | 32 | global $config; |
| 33 | 33 | |
| 34 | - if($motor == 'mysql') { |
|
| 34 | + if ($motor == 'mysql') { |
|
| 35 | 35 | return new Mysql; |
| 36 | 36 | } |
| 37 | 37 | |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | $sqlite3 = $config['database']['drivers']['sqlite3']; |
| 31 | 31 | |
| 32 | 32 | # Establecer conexión, si la base de datos no existe, es creada |
| 33 | - parent::__construct('sqlite:' . str_replace('___ROOT___',___ROOT___,$sqlite3['file'])); |
|
| 33 | + parent::__construct('sqlite:' . str_replace('___ROOT___', ___ROOT___, $sqlite3['file'])); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | . (null !== $limit ? "LIMIT $limit" : '') |
| 73 | 73 | ); |
| 74 | 74 | |
| 75 | - if(false != $result && sizeof($result)) { |
|
| 75 | + if (false != $result && sizeof($result)) { |
|
| 76 | 76 | $matriz = (array) $result->fetchAll(PDO::FETCH_ASSOC); |
| 77 | 77 | $result->closeCursor(); |
| 78 | 78 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | ); |
| 45 | 45 | |
| 46 | 46 | # Verificar conexión |
| 47 | - if($this->connect_errno) { |
|
| 47 | + if ($this->connect_errno) { |
|
| 48 | 48 | throw new \RuntimeException('ERROR :' . $this->connect_errno . ' conectando con la base de datos' . $this->connect_error); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | . (null !== $limit ? "LIMIT $limit" : '') |
| 83 | 83 | ); |
| 84 | 84 | |
| 85 | - if(false != $result && $result->num_rows) { |
|
| 85 | + if (false != $result && $result->num_rows) { |
|
| 86 | 86 | $matriz = (array) $result->fetch_all(MYSQLI_ASSOC); |
| 87 | 87 | $result->free(); |
| 88 | 88 | |
@@ -80,22 +80,22 @@ |
||
| 80 | 80 | global $session, $config; |
| 81 | 81 | |
| 82 | 82 | # Verificar si está habilitada la opción de sesión de usuario con cookie |
| 83 | - if($config['sessions']['user_cookie']['enable']) { |
|
| 83 | + if ($config['sessions']['user_cookie']['enable']) { |
|
| 84 | 84 | # Obtener |
| 85 | 85 | $user_session = $session->get($this->get('session_hash') . '__user_id'); |
| 86 | 86 | $salt = $this->get('appsalt'); |
| 87 | 87 | $encrypt = $this->get('appencrypt'); |
| 88 | 88 | |
| 89 | 89 | # Verificar que no estén vacías y coincidan |
| 90 | - if(null == $user_session && null != $salt && null != $encrypt && Helper\Strings::chash($salt ?? '_', $encrypt ?? '/$')) { |
|
| 90 | + if (null == $user_session && null != $salt && null != $encrypt && Helper\Strings::chash($salt ?? '_', $encrypt ?? '/$')) { |
|
| 91 | 91 | # Generar un nuevo session hash |
| 92 | - $this->set('session_hash', md5(time()) , $config['sessions']['user_cookie']['lifetime']); |
|
| 92 | + $this->set('session_hash', md5(time()), $config['sessions']['user_cookie']['lifetime']); |
|
| 93 | 93 | |
| 94 | 94 | # Desencriptar el id del usuario |
| 95 | 95 | $id_user = Helper\Strings::ocrend_decode($encrypt, $config['sessions']['user_cookie']['key_encrypt']); |
| 96 | 96 | |
| 97 | 97 | # Reestablecer la sesión |
| 98 | - $session->set($this->get('session_hash') . '__user_id',(int) $id_user); |
|
| 98 | + $session->set($this->get('session_hash') . '__user_id', (int) $id_user); |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -38,15 +38,15 @@ |
||
| 38 | 38 | if ($__TWIG_READABLE_AND_WRITABLE) { |
| 39 | 39 | |
| 40 | 40 | # Intentar solucionarlo |
| 41 | - if(!is_dir($__TWIG_CACHE_PATH)) { |
|
| 41 | + if (!is_dir($__TWIG_CACHE_PATH)) { |
|
| 42 | 42 | mkdir($__TWIG_CACHE_PATH, 0644, true); |
| 43 | 43 | } else { |
| 44 | 44 | chmod($__TWIG_CACHE_PATH, 0644); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | # Revisar la lecutra para twig |
| 48 | - if($__TWIG_READABLE_AND_WRITABLE) { |
|
| 49 | - throw new \RuntimeException('Debe conceder permisos de escritura y lectura a la ruta '. $__TWIG_CACHE_PATH .' ó crearla si no existe.'); |
|
| 48 | + if ($__TWIG_READABLE_AND_WRITABLE) { |
|
| 49 | + throw new \RuntimeException('Debe conceder permisos de escritura y lectura a la ruta ' . $__TWIG_CACHE_PATH . ' ó crearla si no existe.'); |
|
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | |
@@ -52,7 +52,7 @@ |
||
| 52 | 52 | |
| 53 | 53 | # Verificar sesión del usuario |
| 54 | 54 | $session_name = $cookie->get('session_hash') . '__user_id'; |
| 55 | - if(null !== $session->get($session_name)) { |
|
| 55 | + if (null !== $session->get($session_name)) { |
|
| 56 | 56 | $this->id_user = $session->get($session_name); |
| 57 | 57 | } |
| 58 | 58 | } |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | * |
| 37 | 37 | * @return void |
| 38 | 38 | */ |
| 39 | - protected function startDBConexion($driver = null) { |
|
| 39 | + protected function startDBConexion($driver = null) { |
|
| 40 | 40 | global $config; |
| 41 | 41 | $this->db = Database::resolveDriver($driver ?? $config['database']['default_driver']); |
| 42 | 42 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | /** |
| 110 | 110 | * Verifica las peticiones por defecto |
| 111 | 111 | */ |
| 112 | - final private function checkRequests() { |
|
| 112 | + final private function checkRequests() { |
|
| 113 | 113 | # Verificar si existe peticiones |
| 114 | 114 | if (null !== $this->requestUri) { |
| 115 | 115 | $this->real_request = explode('/', $this->requestUri); |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @throws \RuntimeException si no puede definirse la ruta |
| 131 | 131 | */ |
| 132 | - final public function setRoute(string $index, string $rule = 'none') { |
|
| 132 | + final public function setRoute(string $index, string $rule = 'none') { |
|
| 133 | 133 | # Nombres de rutas no permitidos |
| 134 | 134 | if (in_array($index, ['/controller', '/method', '/id'])) { |
| 135 | 135 | throw new \RuntimeException('No puede definirse ' . $index . ' como índice en la ruta.'); |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | $rules = new Rules; |
| 167 | 167 | |
| 168 | 168 | # Retornar ruta con la regla definida aplicada |
| 169 | - if(method_exists($rules, $this->routerCollectionRules[$index])) { |
|
| 169 | + if (method_exists($rules, $this->routerCollectionRules[$index])) { |
|
| 170 | 170 | return $rules->{$this->routerCollectionRules[$index]}($ruta); |
| 171 | 171 | } |
| 172 | 172 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | final public function getId(bool $with_rules = false) { |
| 207 | 207 | $id = $this->routerCollection['/id']; |
| 208 | - if($with_rules && (!is_numeric($id) || $id <= 0)) { |
|
| 208 | + if ($with_rules && (!is_numeric($id) || $id <= 0)) { |
|
| 209 | 209 | return null; |
| 210 | 210 | } |
| 211 | 211 | |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | * |
| 220 | 220 | * @return void |
| 221 | 221 | */ |
| 222 | - final private function loadController() { |
|
| 222 | + final private function loadController() { |
|
| 223 | 223 | # Definir controlador |
| 224 | 224 | if (null != ($controller = $this->getController())) { |
| 225 | 225 | $controller = $controller . 'Controller'; |
@@ -258,15 +258,15 @@ discard block |
||
| 258 | 258 | * |
| 259 | 259 | * @return void |
| 260 | 260 | */ |
| 261 | - final public function executeController() { |
|
| 261 | + final public function executeController() { |
|
| 262 | 262 | global $config; |
| 263 | 263 | |
| 264 | - if($config['build']['production']) { |
|
| 264 | + if ($config['build']['production']) { |
|
| 265 | 265 | try { |
| 266 | 266 | $this->loadController(); |
| 267 | - } catch(\Throwable $e) { |
|
| 267 | + } catch (\Throwable $e) { |
|
| 268 | 268 | $this->productionError(); |
| 269 | - } catch(\Exception $e) { |
|
| 269 | + } catch (\Exception $e) { |
|
| 270 | 270 | $this->productionError(); |
| 271 | 271 | } |
| 272 | 272 | } else { |