2021-05-03 15:11:59 +02:00
|
|
|
<?php
|
2021-05-09 16:27:21 +02:00
|
|
|
require_once('../assets/php/form.php');
|
|
|
|
include_once('../assets/php/common/user.php');
|
2021-05-03 15:11:59 +02:00
|
|
|
|
2021-05-09 16:27:21 +02:00
|
|
|
class FormChangeEmail extends Form {
|
2021-05-09 16:46:12 +02:00
|
|
|
//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])?)*$';
|
2021-05-09 16:27:21 +02:00
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$options = array("action" => "./?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 = '<div class="row">'.$htmlErroresGlobales.'
|
2021-05-09 20:31:54 +02:00
|
|
|
<fieldset id="email_usuario">
|
|
|
|
<legend>Nuevo email de usuario</legend>
|
2021-05-10 11:52:45 +02:00
|
|
|
<input type="text" name="new_email" id="new_email" value="" placeholder="Nuevo Email" required/>
|
|
|
|
<input type="password" name="pass" id="pass" value="" placeholder="Contraseña" required/>
|
|
|
|
<input type="password" name="repass" id="repass" value="" placeholder="Repita la contraseña" required/>
|
2021-05-09 20:31:54 +02:00
|
|
|
</fieldset>
|
|
|
|
<div class="actions">
|
|
|
|
<input type="submit" id="submit" value="Cambiar Nombre de Usuario" class="primary" />
|
|
|
|
<input type="reset" id="reset" value="Borrar" />
|
|
|
|
</div>
|
|
|
|
</div>';
|
2021-05-09 16:27:21 +02:00
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO */
|
|
|
|
protected function procesaFormulario($datos){
|
|
|
|
$result = array();
|
|
|
|
|
2021-05-09 16:46:12 +02:00
|
|
|
$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.";
|
2021-05-09 16:27:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$password = $datos['pass'] ?? null;
|
2021-05-09 21:59:52 +02:00
|
|
|
if ( empty($password) || mb_strlen($password) < 4 ) {
|
2021-05-10 11:52:45 +02:00
|
|
|
$result['pass'] = "El password tiene que tener\n una longitud de al menos\n 4 caracteres.";
|
2021-05-09 16:27:21 +02:00
|
|
|
}
|
|
|
|
$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.";
|
2021-05-09 21:59:52 +02:00
|
|
|
$_SESSION['message'] = "<div class='row'>
|
|
|
|
<div class='column side'></div>
|
|
|
|
<div class='column middle'>
|
|
|
|
<div class='code info'>
|
|
|
|
<h1>Ha ocurrido un probrema</h1><hr />
|
|
|
|
<p>No hemos podido actualizar su nombre de usuario.</p>
|
|
|
|
<a href=''><button>Cerrar Mensaje</button></a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class='column side'></div>
|
|
|
|
</div>
|
|
|
|
";
|
2021-05-09 16:27:21 +02:00
|
|
|
} else {
|
2021-05-09 16:46:12 +02:00
|
|
|
//$bd->changeUserName(unserialize($_SESSION['user'])->getId(), $username);
|
2021-05-09 16:27:21 +02:00
|
|
|
$user = $bd->selectUser($username, $password);
|
|
|
|
if (!$user){
|
2021-05-09 16:46:12 +02:00
|
|
|
$result[] = "Ha ocurrido un probrema al actualizar el email de usuario.";
|
2021-05-09 16:27:21 +02:00
|
|
|
}else{
|
|
|
|
$_SESSION['user'] = serialize($user);
|
2021-05-09 16:46:12 +02:00
|
|
|
$_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>
|
|
|
|
";
|
2021-05-09 16:27:21 +02:00
|
|
|
$result = './?option=manage_profile';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function test_input($input){
|
|
|
|
return htmlspecialchars(trim(strip_tags($input)));
|
|
|
|
}
|
|
|
|
}
|
2021-05-03 15:11:59 +02:00
|
|
|
?>
|