From bb94e302821285a8e4792990d79b2fdef4fb9c47 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fernando=20M=C3=A9ndez?=
<45081533+FerMdez@users.noreply.github.com>
Date: Sun, 9 May 2021 16:27:21 +0200
Subject: [PATCH] Add files via upload
---
assets/php/config.php | 2 -
panel_user/includes/formChangeEmail.php | 82 +++++++++++++++++++++++++
panel_user/includes/formChangeName.php | 39 ++++++------
panel_user/includes/formChangePass.php | 82 +++++++++++++++++++++++++
panel_user/panelUser.php | 60 +++++-------------
5 files changed, 198 insertions(+), 67 deletions(-)
diff --git a/assets/php/config.php b/assets/php/config.php
index 66f1854..2d8ef8e 100644
--- a/assets/php/config.php
+++ b/assets/php/config.php
@@ -44,6 +44,4 @@
* @see http://php.net/manual/en/language.types.callable.php
*/
register_shutdown_function(array($app, 'shutdown'));
-
-
?>
diff --git a/panel_user/includes/formChangeEmail.php b/panel_user/includes/formChangeEmail.php
index 15c5adc..5d83137 100644
--- a/panel_user/includes/formChangeEmail.php
+++ b/panel_user/includes/formChangeEmail.php
@@ -1,3 +1,85 @@
"./?option=manage_profile");
+ parent::__construct('formChangeUserEmail', $options);
+ }
+
+ protected function generaCamposFormulario($datos, $errores = array()){
+ $nombre = $datos['nombreUsuario'] ?? '';
+
+ // Se generan los mensajes de error si existen.
+ $htmlErroresGlobales = self::generaListaErroresGlobales($errores);
+ $errorNombre = self::createMensajeError($errores, 'nombre', 'span', array('class' => 'error'));
+ $errorPassword = self::createMensajeError($errores, 'pass', 'span', array('class' => 'error'));
+ $errorPassword2 = self::createMensajeError($errores, 'repass', 'span', array('class' => 'error'));
+
+ $html = '
';
+
+ return $html;
+ }
+
+ /* TODO */
+ protected function procesaFormulario($datos){
+ $result = array();
+
+ $nombre = $datos['new_name'] ?? null;
+ if ( empty($nombre) || mb_strlen($nombre) < 5 ) {
+ $result['new_name'] = "El nombre tiene que tener una longitud de al menos 5 caracteres.";
+ }
+
+ $password = $datos['pass'] ?? null;
+ if ( empty($password) || mb_strlen($password) < 5 ) {
+ $result['pass'] = "El password tiene que tener una longitud de al menos 5 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);
+ if (!$user) {
+ $result[] = "El usuario no existe.";
+ } else {
+ $bd->changeUserName(unserialize($_SESSION['user'])->getId(), $username);
+ $user = $bd->selectUser($username, $password);
+ if (!$user){
+ $result[] = "Ha ocurrido un probrema al actualizar el nombre de usuario.";
+ }else{
+ $_SESSION['user'] = serialize($user);
+ $_SESSION["nombre"] = $user->getName();
+ $result = './?option=manage_profile';
+ }
+ }
+ }
+ return $result;
+ }
+
+ protected function test_input($input){
+ return htmlspecialchars(trim(strip_tags($input)));
+ }
+}
?>
\ No newline at end of file
diff --git a/panel_user/includes/formChangeName.php b/panel_user/includes/formChangeName.php
index e2b27dc..756906c 100644
--- a/panel_user/includes/formChangeName.php
+++ b/panel_user/includes/formChangeName.php
@@ -19,27 +19,27 @@ class FormChangeName extends Form {
$errorPassword2 = self::createMensajeError($errores, 'repass', 'span', array('class' => 'error'));
$html = '';
+
+
+
+
+
+ ';
+
return $html;
}
-
protected function procesaFormulario($datos){
$result = array();
@@ -80,4 +80,5 @@ class FormChangeName extends Form {
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
-}
\ No newline at end of file
+}
+?>
\ No newline at end of file
diff --git a/panel_user/includes/formChangePass.php b/panel_user/includes/formChangePass.php
index 15c5adc..af9fdd2 100644
--- a/panel_user/includes/formChangePass.php
+++ b/panel_user/includes/formChangePass.php
@@ -1,3 +1,85 @@
"./?option=manage_profile");
+ parent::__construct('formChangeUserPass', $options);
+ }
+
+ protected function generaCamposFormulario($datos, $errores = array()){
+ $nombre = $datos['nombreUsuario'] ?? '';
+
+ // Se generan los mensajes de error si existen.
+ $htmlErroresGlobales = self::generaListaErroresGlobales($errores);
+ $errorNombre = self::createMensajeError($errores, 'nombre', 'span', array('class' => 'error'));
+ $errorPassword = self::createMensajeError($errores, 'pass', 'span', array('class' => 'error'));
+ $errorPassword2 = self::createMensajeError($errores, 'repass', 'span', array('class' => 'error'));
+
+ $html = '';
+
+ return $html;
+ }
+
+ /* TODO */
+ protected function procesaFormulario($datos){
+ $result = array();
+
+ $nombre = $datos['new_name'] ?? null;
+ if ( empty($nombre) || mb_strlen($nombre) < 5 ) {
+ $result['new_name'] = "El nombre tiene que tener una longitud de al menos 5 caracteres.";
+ }
+
+ $password = $datos['pass'] ?? null;
+ if ( empty($password) || mb_strlen($password) < 5 ) {
+ $result['pass'] = "El password tiene que tener una longitud de al menos 5 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);
+ if (!$user) {
+ $result[] = "El usuario no existe.";
+ } else {
+ $bd->changeUserName(unserialize($_SESSION['user'])->getId(), $username);
+ $user = $bd->selectUser($username, $password);
+ if (!$user){
+ $result[] = "Ha ocurrido un probrema al actualizar el nombre de usuario.";
+ }else{
+ $_SESSION['user'] = serialize($user);
+ $_SESSION["nombre"] = $user->getName();
+ $result = './?option=manage_profile';
+ }
+ }
+ }
+ return $result;
+ }
+
+ protected function test_input($input){
+ return htmlspecialchars(trim(strip_tags($input)));
+ }
+}
?>
\ No newline at end of file
diff --git a/panel_user/panelUser.php b/panel_user/panelUser.php
index 2f141b0..0c65c34 100644
--- a/panel_user/panelUser.php
+++ b/panel_user/panelUser.php
@@ -31,58 +31,26 @@
$formCN = new FormChangeName();
$htmlFormChangeName = $formCN->gestiona();
+
+ $formCP = new FormChangePass();
+ $htmlFormChangePass = $formCP->gestiona();
+
+ $formCE = new FormChangeEmail();
+ $htmlFormChangeEmail = $formCE->gestiona();
return $reply = '
Cambiar nombre de usuario
'.$htmlFormChangeName.'
-
-
-
Cambiar email de usuario
-
-
'."\n";
+
+
Cambiar contraseña
+ '.$htmlFormChangePass.'
+
+
+
Cambiar email de usuario
+ '.$htmlFormChangeEmail.'
+ '."\n";
}
//User purchase history.