Add files via upload

This commit is contained in:
Fernando Méndez 2021-04-16 12:57:37 +02:00 committed by GitHub
parent 1c41cdb32f
commit c0a43216fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 154 additions and 121 deletions

View File

@ -1,16 +1,16 @@
<!DOCTYPE HTML> <!DOCTYPE HTML>
<?php <?php
session_start(); //General Config File:
require_once('./assets/php/config.php');
//HTML template:
require_once('./assets/php/template.php');
$template = new Template();
$prefix = $template->get_prefix();
//List of the tittles of the movies: //List of the tittles of the movies:
include_once($prefix.'showtimes/includes/loadFilms.php'); require_once($prefix.'panel_admin/includes/film_dao.php');
$loadFilms = new loadFilms(); $films = new Film_DAO("complucine");
$films = $loadFilms->getFilms(); $films_array = $films->allFilmData();
$tittles = array();
foreach($films_array as $key => $value){
$tittles[$key] = $value->getTittle();
}
?> ?>
<!-- <!--
Práctica 2 - Sistemas Web | Grupo D Práctica 2 - Sistemas Web | Grupo D
@ -50,7 +50,7 @@
<h1>Últimos Estrenos</h1><hr /> <h1>Últimos Estrenos</h1><hr />
<?php <?php
$count = 0; $count = 0;
for($i = count($films)-4; $i < count($films); $i++){ for($i = count($tittles)-4; $i < count($tittles); $i++){
if($count%2===0){ if($count%2===0){
if($count != 0) echo "</div> if($count != 0) echo "</div>
"; ";
@ -59,7 +59,7 @@
} }
echo "<div class='zoom'> echo "<div class='zoom'>
<div class='columna'> <div class='columna'>
<a href='".$prefix."showtimes/#".$films[$i]."'><div class='image'><img src='img/".$films[$i].".jpg' alt='".$films[$i]."' /></div></a> <a href='".$prefix."showtimes/#".$tittles[$i]."'><div class='image'><img src='img/".$tittles[$i].".jpg' alt='".$tittles[$i]."' /></div></a>
</div> </div>
</div> </div>
"; ";
@ -72,11 +72,11 @@
<div class="column right"> <div class="column right">
<div class="galery"> <div class="galery">
<?php <?php
$count = rand(0, count($films)-1); $count = rand(0, count($tittles)-1);
$title = str_replace('_', ' ', $films[$count]); $title = str_replace('_', ' ', $tittles[$count]);
echo "<h1>{$title}</h1><hr /> echo "<h1>{$title}</h1><hr />
<div class='zoom'> <div class='zoom'>
<a href='".$prefix."showtimes/#".$films[$count]."'><div class='image main'><img src='img/".$films[$count].".jpg' alt='".$films[$count]."' /></div></a> <a href='".$prefix."showtimes/#".$tittles[$count]."'><div class='image main'><img src='img/".$tittles[$count].".jpg' alt='".$tittles[$count]."' /></div></a>
</div>\n"; </div>\n";
?> ?>
</div> </div>

View File

@ -1,73 +1,100 @@
<?php <?php
require_once('user_dao.php');
?> include_once($prefix.'login/includes/user_dao.php');
include_once($prefix.'assets/php/form.php');
<?php
class Register { class FormRegister extends Form {
// ATRIBUTOS //Constants:
private $name; 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])?)*$';
private $email;
private $password; //Atributes:
private $repassword; private $user; // User who is going to log-in.
private $rol; // Desde aqui solo se registran usuarios finales, seran rol "user" private $reply; // Validation response
private $id; // Generado en la BD? Aleatorio?
private $reply; //Constructor:
public function __construct() {
// CONSTRUCTOR parent::__construct('formRegister');
function __construct() {} $this->reply = array();
}
// METODOS
public function testReg() { //Methods:
$this->name = $this->test_input($_POST["name"]);
$this->email = $this->test_input($_POST["email"]); //Returns validation response:
$this->password = $this->test_input($_POST["pass"]); public function getReply() {
$this->repassword = $this->test_input($_POST["repass"]);
$this->rol = "user"; if(isset($_SESSION["login"])){
$this->id = "xxxx"; $name = strtoupper($_SESSION['nombre']);
$this->reply = "<h1>Bienvenido {$_SESSION['nombre']}</h1><hr />
// Creamos DAO <p>{$name}, has creado tu cuenta de usuario correctamente.</p>
$instanceDAO = new UserDAO('complucine'); <p>Usa los botones para navegar</p>
<a href='../'><button>Inicio</button></a>
// Creamos DTO <a href='../../panel_{$_SESSION["rol"]}'><button>Mi Panel</button></a>\n";
$uDTO = $instanceDAO->loadUser($this->id, $this->name, $this->email, $this->password, $this->rol); }
else if(!isset($_SESSION["login"])){
if($this->password == $this->repassword) { // Comprobacion de contrasenyas iguales $this->reply = "<h1>ERROR</h1><hr />".
$resultado = $instanceDAO->selectUser($uDTO->getName()); "<p>Ha ocurrido un problema y no hemos podido completar el registro.</p>
if($resultado->num_rows == 0) { // Comprobacion de que el usuario no existe ya en la BD <p>Vuelve a intetarlo o inicia sesión si tienesuna cuenta de usuario.</p>
// Se manda el usuario al DAO, que lo creara en la BD <a href='../login/'><button>Iniciar Sesión</button></a>
$instanceDAO->createUser($uDTO->getId(), $uDTO->getName(), $uDTO->getEmail(), $uDTO->getPass(), $uDTO->getRol()); <form method='post' action='../login/'><button name='register' id='register'>Registro</button></form>\n";
}
$this->reply = "<h1>¡Éxito en el registro!</h1><hr/>
<p>{$_POST['name']}, te has registrado correctamente.</p> return $this->reply;
<p>Puedes iniciar sesión en el siguiente enlace.</p> }
<br>
<a href='./index.php'><button>Iniciar sesión</button></a>\n"; //Process form:
} public function processesForm($name, $mail, $pass, $repass) {
else { $register = true;
$this->reply = "<h1>¡Ha ocurrido un error!</h1><hr/>". $name = $this->test_input($name);
"<p>¡Ya existe un usuario con este nombre!</p> $mail = $this->test_input($mail);
<p>Vuelve a intetarlo o prueba a inicia sesión.</p> $pass = $this->test_input($pass);
<a href='./'><button>Iniciar Sesión</button></a> $repass = $this->test_input($repass);
<form method='post' action='./'><button name='register' id='register'>Registro</button></form>\n";
} $username = isset($name) ? $name : null ;
$resultado->free(); if (!$username) {
} $register = false;
else { }
$this->reply = "<h1>¡Ha ocurrido un error!</h1><hr/>".
"<p>Los datos introducidos no son válidos.</p> $email = isset($mail) ? $mail : null ;
<p>Vuelve a intetarlo o prueba a inicia sesión.</p> if (!$email || !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $email)) {
<a href='./'><button>Iniciar Sesión</button></a> $register = false;
<form method='post' action='./'><button name='register' id='register'>Registro</button></form>\n"; }
}
} $password = isset($pass) ? $pass : null ;
$repassword = isset($repass) ? $repass : null ;
// Metodo auxiliar que comprueba la validez de los parametros if($password != $repassword){
private function test_input($input){ if (!$password || mb_strlen($password) < 4) {
return htmlspecialchars(trim(strip_tags($input))); $register = false;
} }
if(!$repassword || mb_strlen($repassword) < 4){
public function getReply() { $register = false;
return $this->reply; }
} }
}
if ($register) {
$bd = new UserDAO('complucine');
if($bd){
$this->user = $bd->selectUser($username, $password);
try{
if (!$this->user) {
$bd->createUser("", $username, $email, $password, "user");
$this->user = $bd->selectUser($username, $password);
if ($this->user) {
$_SESSION["nombre"] = $this->user->getName();
$_SESSION["rol"] = $this->user->getRol();
$_SESSION["login"] = $register;
}
}
}
catch (Exception $e){
$_SESSION["login"] = $register;
}
}
}
}
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
}
?> ?>

