Add files via upload

This commit is contained in:
Fernando Méndez 2021-05-12 10:40:22 +02:00 committed by GitHub
parent b6ea25caa1
commit 1b64bce911
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 170 additions and 178 deletions

View File

@ -328,6 +328,13 @@
text-align: center; text-align: center;
height: 250px; height: 250px;
} }
.code.info #register{
border: 1px solid#d3ebff;
}
.code.info #register:hover {
color: #1f2c3d;
background-color: #d3ebff;
}
.code.showtimes{ .code.showtimes{
height: 600px; height: 600px;
} }
@ -532,7 +539,7 @@
color: rgb(138, 150, 32); color: rgb(138, 150, 32);
} }
#submit { #submit, #register {
width: 100%; width: 100%;
height: 35px; height: 35px;
border: 1px solid #dadada; border: 1px solid #dadada;
@ -544,7 +551,7 @@
filter: brightness(105%); filter: brightness(105%);
cursor: pointer; cursor: pointer;
} }
#submit:hover { #submit:hover, #register:hover {
color: #dadada; color: #dadada;
background-color: #1f2c3d; background-color: #1f2c3d;
} }

View File

@ -327,6 +327,9 @@ main img {
text-align: center; text-align: center;
height: 250px; height: 250px;
} }
.code.info #register{
border: 1px solid#d3ebff;
}
.code.showtimes{ .code.showtimes{
height: 600px; height: 600px;
} }
@ -526,7 +529,7 @@ textarea {
color: rgb(138, 150, 32); color: rgb(138, 150, 32);
} }
#submit { #submit, #register {
width: 100%; width: 100%;
height: 35px; height: 35px;
border: 1px solid #000000; border: 1px solid #000000;
@ -538,7 +541,7 @@ textarea {
filter: brightness(105%); filter: brightness(105%);
cursor: pointer; cursor: pointer;
} }
#submit:hover { #submit:hover, #register:hover {
background-color: #d3ebff; background-color: #d3ebff;
} }

View File

