From 6d0619f5ece433944ab645270313c9ef12d5f6d4 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:46:12 +0200 Subject: [PATCH] Add files via upload --- panel_user/includes/formChangeEmail.php | 25 ++++++++++++++++++------ panel_user/includes/formChangeName.php | 18 ++++++++++++++--- panel_user/includes/formChangePass.php | 26 +++++++++++++++++-------- panel_user/index.php | 1 + panel_user/panelUser.php | 1 + 5 files changed, 54 insertions(+), 17 deletions(-) diff --git a/panel_user/includes/formChangeEmail.php b/panel_user/includes/formChangeEmail.php index 5d83137..0ee1c96 100644 --- a/panel_user/includes/formChangeEmail.php +++ b/panel_user/includes/formChangeEmail.php @@ -3,6 +3,8 @@ require_once('../assets/php/form.php'); include_once('../assets/php/common/user.php'); class FormChangeEmail extends Form { + //Constants: + const HTML5_EMAIL_REGEXP = '^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$'; public function __construct() { $options = array("action" => "./?option=manage_profile"); @@ -44,9 +46,9 @@ class FormChangeEmail extends Form { 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."; + $email = $datos['new_email'] ?? null; + if ( empty($email) || !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $email) ) { + $result['new_email'] = "El nuevo email no es válido."; } $password = $datos['pass'] ?? null; @@ -64,13 +66,24 @@ class FormChangeEmail extends Form { if (!$user) { $result[] = "El usuario no existe."; } else { - $bd->changeUserName(unserialize($_SESSION['user'])->getId(), $username); + //$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."; + $result[] = "Ha ocurrido un probrema al actualizar el email de usuario."; }else{ $_SESSION['user'] = serialize($user); - $_SESSION["nombre"] = $user->getName(); + $_SESSION['message'] = "
+
+
+
+

Operacion realizada con exito


+

Se ha modificado su email correctamente.

+ +
+
+
+
+ "; $result = './?option=manage_profile'; } } diff --git a/panel_user/includes/formChangeName.php b/panel_user/includes/formChangeName.php index 756906c..d412084 100644 --- a/panel_user/includes/formChangeName.php +++ b/panel_user/includes/formChangeName.php @@ -44,8 +44,8 @@ class FormChangeName extends Form { $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."; + if ( empty($nombre) || mb_strlen($nombre) < 4 ) { + $result['new_name'] = "El nombre tiene que tener una longitud de al menos 4 caracteres."; } $password = $datos['pass'] ?? null; @@ -54,7 +54,7 @@ class FormChangeName extends Form { } $password2 = $datos['repass'] ?? null; if ( empty($password2) || strcmp($password, $password2) !== 0 ) { - $result['repass'] = "Los passwords deben coincidir"; + $result['repass'] = "Los passwords deben coincidir."; } if (count($result) === 0) { @@ -70,6 +70,18 @@ class FormChangeName extends Form { }else{ $_SESSION['user'] = serialize($user); $_SESSION["nombre"] = $user->getName(); + $_SESSION['message'] = "
+
+
+
+

Operacion realizada con exito


+

Se ha modificado su nombre de usuario correctamente.

+ +
+
+
+
+ "; $result = './?option=manage_profile'; } } diff --git a/panel_user/includes/formChangePass.php b/panel_user/includes/formChangePass.php index af9fdd2..0225822 100644 --- a/panel_user/includes/formChangePass.php +++ b/panel_user/includes/formChangePass.php @@ -44,9 +44,9 @@ class FormChangePass extends Form { 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."; + $old_pass = $datos['old_pass'] ?? null; + if ( empty($old_pass) || mb_strlen($old_pass) < 5 ) { + $result['old_pass'] = "El password tiene que tener una longitud de al menos 5 caracteres."; } $password = $datos['pass'] ?? null; @@ -55,7 +55,7 @@ class FormChangePass extends Form { } $password2 = $datos['repass'] ?? null; if ( empty($password2) || strcmp($password, $password2) !== 0 ) { - $result['repass'] = "Los passwords deben coincidir"; + $result['repass'] = "Los passwords deben coincidir."; } if (count($result) === 0) { @@ -64,13 +64,23 @@ class FormChangePass extends Form { if (!$user) { $result[] = "El usuario no existe."; } else { - $bd->changeUserName(unserialize($_SESSION['user'])->getId(), $username); + //$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."; + $result[] = "Ha ocurrido un probrema al actualizar contraseña."; }else{ - $_SESSION['user'] = serialize($user); - $_SESSION["nombre"] = $user->getName(); + $_SESSION['message'] = "
+
+
+
+

Operacion realizada con exito


+

Se ha modificado su contraseña correctamente.

+ +
+
+
+
+ "; $result = './?option=manage_profile'; } } diff --git a/panel_user/index.php b/panel_user/index.php index 25acd87..e462648 100644 --- a/panel_user/index.php +++ b/panel_user/index.php @@ -68,6 +68,7 @@
print_msg(); echo $reply; ?>
diff --git a/panel_user/panelUser.php b/panel_user/panelUser.php index 0c65c34..15631ae 100644 --- a/panel_user/panelUser.php +++ b/panel_user/panelUser.php @@ -25,6 +25,7 @@ //Manage the user account. static function manage(){ + require_once('./includes/formChangePass.php'); require_once('./includes/formChangeEmail.php'); require_once('./includes/formChangeName.php');