View File

@ -1,13 +1,14 @@
<?php <?php
//General Config File: //General Config File:
require_once('../assets/php/config.php') require_once('../assets/php/config.php');
//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 = $register->getReply();
$reg = new Register();
$reg->testReg();
?> ?>
<!DOCTYPE HTML> <!DOCTYPE HTML>
<!-- <!--
Práctica 2 - Sistemas Web | Grupo D Práctica 2 - Sistemas Web | Grupo D
@ -15,14 +16,15 @@
--> -->
<html lang="es"> <html lang="es">
<!-- Head --> <!-- Head -->
<?php <?php
$template->print_head(); $template->print_head();
?> ?>
<body> <body>
<!-- Header --> <!-- Header -->
<?php <?php
$template->print_header(); $template->print_header();
?> ?>
<!-- Main --> <!-- Main -->
<div class="main"> <div class="main">
<div class="image"><img src="../img/logo_trasparente.png" /></div> <div class="image"><img src="../img/logo_trasparente.png" /></div>
@ -34,9 +36,9 @@
<div class="column side"></div> <div class="column side"></div>
<div class="column middle"> <div class="column middle">
<div class="code info"> <div class="code info">
<?php <?php
echo $reg->getReply(); echo $reply;
?> ?>
</div> </div>
</div> </div>
<div class="column side"></div> <div class="column side"></div>
@ -44,8 +46,10 @@
</section> </section>
<!-- Footer --> <!-- Footer -->
<?php <?php
$template->print_footer(); $template->print_footer();
?> ?>
</body> </body>
</html>
</html>