@ -33,17 +33,18 @@
return ""; return "";
} }
public static function create_session($cinema, $hall, $start, $date, $film, $price, $format,$repeat){ public static function create_session($session){
$bd = new SessionDAO('complucine'); $bd = new SessionDAO('complucine');
if($bd ){ if($bd ){
if(!$bd->searchSession($cinema, $hall, $start, $date)){ if(!$bd->searchSession($session['cinema'], $session['hall'],$session['start'],$session['date'])){
$bd->createSession(null,$film, $hall, $cinema, $date, $start, $price, $format); $bd->createSession(null,$session['film'], $session['hall'], $session['cinema'], $session['date'],
$session['start'], $session['price'], $session['format']);
if($repeat > "0") { if($session['repeat'] > "0") {
$repeats = $repeat; $repeat = $session['repeat'];
$repeat = $repeat - 1; $session['repeat'] = $session['repeat'] - 1;
$date = date('Y-m-d', strtotime( $date . ' +1 day') ); $session['date'] = date('Y-m-d', strtotime( $session['date'] . ' +1 day') );
self::create_session($cinema, $hall, $start, $date, $film, $price, $format,$repeat); self::create_session($session);
return "Se han creado las ".$repeat ." sesiones con exito"; return "Se han creado las ".$repeat ." sesiones con exito";
} }
@ -55,13 +56,13 @@
} else return "Error al conectarse a la base de datos"; } else return "Error al conectarse a la base de datos";
} }
public static function edit_session($cinema, $or_hall, $or_date, $or_start, $hall, $start, $date, $film, $price, $format){ public static function edit_session($session){
$bd = new SessionDAO('complucine'); $bd = new SessionDAO('complucine');
if($bd ){ if($bd ){
if($bd->searchSession($cinema, $or_hall, $or_start, $or_date)){ if($bd->searchSession($session['cinema'], $session['origin_hall'],$session['origin_start'],$session['origin_date'])){
$origin = array("cinema" => $cinema,"hall" => $or_hall,"start" => $or_start,"date" => $or_date); $origin = array("cinema" => $session['cinema'],"hall" => $session['origin_hall'],"start" => $session['origin_start'],"date" => $session['origin_date']);
$bd->editSession($film, $hall, $cinema, $date, $bd->editSession($session['film'], $session['hall'], $session['cinema'], $session['date'],
$start, $price, $format,$origin); $session['start'], $session['price'], $session['format'],$origin);
return "Se ha editado la session con exito"; return "Se ha editado la session con exito";
} else } else
return "Esta session no existe"; return "Esta session no existe";
@ -69,11 +70,11 @@
} else return "Error al conectarse a la base de datos"; } else return "Error al conectarse a la base de datos";
} }
public static function delete_session($cinema, $hall, $start, $date){ public static function delete_session($session){
$bd = new SessionDAO('complucine'); $bd = new SessionDAO('complucine');
if($bd ){ if($bd ){
if($bd->searchSession($cinema, $hall, $start, $date)){ if($bd->searchSession($session['cinema'], $session['hall'],$session['start'],$session['date'])){
$bd->deleteSession($hall, $cinema, $date, $start); $bd->deleteSession($session['hall'], $session['cinema'], $session['date'], $session['start']);
return "Se ha eliminado la session con exito"; return "Se ha eliminado la session con exito";
} else } else
return "Esta session no existe"; return "Esta session no existe";

View File

@ -46,4 +46,9 @@
* @see http://php.net/manual/en/language.types.callable.php * @see http://php.net/manual/en/language.types.callable.php
*/ */
register_shutdown_function(array($app, 'shutdown')); register_shutdown_function(array($app, 'shutdown'));
//Depuración (BORRAR):
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?> ?>

View File

@ -335,4 +335,9 @@ abstract class Form {
return $result; return $result;
} }
//Test some form input.
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
} }

View File

@ -24,12 +24,12 @@ class FormLogin extends Form {
$html = "<div class='row'> $html = "<div class='row'>
<fieldset id='nombre_usuario'><pre>".$htmlErroresGlobales."</pre> <fieldset id='nombre_usuario'><pre>".$htmlErroresGlobales."</pre>
<legend>Nuevo Nombre de usuario</legend> <legend>Datos Personales</legend>
<input type='text' name='name' id='name' value='' placeholder='Nombre' required/><pre>".$errorNombre."</pre> <input type='text' name='name' id='name' value='' placeholder='Nombre' required/><pre>".$errorNombre."</pre>
<input type='password' name='pass' id='pass' value='' placeholder='Contraseña' required/><pre>".$errorPassword."</pre> <input type='password' name='pass' id='pass' value='' placeholder='Contraseña' required/><pre>".$errorPassword."</pre>
</fieldset> </fieldset>
<div class='actions'> <div class='actions'>
<input type='submit' id='submit' value='Cambiar Nombre de Usuario' class='primary' /> <input type='submit' id='submit' value='Iniciar Sesión' class='primary' />
<input type='reset' id='reset' value='Borrar' /> <input type='reset' id='reset' value='Borrar' />
</div> </div>
</div>"; </div>";
@ -65,7 +65,7 @@ class FormLogin extends Form {
$_SESSION["login"] = true; $_SESSION["login"] = true;
$result = 'validate.php'; $result = 'validate.php';
} else { } else {
$result[] = "El usuario o el password no coinciden."; $result[] = "El usuario o el password\nno coinciden.";
} }
} else { } else {
$result[] = "Error al conectar con la BD."; $result[] = "Error al conectar con la BD.";
@ -75,10 +75,6 @@ class FormLogin extends Form {
return $result; return $result;
} }
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
//Returns validation response: //Returns validation response:
static public function getReply() { static public function getReply() {

View File

@ -17,7 +17,7 @@
$isLogin = $view->getIsLogin(); $isLogin = $view->getIsLogin();
//Forms: //Forms:
require('includes/formLogin.php'); require('includes/formLogin.php');
require('../register/includes/formRegister.php'); require($prefix.'register/includes/formRegister.php');
$formLogin = new FormLogin(); $formLogin = new FormLogin();
$htmlFormLogin = $formLogin->gestiona(); $htmlFormLogin = $formLogin->gestiona();
$formRegister = new FormRegister(); $formRegister = new FormRegister();

View File

@ -1,148 +1,107 @@
<?php <?php
require_once($prefix.'assets/php/common/session_dao.php'); require_once($prefix.'assets/php/common/session_dao.php');
require_once($prefix.'assets/php/common/film_dao.php');
require_once($prefix.'assets/php/common/session.php'); require_once($prefix.'assets/php/common/session.php');
require_once($prefix.'assets/php/form.php'); require_once($prefix.'assets/php/form.php');
//Receive data from froms and prepare the correct response //Receive data from froms and prepare the correct response
class FormSession extends Form { class FormSession extends Form {
private $option;
//Constructor: //Constructor:
public function __construct($option) { public function __construct() {
$this->option = $option; parent::__construct('formSession');
$options = array("action" => "./?state=".$option);
parent::__construct('formSession',$options);
} }
//TODO Edit session no funciona correctamente con el seleccionar una pelicula distinta, hay que guardar la id de la sesion de alguna forma y usarla o guardar en la sesion //TODO Edit session no funciona correctamente con el seleccionar una pelicula distinta, hay que guardar la id de la sesion de alguna forma y usarla o guardar en la sesion
protected function generaCamposFormulario($data, $errores = array()){ public static function generaCampoFormulario($data, $errores = array()){
$filmList = new Film_DAO('complucine'); $cinema = $data['cinema'] ?? '';
$films = $filmList->allFilmData(); $film = $data['film'] ?? '';
$hall = $data['hall'] ?? '';
$date = $data['date'] ?? '';
$start = $data['start'] ?? '';
$price = $data['price'] ?? '';
$format = $data['format'] ?? '';
if($this->option == "new_session") { $htmlform .= '<div class="column left">
$cinema = $data['cinema'] ?? $_SESSION["cinema"]; <form method="post" id="'.$data['option'].'" action="./includes/processForm.php"\>
$film = $data['film'] ?? 1;
$hall = $data['hall'] ?? '';
$date = $data['date'] ?? '';
$start = $data['start'] ?? '';
$price = $data['price'] ?? '';
$format = $data['format'] ?? '';
}
else {
$cinema = $data['cinema'] ?? $_SESSION["cinema"];
$film = $data['film'] ?? $_POST["film"];
$hall = $data['hall'] ?? $_POST["hall"];
$date = $data['date'] ?? $_POST["date"];
$start = $data['start'] ?? $_POST["start"];
$price = $data['price'] ?? $_POST["price"];
$format = $data['format'] ?? $_POST["format"];
}
$or_hall = $data["or_hall"] ?? $hall;
$or_date = $data["or_date"] ?? $date;
$or_start = $data["or_start"] ?? $start;
$htmlErroresGlobales = self::generaListaErroresGlobales($errores);
$html .= '<div class="column left">
'.$htmlErroresGlobales.'
<fieldset> <fieldset>
<legend>Datos</legend> <legend>Datos</legend>
<input type="number" step="0.01" name="price" value="'.$price.'" min="0" placeholder="Precio de la entrada" required/> <br> <input type="number" step="0.01" name="price" value="'.$price.'" min="0" placeholder="Precio de la entrada" required/> <br>
<input type="text" name="format" value="'.$format.'" placeholder="Formato de pelicula" required/> <br> <input type="text" name="format" value="'.$format.'" placeholder="Formato de pelicula" required/> <br>
<input type="hidden" name="film" value="'.$film.'"/> <input type="hidden" name="film" value="'.$film["idfilm"].'"/>
<select name="hall" class="button large">'; <select name="hall" class="button large">';
foreach(Hall::getListHalls($cinema) as $hll){ foreach(Hall::getListHalls($cinema) as $hll){
if($hll->getNumber() == $hall){ if($hll->getNumber() == $hall){
$html.= ' $htmlform.= '
<option value="'. $hll->getNumber() .'"selected> Sala '. $hll->getNumber() .'</option> '; <option value="'. $hll->getNumber() .'"selected> Sala '. $hll->getNumber() .'</option> ';
}else{ }else{
$html.= ' $htmlform.= '
<option value="'. $hll->getNumber() .'"> Sala '. $hll->getNumber() .'</option>'; <option value="'. $hll->getNumber() .'"> Sala '. $hll->getNumber() .'</option>';
} }
} }
$html.= ' $htmlform.= '
</select> </select>
<input type="hidden" name="or_hall" value="'.$or_hall.'"/>
</fieldset> </fieldset>
<fieldset> <fieldset>
<legend>Horario</legend> <legend>Horario</legend>
<input type="time" name="start" value="'.$start.'" placeholder="Hora de inicio" required/> <br> <input type="time" name="start" value="'.$start.'" placeholder="Hora de inicio" required/> <br>
<input type="hidden" name="or_start" value="'.$or_start.'"/>
<input type="date" name="date" value="'.$date.'" placeholder="Fecha de inicio" required/> <br> <input type="date" name="date" value="'.$date.'" placeholder="Fecha de inicio" required/> <br>
<input type="hidden" name="or_date" value="'.$or_date.'"/>
</fieldset> </fieldset>
'; ';
if($film){ if($film){
if($this->option == "new_session") if($data['option'] == "new_session")
$html .= '<input type="number" name="repeat" value="" min="0" title="Añadir esta sesion durante los proximos X dias" min="0" max="31" placeholder="Añadir X dias"/> <br> $htmlform .= '<input type="number" name="repeat" value="" min="0" title="Añadir esta sesion durante los proximos X dias" min="0" max="31" placeholder="Añadir X dias"/> <br>
<button type="submit" id="submit" name="sumbit" class="button large">Crear</button><br>'; <button type="submit" name="new_session" class="button large">Crear</button><br>';
if($this->option == "edit_session"){ if($data['option'] == "edit_session"){
$html .= ' if(!$_SESSION["or_hall"]) $_SESSION["or_hall"] = $hall;
<button type="submit" id="submit" name="sumbit" class="button large">Editar</button><br> if(!$_SESSION["or_date"]) $_SESSION["or_date"] = $date;
<button type="submit" id="submit" name="delete" class="primary">Borrar</button><br>'; if(!$_SESSION["or_start"])$_SESSION["or_start"] = $start;
$htmlform .= '
<button type="submit" name="edit_session" class="button large">Editar</button><br>
<button type="submit" name="delete_session" class="primary">Borrar</button><br>';
} }
} }
$html .= ' $htmlform .= "
<input type="reset" value="Limpiar Campos" > <input type='reset' value='Limpiar Campos' >
</form>
</div> </div>
<div class="column side"> <div class='column side'>";
<select name="film" class="button large">'; if($film["tittle"]){
foreach($films as $f){ $htmlform .= " <section id='".$film["tittle"]."'>
if($f->getId() == $film){ <div class='code showtimes'>
$html .= "<option value=\"". $f->getId() ." \"selected> " . $f->getId() . "|" . $f->getTittle() ." Idioma: " . $f->getLanguage() . "</option>"; <div class='image'><img src='../img/".$film["tittle"].".jpg' alt='".$film["tittle"]."' /></div>
}else{ <h2>".str_replace('_', ' ',$film["tittle"])."</h2>
$html .= "<option value=\"". $f->getId() ." \"> " . $f->getId() . "|" . $f->getTittle() ." Idioma: " . $f->getLanguage() . "</option>"; <hr />
} <div class='blockquote'>
<p>".$film["description"]."</p>
</div>
<p>Duración: ".$film["duration"]." minutos</p>
</div>
</section>
";
} }
$htmlform .= '<button type="submit" name="select_films" form="'.$data['option'].'" formaction="?state=select_film&option='.$data['option'].'" class="button large">Seleccionar una Pelicula</button><br>
return $html; </div>
';
return $htmlform;
} }
//Methods: //Methods:
//Process form: //Process form:
protected function procesaFormulario($data){ public static function processesForm($data){
$result = array(); if($data["option"] == "new_session"){
$_SESSION['msg'] = Session::create_session($data);
$film = $data['film'] ; header( "Location: ../?state=success" );
$hall = $data['hall'] ; }else if($data["option"] == "edit_session"){
$date = $data['date'] ; $_SESSION['msg'] = Session::edit_session($data);
$start = $data['start']; header( "Location: ../?state=success" );
$price = $data['price'] ; }
$format = $data['format'] ?? null ; else if($data["option"] == "delete_session") {
$repeat = $data['repeat'] ?? 0; $_SESSION['msg'] = Session::delete_session($data);
$or_hall = $data["or_hall"] ; header( "Location: ../?state=success" );
$or_date = $data["or_date"] ;
$or_start = $data["or_start"] ;
if (($price == 0 || empty($price))&& isset($data["sumbit"]) ) {
$result['price'] = "<li> No puede haber 0 euros. </li> <br>";
}
if (empty($format) && isset($data["sumbit"])) {
$result['format'] = "<li> El formato no puede estar vacio. </li> <br>";
}
if (count($result) === 0 && isset($data["sumbit"]) ) {
if($this->option == "new_session"){
$_SESSION['msg'] = Session::create_session($_SESSION["cinema"], $hall, $start, $date, $film, $price, $format,$repeat);
$result = './?state=success';
}
if($this->option == "edit_session"){
$_SESSION['msg'] = Session::edit_session($_SESSION["cinema"], $or_hall, $or_date, $or_start, $hall, $start, $date, $film, $price, $format);
$result = './?state=success';
}
}
if(!isset($result['hall']) && !isset($result['start']) && !isset($result['date']) && isset($data["delete"])) {
$_SESSION['msg'] = Session::delete_session($_SESSION["cinema"], $or_hall, $or_start, $or_date);
$result = './?state=success';
} }
return $result;
} }
} }

View File

@ -1,4 +1,8 @@
<?php <?php
ini_set('display_errors', 0);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
//General Config File: //General Config File:
require_once('../assets/php/config.php'); require_once('../assets/php/config.php');
//Controller file: //Controller file:

View File

@ -183,18 +183,48 @@
} }
static function new_session(){ static function new_session(){
$formSession = new FormSession("new_session"); echo "inicio";
if(isset($_POST["new_session"])){
$data = array("option" => "new_session","hall" => $_POST['hall'],"cinema" => $_SESSION["cinema"],"date" => $_POST['date']);
}else if(isset($_POST["select_film"])){
$film = array("idfilm" => $_POST["id"],"tittle" => $_POST["tittle"], "description" => $_POST["description"], "duration" => $_POST["duration"]);
$data = array("option" => "new_session","hall" => $_POST['hall'],"cinema" => $_SESSION["cinema"],"date" => $_POST['date'],"film" => $film, "start" => $_POST['start']
, "price" => $_POST['price'], "format" => $_POST['format']);
}
if($data){
$panel = '<h1>Crear una sesión.</h1><hr /></br>
'.FormSession::generaCampoFormulario($data, null);
}else $panel = self::warning();
$panel = '<h1>Crear una sesion.</h1><hr/></br>'
.$formSession->gestiona();
return $panel; return $panel;
} }
static function edit_session(){ static function edit_session(){
$formSession = new FormSession("edit_session"); if(isset($_POST["edit_session"])){
$panel = '<h1>Editar una sesion.</h1><hr/></br>' $_SESSION["or_hall"] = "";
.$formSession->gestiona(); $_SESSION["or_date"] = "";
$_SESSION["or_start"] = "";
$film = Session::getThisSessionFilm($_POST["film"]);
$data = array("option" => "edit_session","hall" => $_POST["hall"],"cinema" => $_SESSION["cinema"],"date" => $_POST['date'],"film" => $film,
"start" => $_POST['start'],"price" => $_POST['price'],"format" => $_POST['format']);
}else if(isset($_SESSION["session"])){
$film = array("idfilm" => $_POST["id"],"tittle" => $_POST["tittle"], "description" => $_POST["description"], "duration" => $_POST["duration"]);
$data = array("option" => "edit_session","hall" => $_POST['hall'],"cinema" => $_SESSION["cinema"],"date" => $_POST['date'],"film" => $film, "start" => $_POST['start']
, "price" => $_POST['price'], "format" => $_POST['format']);
}
if($data){
$panel = '<h1>Editar una sesión.</h1><hr /></br>
'.FormSession::generaCampoFormulario($data, null);
} else $panel = self::warning();
return $panel; return $panel;
} }

View File

@ -40,17 +40,17 @@ class FormChangeEmail extends Form {
protected function procesaFormulario($datos){ protected function procesaFormulario($datos){
$result = array(); $result = array();
$email = $datos['new_email'] ?? null; $email = $this->test_input($datos['new_email']) ?? null;
if ( empty($email) || !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $email) ) { if ( empty($email) || !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $email) ) {
$result['new_email'] = "El nuevo email no es válido."; $result['new_email'] = "El nuevo email no es válido.";
} }
$email2 = $datos['remail'] ?? null; $email2 = $this->test_input($datos['remail']) ?? null;
if ( empty($email2) || strcmp($email, $email2) !== 0 ) { if ( empty($email2) || strcmp($email, $email2) !== 0 ) {
$result['remail'] = "Los emails deben coincidir"; $result['remail'] = "Los emails deben coincidir";
} }
$password = $datos['pass'] ?? null; $password = $this->test_input($datos['pass']) ?? null;
if ( empty($password) || mb_strlen($password) < 4 ) { if ( empty($password) || mb_strlen($password) < 4 ) {
$result['pass'] = "El password tiene que tener\n una longitud de al menos\n 4 caracteres."; $result['pass'] = "El password tiene que tener\n una longitud de al menos\n 4 caracteres.";
} }

View File

@ -38,18 +38,18 @@ class FormChangeName extends Form {
protected function procesaFormulario($datos){ protected function procesaFormulario($datos){
$result = array(); $result = array();
$nombre = $datos['new_name'] ?? null; $nombre = $this->test_input($datos['new_name']) ?? null;
$nombre = strtolower($nombre); $nombre = strtolower($nombre);
if ( empty($nombre) || mb_strlen($nombre) < 3 || mb_strlen($nombre) > 8 ) { 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."; $result['new_name'] = "El nombre tiene que tener\n una longitud de al menos\n 3 caracteres\n y menos de 8 caracteres.";
} }
$nombre2 = $datos['rename'] ?? null; $nombre2 = $this->test_input($datos['rename']) ?? null;
if ( empty($nombre2) || strcmp($nombre, $nombre2) !== 0 ) { if ( empty($nombre2) || strcmp($nombre, $nombre2) !== 0 ) {
$result['rename'] = "Los nombres deben coincidir."; $result['rename'] = "Los nombres deben coincidir.";
} }
$password = $datos['pass'] ?? null; $password = $this->test_input($datos['pass']) ?? null;
if ( empty($password) || mb_strlen($password) < 4 ) { if ( empty($password) || mb_strlen($password) < 4 ) {
$result['pass'] = "El password tiene que tener\n una longitud de al menos\n 4 caracteres."; $result['pass'] = "El password tiene que tener\n una longitud de al menos\n 4 caracteres.";
} }
@ -99,9 +99,5 @@ class FormChangeName extends Form {
} }
return $result; return $result;
} }
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
} }
?> ?>

