From 6834851714103f27441e2e4a85b04d9dcae662aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20M=C3=A9ndez?= <45081533+FerMdez@users.noreply.github.com> Date: Tue, 11 May 2021 17:36:06 +0200 Subject: [PATCH] Add files via upload --- assets/css/highContrast.css | 3 + assets/css/main.css | 3 + assets/php/common/user_dao.php | 20 +++-- assets/php/config.php | 11 ++- panel_user/includes/formChangeEmail.php | 2 +- panel_user/includes/formChangeName.php | 2 +- panel_user/includes/formChangePass.php | 1 - panel_user/includes/formDeleteAccount.php | 101 ++++++++++++---------- panel_user/panelUser.php | 15 ++-- 9 files changed, 90 insertions(+), 68 deletions(-) diff --git a/assets/css/highContrast.css b/assets/css/highContrast.css index 50499c3..ec692ed 100644 --- a/assets/css/highContrast.css +++ b/assets/css/highContrast.css @@ -315,6 +315,9 @@ font-size: 90%; color: #00020f; } + .code label{ + color: #d3ebff; + } .code.details{ height: 750px; } diff --git a/assets/css/main.css b/assets/css/main.css index c68668a..a1744f6 100644 --- a/assets/css/main.css +++ b/assets/css/main.css @@ -314,6 +314,9 @@ main img { font-size: 90%; color: #d3ebff; } +.code label{ + color: #d3ebff; +} .code.details{ height: 750px; } diff --git a/assets/php/common/user_dao.php b/assets/php/common/user_dao.php index eea4f95..483a76a 100644 --- a/assets/php/common/user_dao.php +++ b/assets/php/common/user_dao.php @@ -18,15 +18,6 @@ //Methods: - // Delete user - public function deleteUser($user_id) { - $sql = sprintf( "DELETE FROM users WHERE id = '%s'", $user_id); - - $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); - - return $resul; - } - //Encrypt password with SHA254. private function encryptPass($password){ //$password = hash('sha256', $password); @@ -75,6 +66,7 @@ $resul = mysqli_query($this->mysqli, $sql); $resul->data_seek(0); + $user = null; while ($fila = $resul->fetch_assoc()) { if($username === $fila['username'] && $this->verifyPass($password, $fila['passwd'])){ $user = $this->loadUser($fila['id'], $fila['username'], $fila['email'], $fila['passwd'], $fila['rol']); @@ -132,6 +124,16 @@ } + //Delete user account by id. + public function deleteUserAccount($id){ + $id = $this->mysqli->real_escape_string($id); + + $sql = sprintf( "DELETE FROM users WHERE id = '%d'", $id ); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + return $resul; + } + //Create a new User Data Transfer Object. public function loadUser($id, $username, $email, $password, $rol){ return new User($id, $username, $email, $password, $rol); diff --git a/assets/php/config.php b/assets/php/config.php index e98fe70..f03a4fb 100644 --- a/assets/php/config.php +++ b/assets/php/config.php @@ -2,10 +2,10 @@ /** * Connection parameters to the DB. */ - define('BD_HOST', 'vm01.db.swarm.test'); + define('BD_HOST', 'localhost'); define('BD_NAME', 'complucine'); - define('BD_USER', 'root'); - define('BD_PASS', 'T4cFwfxT_vI2W!nYp!tv'); + define('BD_USER', 'sw'); + define('BD_PASS', '_admin_'); /* * Configuration parameters used to generate URLs and file paths in the application @@ -46,4 +46,9 @@ * @see http://php.net/manual/en/language.types.callable.php */ register_shutdown_function(array($app, 'shutdown')); + + //Depuración (BORRAR): + ini_set('display_errors', 1); + ini_set('display_startup_errors', 1); + error_reporting(E_ALL); ?> diff --git a/panel_user/includes/formChangeEmail.php b/panel_user/includes/formChangeEmail.php index 57d4071..8909623 100644 --- a/panel_user/includes/formChangeEmail.php +++ b/panel_user/includes/formChangeEmail.php @@ -12,7 +12,7 @@ class FormChangeEmail extends Form { } protected function generaCamposFormulario($datos, $errores = array()){ - $nombre = $datos['nombreUsuario'] ?? ''; + $email = $datos['email'] ?? ''; // Se generan los mensajes de error si existen. $htmlErroresGlobales = self::generaListaErroresGlobales($errores); diff --git a/panel_user/includes/formChangeName.php b/panel_user/includes/formChangeName.php index f7cc0b5..41cac32 100644 --- a/panel_user/includes/formChangeName.php +++ b/panel_user/includes/formChangeName.php @@ -74,7 +74,7 @@ class FormChangeName extends Form { "; } else { $user = $bd->selectUser($nombre, $password); - if ($user == ""){ + if ($user){ $result[] = "El nombre de usuario ya existe."; } else { $bd->changeUserName(unserialize($_SESSION['user'])->getId(), $nombre); diff --git a/panel_user/includes/formChangePass.php b/panel_user/includes/formChangePass.php index 955860d..80bc67f 100644 --- a/panel_user/includes/formChangePass.php +++ b/panel_user/includes/formChangePass.php @@ -10,7 +10,6 @@ class FormChangePass extends Form { } protected function generaCamposFormulario($datos, $errores = array()){ - $nombre = $datos['nombreUsuario'] ?? ''; // Se generan los mensajes de error si existen. $htmlErroresGlobales = self::generaListaErroresGlobales($errores); diff --git a/panel_user/includes/formDeleteAccount.php b/panel_user/includes/formDeleteAccount.php index 11ce375..99871dd 100644 --- a/panel_user/includes/formDeleteAccount.php +++ b/panel_user/includes/formDeleteAccount.php @@ -1,81 +1,88 @@ "./?option=delete_user"); - parent::__construct('formDelete', $options); + parent::__construct('formDeleteAccount', $options); } - - // Metodos - // Generar formulario + protected function generaCamposFormulario($datos, $errores = array()){ - $nombre = $datos['nombreUsuario'] ?? ''; + $nombre = $datos['username'] ?? ''; // Se generan los mensajes de error si existen. $htmlErroresGlobales = self::generaListaErroresGlobales($errores); + $errorNombre = self::createMensajeError($errores, 'new_name', 'span', array('class' => 'error')); + $errorEmail = self::createMensajeError($errores, 'email', 'span', array('class' => 'error')); $errorPassword = self::createMensajeError($errores, 'pass', 'span', array('class' => 'error')); + $errorPassword2 = self::createMensajeError($errores, 'repass', 'span', array('class' => 'error')); $html = "