[Valida] si el registro de usuario es único y añade paréntesis a la función exit
This commit is contained in:
parent
9d96eacc7b
commit
fc65a6b0e0
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
require_once 'models/adminModel.php';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
require_once 'models/articlesModel.php';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
require_once 'models/blogModel.php';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
require_once 'models/communityModel.php';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
require_once 'models/profilesModel.php';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
require_once 'models/searchModel.php';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
require_once 'models/usersModel.php';
|
||||
|
||||
|
@ -36,16 +36,39 @@ class usersController {
|
|||
array('password', 'exists' => true, 'min_lenght' => 6, 'max_lenght' => 255, 'not_spaces' => true, 'equal' => $_POST['confirm-password'])
|
||||
));
|
||||
|
||||
// Formatea en minúsculas la dirección de e-mail.
|
||||
$data['email'] = strtolower($data['email']);
|
||||
|
||||
$usersModel = new usersModel();
|
||||
|
||||
$users = $usersModel -> find($data['username'], $data['email']);
|
||||
|
||||
$msg = 'Existe una cuenta registrada con el mismo apodo o dirección de correo electrónico, por favor intételo de nuevo';
|
||||
|
||||
// Valida si la cuenta es única y elimina cuentas expiradas.
|
||||
foreach ($users as $user) {
|
||||
// Valida si es una cuenta activa o inactiva con registro de datos de usuario.
|
||||
if (empty($user['hash_expiration'])) {
|
||||
messages::add($msg);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
// Valida si es una cuenta expirada.
|
||||
if (time() > $user['hash_expiration']) {
|
||||
$usersModel -> delete($user['id']);
|
||||
}
|
||||
else {
|
||||
messages::add($msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
messages::exist(NABU_ROUTES['signup']);
|
||||
|
||||
// Genera una llave aleatoria de verificación de dirección de e-mail.
|
||||
$key = bin2hex(random_bytes(32));
|
||||
|
||||
// Formatea en minúsculas la dirección de e-mail.
|
||||
$data['email'] = strtolower($data['email']);
|
||||
|
||||
// Hash de verificación de e-mail.
|
||||
$hash = hash_hmac(self::hash, $data['email'], $key);
|
||||
|
||||
|
@ -66,8 +89,16 @@ class usersController {
|
|||
'expiration' => time() + 60 * 60
|
||||
);
|
||||
|
||||
require_once 'models/verificationsModel.php';
|
||||
|
||||
// Registra el hash de verificación de dirección de e-mail.
|
||||
$usersModel -> verification($verification);
|
||||
$verificationsModel = new verificationsModel();
|
||||
|
||||
$verificationsModel -> save($verification);
|
||||
|
||||
messages::add('Su cuenta se ha registrado correctamente, por favor verifica tu dirección de correo electrónico');
|
||||
|
||||
utils::redirect(NABU_ROUTES['signup']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
require_once 'models/verificationsModel.php';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
define('NABU_URL', 'http://localhost:8000');
|
||||
|
||||
|
@ -33,7 +33,7 @@ define('NABU_DEFAULT', array(
|
|||
date_default_timezone_set('America/Mexico_City');
|
||||
|
||||
/*
|
||||
// Nivel de reporte de errores.
|
||||
// Nivel de reporte de errores (todos los errores).
|
||||
ini_set('error_reporting', E_ALL);
|
||||
|
||||
// No muestra en pantalla todos los errores.
|
||||
|
@ -45,7 +45,7 @@ ini_set('display_startup_errors', false);
|
|||
// No registra mensajes repetidos.
|
||||
ini_set('ignore_repeated_errros', true);
|
||||
|
||||
// Configura los registros de errores en 'error_log' (manejador de errores de PHP).
|
||||
// Selecciona el manejador de errores de PHP 'error_log'.
|
||||
ini_set('log_errors', true);
|
||||
|
||||
// Define la ruta del archivo de registro de errores para 'error_log'.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
session_start();
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
return array(
|
||||
'admin' => array('route' => 'admin', 'controller' => 'adminController', 'view' => 'admin'),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
// Realiza la conexión con la base de datos.
|
||||
class connection {
|
||||
|
@ -50,7 +50,7 @@ class connection {
|
|||
// Define la codificación de caracteres para el cliente del SGBD y los resultados de las consultas.
|
||||
$this -> pdo -> exec('SET CHARSET ' . $config['charset']);
|
||||
}
|
||||
catch(PDOException $e) {
|
||||
catch (PDOException $e) {
|
||||
exit($e -> getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
// Valida formularios contra ataques CSRF.
|
||||
class csrf {
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit();
|
||||
|
||||
class emails {
|
||||
|
||||
}
|
|
@ -1,21 +1,23 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
// Administra mensajes sobre advertencias, avisos y errores en las páginas.
|
||||
class messages {
|
||||
// Agrega mensajes sobre advertencias o avisos.
|
||||
static public function add(string $message) {
|
||||
if (empty($_SESSION['messages']))
|
||||
if (empty($_SESSION['messages'])) {
|
||||
$_SESSION['messages'] = array();
|
||||
}
|
||||
|
||||
array_push($_SESSION['messages'], $message);
|
||||
}
|
||||
|
||||
// @return un array de mensajes.
|
||||
static public function get() {
|
||||
if (empty($_SESSION['messages']))
|
||||
if (empty($_SESSION['messages'])) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$messages = $_SESSION['messages'];
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
// Colección de herramientas propias de Nabu.
|
||||
class utils {
|
||||
// Redirecciona a una página web y termina la ejecución de todos los scripts de PHP.
|
||||
static public function redirect(string $route) {
|
||||
header('Location: ' . $route);
|
||||
exit;
|
||||
exit();
|
||||
}
|
||||
|
||||
// @return la fecha actual.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
// Valida los campos de un formulario.
|
||||
class validations {
|
||||
|
@ -96,8 +96,9 @@ class validations {
|
|||
$data = array();
|
||||
|
||||
foreach ($options as $option) {
|
||||
if (empty($option[0]) || !is_string($option[0]))
|
||||
if (empty($option[0]) || !is_string($option[0])) {
|
||||
$this -> errors('Not found field name');
|
||||
}
|
||||
|
||||
$type = 'string';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
class adminModel extends connection {
|
||||
public function __construct() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
class articlesModel extends connection {
|
||||
public function __construct() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
class blogModel extends connection {
|
||||
public function __construct() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
class communityModel extends connection {
|
||||
public function __construct() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
class profilesModel extends connection {
|
||||
public function __construct() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
class searchModel extends connection {
|
||||
public function __construct() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
class usersModel extends connection {
|
||||
public function __construct() {
|
||||
|
@ -27,7 +27,7 @@ class usersModel extends connection {
|
|||
|
||||
return $users;
|
||||
}
|
||||
catch(PDOException $e) {
|
||||
catch (PDOException $e) {
|
||||
$this -> errors($e -> getMessage(), 'tuvimos un problema para validar si tu apodo y dirección de correo electrónico son únicos');
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class usersModel extends connection {
|
|||
try {
|
||||
$this -> pdo -> prepare($query) -> execute($data);
|
||||
}
|
||||
catch(PDOException $e) {
|
||||
catch (PDOException $e) {
|
||||
$this -> errors($e -> getMessage(), 'tuvimos un problema para registrar tu cuenta de usuario');
|
||||
}
|
||||
}
|
||||
|
@ -65,25 +65,26 @@ class usersModel extends connection {
|
|||
|
||||
return $user;
|
||||
}
|
||||
catch(PDOException $e) {
|
||||
catch (PDOException $e) {
|
||||
$this -> errors($e -> getMessage(), 'tuvimos un problema para buscar tu cuenta de usuario');
|
||||
}
|
||||
}
|
||||
|
||||
// Registra el 'hash de verificación de dirección de e-mail' con tiempo de expiración.
|
||||
public function verification(array $verification) {
|
||||
$query = 'INSERT INTO verifications(id, hash, expiration) VALUES(:id, :hash, :expiration)';
|
||||
// Elimina un usuario.
|
||||
public function delete(int $id) {
|
||||
$query = 'DELETE FROM users WHERE id = ?';
|
||||
|
||||
try {
|
||||
$this -> pdo -> prepare($query) -> execute($verification);
|
||||
$this -> pdo -> prepare($query) -> execute(array($id));
|
||||
}
|
||||
catch(PDOException $e) {
|
||||
$this -> errors($e -> getMessage(), 'tuvimos un problema para registrar tu clave de verificación de dirección de correo electrónico');
|
||||
catch (PDOException) {
|
||||
$this -> errors($e -> getMessage(), 'tuvimos un problema para eliminar una cuenta de usuario');
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
parent::__destruct();
|
||||
|
||||
$this -> pdo = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,27 @@
|
|||
<?php
|
||||
|
||||
defined('NABU') || exit;
|
||||
defined('NABU') || exit();
|
||||
|
||||
class verificationsModel extends connection {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
// Registra el 'hash de verificación de dirección de e-mail' con tiempo de expiración.
|
||||
public function save(array $verification) {
|
||||
$query = 'INSERT INTO verifications(id, hash, expiration) VALUES(:id, :hash, :expiration)';
|
||||
|
||||
try {
|
||||
$this -> pdo -> prepare($query) -> execute($verification);
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
$this -> errors($e -> getMessage(), 'tuvimos un problema para registrar tu clave de verificación de dirección de correo electrónico');
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
parent::__destruct();
|
||||
|
||||
$this -> pdo = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Administración' ?>
|
||||
<?php $styles = array(
|
||||
'admin/dashboard/dashboard.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Editar artículo' ?>
|
||||
<?php $styles = array(
|
||||
'admin/edit-article/edit-article.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Artículos publicados' ?>
|
||||
<?php $styles = array(
|
||||
'admin/published-articles/published-articles.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Usuarios registrados' ?>
|
||||
<?php $styles = array(
|
||||
'admin/users/users.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $username = $_SESSION['user']['username'] ?>
|
||||
|
||||
<header>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
|
||||
<article class="card">
|
||||
<picture class="banner">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
|
||||
<footer class="footer">
|
||||
<div class="rights">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
|
||||
<!-- Muestra mensajes sobre advertencias o avisos. -->
|
||||
<?php if (!empty($messages)): ?>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
|
||||
<div class="overlay"></div>
|
||||
<nav class="nav">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
|
||||
<a href="<?= $view . '&page=' . $page - 1 ?>">Anterior</a>
|
||||
<span><?= $page ?></span>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
|
||||
<form method="POST" action="<?= NABU_ROUTES['home'] ?>">
|
||||
<input type="hidden" name="csrf" value="<?= $token ?>">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Muro' ?>
|
||||
<?php $styles = array(
|
||||
'pages/all-articles/all-articles.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Artículo' ?>
|
||||
<?php $styles = array(
|
||||
'pages/article/article.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Categoría' ?>
|
||||
<?php $styles = array(
|
||||
'pages/category/category.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Confirmar contraseña' ?>
|
||||
<?php $styles = array(
|
||||
'pages/confirm-password/confirm-password.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Editar artículo' ?>
|
||||
<?php $styles = array(
|
||||
'pages/edit-article/edit-article.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Editar perfil' ?>
|
||||
<?php $styles = array(
|
||||
'pages/edit-profile/edit-profile.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Error' ?>
|
||||
<?php $styles = array(
|
||||
'pages/errors/errors.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Artículos favoritos' ?>
|
||||
<?php $styles = array(
|
||||
'pages/favorites/favorites.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = NABU_DEFAULT['website-name'] ?>
|
||||
<?php $styles = array(
|
||||
'components/articles/articles.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Iniciar sesión' ?>
|
||||
<?php $styles = array(
|
||||
'pages/login/login.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Publicar un artículo' ?>
|
||||
<?php $styles = array(
|
||||
'pages/post-article/post-article.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Perfil' ?>
|
||||
<?php $styles = array(
|
||||
'pages/profile/profile.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Búsquedas' ?>
|
||||
<?php $styles = array(
|
||||
'pages/search/search.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Artículos enviados' ?>
|
||||
<?php $styles = array(
|
||||
'pages/sent-articles/sent-articles.css',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('NABU') || exit ?>
|
||||
<?php defined('NABU') || exit() ?>
|
||||
<?php $head_title = 'Crea una cuenta' ?>
|
||||
<?php $styles = array(
|
||||
'components/footer/footer.css',
|
||||
|
|
Loading…
Reference in a new issue