View File

@ -36,16 +36,16 @@ class FormChangePass extends Form {
protected function procesaFormulario($datos){ protected function procesaFormulario($datos){
$result = array(); $result = array();
$old_pass = $datos['old_pass'] ?? null; $old_pass = $this->test_input($datos['old_pass']) ?? null;
if ( empty($old_pass) || mb_strlen($old_pass) < 4 ) { if ( empty($old_pass) || mb_strlen($old_pass) < 4 ) {
$result['old_pass'] = "El password tiene que tener\n una longitud de al menos\n 4 caracteres."; $result['old_pass'] = "El password tiene que tener\n una longitud de al menos\n 4 caracteres.";
} }
$password = $datos['pass'] ?? null; $password = $this->test_input($datos['pass']) ?? null;
if ( empty($password) || mb_strlen($password) < 4 ) { if ( empty($password) || mb_strlen($password) < 4 ) {
$result['pass'] = "El password tiene que tener una\n longitud de al menos\n 4 caracteres."; $result['pass'] = "El password tiene que tener una\n longitud de al menos\n 4 caracteres.";
} }
$password2 = $datos['repass'] ?? null; $password2 = $this->test_input($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.";
} }
@ -87,9 +87,5 @@ class FormChangePass extends Form {
} }
return $result; return $result;
} }
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
} }
?> ?>

