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 = "
-
".$htmlErroresGlobales."
- Eliminar usuario -
".$errorPassword."
+
".$htmlErroresGlobales."
+ Datos de la cuenta +
".$errorNombre."
+
".$errorEmail."
+
".$errorPassword."
+
".$errorPassword2."
+
+
+ + +
- +
"; return $html; } - - // Procesar el formulario + protected function procesaFormulario($datos){ $result = array(); + $nombre = $datos['name'] ?? null; + $nombre = strtolower($nombre); + if ( empty($nombre) || mb_strlen($nombre) < 3 || mb_strlen($nombre) > 8 ) { + $result['new_name'] = "El nombre tiene que tener\n una longitud de al menos\n 3 caracteres\n y menos de 8 caracteres."; + } + + $email = $datos['email'] ?? null; + if ( empty($email) || !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $email) ) { + $result['email'] = "El email no es válido."; + } + $password = $datos['pass'] ?? null; if ( empty($password) || mb_strlen($password) < 4 ) { - $result['pass'] = "Vuelve a introducir tu contrseña."; + $result['pass'] = "El password tiene que tener\n una longitud de al menos\n 4 caracteres."; + } + $password2 = $datos['repass'] ?? null; + if ( empty($password2) || strcmp($password, $password2) !== 0 ) { + $result['repass'] = "Los passwords deben coincidir."; } if (count($result) === 0) { $bd = new UserDAO("complucine"); - $user = $bd->selectUser(unserialize($_SESSION['user'])->getName(), $password); + $user = $bd->selectUser($nombre, $password); if (!$user) { - $result[] = "Ha ocurrido un problema\nal eliminar el usuario."; - $_SESSION['message'] = "
-
-
-
-

Ha ocurrido un problema


-

No se ha podido eliminar el usuario. - Comprueba que la contraseña introducida sea correcta.

- -
-
-
-
- "; - } - else { - $bd->deleteUser(unserialize($_SESSION['user'])->getId()); - $_SESSION['message'] = "
-
-
-
-

Operacion realizada con exito


-

Se ha eliminado su usuario correctamente.

- -
-
-
-
- "; - $result = '/logout/index.php'; + $result[] = "El usuario o contraseña\nno son correctos."; + } else { + if( (unserialize($_SESSION['user'])->getId() === $user->getId()) && ($nombre === $user->getName()) + && ($email === $user->getEmail()) && ($bd->verifyPass($password, $user->getPass())) ){ + + $bd->deleteUserAccount($user->getId()); + unset($_SESSION); + session_destroy(); + + $result = ROUTE_APP; + } else { + $result[] = "Los datos introducidos\nno son válidos."; + } } } return $result; diff --git a/panel_user/panelUser.php b/panel_user/panelUser.php index efb198d..1de806d 100644 --- a/panel_user/panelUser.php +++ b/panel_user/panelUser.php @@ -72,17 +72,20 @@ //Delete user account. static function delete(){ - require_once('./includes/formDeleteAccount.php'); $formDA = new FormDeleteAccount(); $htmlFormDeleteAccount = $formDA->gestiona(); - return $reply = ' -
-

Eliminar usuario

- '.$htmlFormDeleteAccount.' -
'."\n"; + return $reply = '
+

ELIMINAR CUENTA DE USUARIO


+
+ +
+ '.$htmlFormDeleteAccount.' +
+
+
'."\n"; } } ?> \ No newline at end of file