Add files via upload
This commit is contained in:
		@@ -1,67 +1,20 @@
 | 
			
		||||
<?php
 | 
			
		||||
    session_start();
 | 
			
		||||
 | 
			
		||||
    //Depuración (BORRAR):
 | 
			
		||||
    ini_set('display_errors', 1);
 | 
			
		||||
    ini_set('display_startup_errors', 1);
 | 
			
		||||
    error_reporting(E_ALL);
 | 
			
		||||
 | 
			
		||||
    //HTML template:
 | 
			
		||||
    require_once('../assets/php/template.php');
 | 
			
		||||
    $template = new Template();
 | 
			
		||||
 | 
			
		||||
    //Borrar array cuando tengamos BD:
 | 
			
		||||
    $_users = array(
 | 
			
		||||
        "user" => "userpass",
 | 
			
		||||
        "manager" => "managerpass",
 | 
			
		||||
        "admin" => "adminpass"
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    $name = test_input($_POST["name"]); 
 | 
			
		||||
    $passwd = test_input($_POST["pass"]);
 | 
			
		||||
    $login = false;
 | 
			
		||||
    $rol = "user";
 | 
			
		||||
    $nombre;
 | 
			
		||||
 | 
			
		||||
    function test_input($input){
 | 
			
		||||
        return htmlspecialchars(trim(strip_tags($input)));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    foreach($_users as $clave => $valor){
 | 
			
		||||
        if($clave == $name  && $valor == $passwd){
 | 
			
		||||
            $login = true;
 | 
			
		||||
            if($name == "admin"){
 | 
			
		||||
                $nombre = "Administrador"; //CAMBIAR POR EL NOMBRE DE USUARIO, CUANDO ESTÉ LA BBDD
 | 
			
		||||
                $rol = "admin";
 | 
			
		||||
                
 | 
			
		||||
            } 
 | 
			
		||||
            else if($name == "manager"){
 | 
			
		||||
                $nombre = "Gerente"; //CAMBIAR POR EL NOMBRE DE USUARIO, CUANDO ESTÉ LA BBDD
 | 
			
		||||
                $rol = "manager";
 | 
			
		||||
            }
 | 
			
		||||
            else{
 | 
			
		||||
                $nombre = "Usuario"; //CAMBIAR POR EL NOMBRE DE USUARIO, CUANDO ESTÉ LA BBDD
 | 
			
		||||
            }
 | 
			
		||||
            $_SESSION["nombre"] = $nombre;
 | 
			
		||||
            $_SESSION["login"] = $login;
 | 
			
		||||
            $_SESSION["rol"] = $rol;
 | 
			
		||||
            
 | 
			
		||||
            $reply = "<h1>Bienvenido {$_SESSION['nombre']}</h1><hr />
 | 
			
		||||
                        <p>{$_SESSION['nombre']} has iniciado sesión correctamente.</p>
 | 
			
		||||
                        <p>Usa los botones para navegar</p>
 | 
			
		||||
                        <a href='../'><button>Inicio</button></a>
 | 
			
		||||
                        <a href='../panel_{$rol}'><button>Mi Panel</button></a>\n";
 | 
			
		||||
            /*
 | 
			
		||||
            $host  = $_SERVER['HTTP_HOST'];
 | 
			
		||||
            $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
 | 
			
		||||
            $extra = '';
 | 
			
		||||
            header("Location: http://$host$uri/$extra");
 | 
			
		||||
            exit;
 | 
			
		||||
            */
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(!isset($_SESSION["login"])){
 | 
			
		||||
        $reply = "<h1>ERROR</h1><hr />".
 | 
			
		||||
                    "<p>El usuario o contraseña no son válidos.</p>
 | 
			
		||||
                        <p>Vuelve a intetarlo o regístrate si no lo habías hecho previamente.</p>
 | 
			
		||||
                        <a href='./'><button>Iniciar Sesión</button></a>
 | 
			
		||||
                        <form method='post' action='./'><button name='register' id='register'>Registro</button></form>\n";
 | 
			
		||||
    }
 | 
			
		||||
    //Login form validate:
 | 
			
		||||
    require_once('./includes/formLogin.php');
 | 
			
		||||
    $login = new FormLogin();
 | 
			
		||||
    $login->processesForm($_POST["name"], $_POST["pass"]);
 | 
			
		||||
    $reply = $login->getReply();
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
<!DOCTYPE HTML>
 | 
			
		||||
@@ -107,4 +60,4 @@
 | 
			
		||||
 | 
			
		||||
    </body>
 | 
			
		||||
 | 
			
		||||
</html>
 | 
			
		||||
</html>
 | 
			
		||||
		Reference in New Issue
	
	Block a user