View File

@ -46,22 +46,22 @@ class FormDeleteAccount extends Form {
protected function procesaFormulario($datos){ protected function procesaFormulario($datos){
$result = array(); $result = array();
$nombre = $datos['name'] ?? null; $nombre = $this->test_input($datos['name']) ?? null;
$nombre = strtolower($nombre); $nombre = strtolower($nombre);
if ( empty($nombre) || mb_strlen($nombre) < 3 || mb_strlen($nombre) > 8 ) { 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."; $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; $email = $this->test_input($datos['email']) ?? null;
if ( empty($email) || !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $email) ) { if ( empty($email) || !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $email) ) {
$result['email'] = "El email no es válido."; $result['email'] = "El email no es válido.";
} }
$password = $datos['pass'] ?? null; $password = $this->test_input($datos['pass']) ?? null;
if ( empty($password) || mb_strlen($password) < 4 ) { if ( empty($password) || mb_strlen($password) < 4 ) {
$result['pass'] = "El password tiene que tener\n una longitud de al menos\n 4 caracteres."; $result['pass'] = "El password tiene que tener\n una longitud de al menos\n 4 caracteres.";
} }
$password2 = $datos['repass'] ?? null; $password2 = $this->test_input($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.";
} }
@ -87,9 +87,5 @@ class FormDeleteAccount extends Form {
} }
return $result; return $result;
} }
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
} }
?> ?>