View File

@ -1,18 +1,20 @@
<!DOCTYPE HTML> <!DOCTYPE HTML>
<?php <?php
session_start(); //General Config File:
require_once('../assets/php/config.php');
//HTML template:
require_once('../assets/php/template.php');
$template = new Template();
$prefix = $template->get_prefix();
//List of the tittles and descriptions of the movies: //List of the tittles and descriptions of the movies:
require_once('includes/loadFilms.php'); require_once($prefix.'panel_admin/includes/film_dao.php');
$loadFilms = new loadFilms(); $loadFilms = new Film_DAO("complucine");
$films = $loadFilms->getFilms(); $films = $loadFilms->allFilmData();
$descriptions = $loadFilms->getDescription(); $titles = array();
$descriptions = array();
$times = array();
foreach($films as $key => $value){
$titles[$key] = $value->getTittle();
$descriptions[$key] = $value->getDescription();
$times[$key] = $value->getDuration();
}
?> ?>
<!-- <!--
Práctica 2 - Sistemas Web | Grupo D Práctica 2 - Sistemas Web | Grupo D
@ -39,8 +41,7 @@
<div class='row'> <div class='row'>
<?php <?php
for($i = 0; $i < count($films); $i++){ for($i = 0; $i < count($films); $i++){
$title = str_replace('_', ' ', $films[$i]); $title = str_replace('_', ' ', $titles[$i]);
$description = $descriptions[$i];
if($i%2 === 0){ if($i%2 === 0){
if($i != 0) echo "</div> if($i != 0) echo "</div>
"; ";
@ -53,15 +54,16 @@
echo "<div class='column middle'> echo "<div class='column middle'>
"; ";
} }
echo "<section id='".$films[$i]."'> echo "<section id='".$titles[$i]."'>
<div class='zoom'> <div class='zoom'>
<div class='code showtimes'> <div class='code showtimes'>
<div class='image'><img src='".$prefix."img/".$films[$i].".jpg' alt='".$films[$i]."' /></div> <div class='image'><img src='".$prefix."img/".$titles[$i].".jpg' alt='".$titles[$i]."' /></div>
<h2>".$title."</h2> <h2>".$title."</h2>
<hr /> <hr />
<div class='blockquote'> <div class='blockquote'>
<p>".$description."</p> <p>".$descriptions[$i]."</p>
</div> </div>
<p>Duración: ".$times[$i]." minutos</p>
</div> </div>
</div> </div>
</section> </section>