Add files via upload

This commit is contained in:
Fernando Méndez 2021-05-09 16:46:12 +02:00 committed by GitHub
parent bb94e30282
commit 6d0619f5ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 17 deletions

View File

@ -3,6 +3,8 @@ require_once('../assets/php/form.php');
include_once('../assets/php/common/user.php'); include_once('../assets/php/common/user.php');
class FormChangeEmail extends Form { 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() { public function __construct() {
$options = array("action" => "./?option=manage_profile"); $options = array("action" => "./?option=manage_profile");
@ -44,9 +46,9 @@ class FormChangeEmail extends Form {
protected function procesaFormulario($datos){ protected function procesaFormulario($datos){
$result = array(); $result = array();
$nombre = $datos['new_name'] ?? null; $email = $datos['new_email'] ?? null;
if ( empty($nombre) || mb_strlen($nombre) < 5 ) { if ( empty($email) || !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $email) ) {
$result['new_name'] = "El nombre tiene que tener una longitud de al menos 5 caracteres."; $result['new_email'] = "El nuevo email no es válido.";
} }
$password = $datos['pass'] ?? null; $password = $datos['pass'] ?? null;
@ -64,13 +66,24 @@ class FormChangeEmail extends Form {
if (!$user) { if (!$user) {
$result[] = "El usuario no existe."; $result[] = "El usuario no existe.";
} else { } else {
$bd->changeUserName(unserialize($_SESSION['user'])->getId(), $username); //$bd->changeUserName(unserialize($_SESSION['user'])->getId(), $username);
$user = $bd->selectUser($username, $password); $user = $bd->selectUser($username, $password);
if (!$user){ 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{ }else{
$_SESSION['user'] = serialize($user); $_SESSION['user'] = serialize($user);
$_SESSION["nombre"] = $user->getName(); $_SESSION['message'] = "<div class='row'>
<div class='column side'></div>
<div class='column middle'>
<div class='code info'>
<h1>Operacion realizada con exito</h1><hr />
<p>Se ha modificado su email correctamente.</p>
<a href=''><button>Cerrar Mensaje</button></a>
</div>
</div>
<div class='column side'></div>
</div>
";
$result = './?option=manage_profile'; $result = './?option=manage_profile';
} }
} }

View File

@ -44,8 +44,8 @@ class FormChangeName extends Form {
$result = array(); $result = array();
$nombre = $datos['new_name'] ?? null; $nombre = $datos['new_name'] ?? null;
if ( empty($nombre) || mb_strlen($nombre) < 5 ) { if ( empty($nombre) || mb_strlen($nombre) < 4 ) {
$result['new_name'] = "El nombre tiene que tener una longitud de al menos 5 caracteres."; $result['new_name'] = "El nombre tiene que tener una longitud de al menos 4 caracteres.";
} }
$password = $datos['pass'] ?? null; $password = $datos['pass'] ?? null;
@ -54,7 +54,7 @@ class FormChangeName extends Form {
} }
$password2 = $datos['repass'] ?? null; $password2 = $datos['repass'] ?? null;
if ( empty($password2) || strcmp($password, $password2) !== 0 ) { if ( empty($password2) || strcmp($password, $password2) !== 0 ) {
$result['repass'] = "Los passwords deben coincidir"; $result['repass'] = "Los passwords deben coincidir.";
} }
if (count($result) === 0) { if (count($result) === 0) {
@ -70,6 +70,18 @@ class FormChangeName extends Form {
}else{ }else{
$_SESSION['user'] = serialize($user); $_SESSION['user'] = serialize($user);
$_SESSION["nombre"] = $user->getName(); $_SESSION["nombre"] = $user->getName();
$_SESSION['message'] = "<div class='row'>
<div class='column side'></div>
<div class='column middle'>
<div class='code info'>
<h1>Operacion realizada con exito</h1><hr />
<p>Se ha modificado su nombre de usuario correctamente.</p>
<a href=''><button>Cerrar Mensaje</button></a>
</div>
</div>
<div class='column side'></div>
</div>
";
$result = './?option=manage_profile'; $result = './?option=manage_profile';
} }
} }

View File

@ -44,9 +44,9 @@ class FormChangePass extends Form {
protected function procesaFormulario($datos){ protected function procesaFormulario($datos){
$result = array(); $result = array();
$nombre = $datos['new_name'] ?? null; $old_pass = $datos['old_pass'] ?? null;
if ( empty($nombre) || mb_strlen($nombre) < 5 ) { if ( empty($old_pass) || mb_strlen($old_pass) < 5 ) {
$result['new_name'] = "El nombre tiene que tener una longitud de al menos 5 caracteres."; $result['old_pass'] = "El password tiene que tener una longitud de al menos 5 caracteres.";
} }
$password = $datos['pass'] ?? null; $password = $datos['pass'] ?? null;
@ -55,7 +55,7 @@ class FormChangePass extends Form {
} }
$password2 = $datos['repass'] ?? null; $password2 = $datos['repass'] ?? null;
if ( empty($password2) || strcmp($password, $password2) !== 0 ) { if ( empty($password2) || strcmp($password, $password2) !== 0 ) {
$result['repass'] = "Los passwords deben coincidir"; $result['repass'] = "Los passwords deben coincidir.";
} }
if (count($result) === 0) { if (count($result) === 0) {
@ -64,13 +64,23 @@ class FormChangePass extends Form {
if (!$user) { if (!$user) {
$result[] = "El usuario no existe."; $result[] = "El usuario no existe.";
} else { } else {
$bd->changeUserName(unserialize($_SESSION['user'])->getId(), $username); //$bd->changeUserName(unserialize($_SESSION['user'])->getId(), $username);
$user = $bd->selectUser($username, $password); $user = $bd->selectUser($username, $password);
if (!$user){ if (!$user){
$result[] = "Ha ocurrido un probrema al actualizar el nombre de usuario."; $result[] = "Ha ocurrido un probrema al actualizar contraseña.";
}else{ }else{
$_SESSION['user'] = serialize($user); $_SESSION['message'] = "<div class='row'>
$_SESSION["nombre"] = $user->getName(); <div class='column side'></div>
<div class='column middle'>
<div class='code info'>
<h1>Operacion realizada con exito</h1><hr />
<p>Se ha modificado su contraseña correctamente.</p>
<a href=''><button>Cerrar Mensaje</button></a>
</div>
</div>
<div class='column side'></div>
</div>
";
$result = './?option=manage_profile'; $result = './?option=manage_profile';
} }
} }

View File

@ -68,6 +68,7 @@
<!-- Contents --> <!-- Contents -->
<div class="row"> <div class="row">
<?php <?php
$template->print_msg();
echo $reply; echo $reply;
?> ?>
</div> </div>

View File

@ -25,6 +25,7 @@
//Manage the user account. //Manage the user account.
static function manage(){ static function manage(){
require_once('./includes/formChangePass.php'); require_once('./includes/formChangePass.php');
require_once('./includes/formChangeEmail.php'); require_once('./includes/formChangeEmail.php');
require_once('./includes/formChangeName.php'); require_once('./includes/formChangeName.php');