View File

@ -12,8 +12,7 @@ class FormRegister extends Form {
//Constructor: //Constructor:
public function __construct() { public function __construct() {
$options = array("action" => "../register/register.php"); parent::__construct('formRegister');
parent::__construct('formRegister', $options);
} }
//Methods: //Methods:
@ -41,7 +40,7 @@ class FormRegister extends Form {
<label for='terms'><a href ='../fdicines/terms_conditions/' target='_blank'>Marque esta casilla para verificar que ha leído nuestros términos y condiciones del servicio.</a></label> <label for='terms'><a href ='../fdicines/terms_conditions/' target='_blank'>Marque esta casilla para verificar que ha leído nuestros términos y condiciones del servicio.</a></label>
</div> </div>
<div class='actions'> <div class='actions'>
<input type='submit' id='submit' value='Registrarse' class='primary' /> <input type='submit' name='register' id='register' value='Registrarse' class='primary' />
<input type='reset' id='reset' value='Borrar' /> <input type='reset' id='reset' value='Borrar' />
</div> </div>
</div>"; </div>";
@ -85,11 +84,11 @@ class FormRegister extends Form {
$_SESSION["nombre"] = $this->user->getName(); $_SESSION["nombre"] = $this->user->getName();
$_SESSION["rol"] = $this->user->getRol(); $_SESSION["rol"] = $this->user->getRol();
$_SESSION["login"] = true; $_SESSION["login"] = true;
$result = '../register/register.php'; $result = "../register/register.php";
} }
} }
else{ else{
$result[] = "El nombre de usuario ya existe."; $result[] = "El usuario ya existe.";
} }
} else { } else {
$result[] = "Error al conectar con la BD."; $result[] = "Error al conectar con la BD.";
@ -111,9 +110,8 @@ class FormRegister extends Form {
<a href='../../panel_{$_SESSION["rol"]}'><button>Mi Panel</button></a>\n"; <a href='../../panel_{$_SESSION["rol"]}'><button>Mi Panel</button></a>\n";
} }
else if(!isset($_SESSION["login"])){ else if(!isset($_SESSION["login"])){
$reply = "<h1>ERROR</h1><hr />". $reply = "<h1>ERROR</h1><hr />
"<p>Ha ocurrido un problema y no hemos podido completar el registro.</p> <p>Ha ocurrido un problema y no hemos podido completar el registro</p>
<p>Puede que el nombre de usuario ya esté registrado.</p>
<p>Vuelve a intetarlo o inicia sesión si tienes una cuenta de usuario.</p> <p>Vuelve a intetarlo o inicia sesión si tienes una cuenta de usuario.</p>
<a href='../login/'><button>Iniciar Sesión</button></a> <a href='../login/'><button>Iniciar Sesión</button></a>
<form method='post' action='../login/'><button name='register' id='register'>Registro</button></form>\n"; <form method='post' action='../login/'><button name='register' id='register'>Registro</button></form>\n";
@ -122,9 +120,5 @@ class FormRegister extends Form {
return $reply; return $reply;
} }
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
} }
?> ?>

View File

@ -4,8 +4,6 @@
//Login form validate: //Login form validate:
require_once('./includes/formRegister.php'); require_once('./includes/formRegister.php');
//$register = new FormRegister();
//$register->processesForm($_POST["name"], $_POST["email"], $_POST["pass"], $_POST["repass"]);
$reply = FormRegister::getReply(); $reply = FormRegister::getReply();
?> ?>
@ -38,6 +36,8 @@
<div class="code info"> <div class="code info">
<?php <?php
echo $reply; echo $reply;
//$formRegister = new FormRegister();
//echo $htmlFormRegister = $formRegister->gestiona();
?> ?>
</div> </div>
</div> </div>