'error'));
        $errorPassword = self::createMensajeError($errores, 'pass', 'span', array('class' => 'error'));
        $html = "
";
        return $html;
    }
    protected function procesaFormulario($datos){
        $result = array();
        
        $nombre = $this->test_input($datos['name']) ?? null;
        //$nombre = $datos['name'] ?? null;
        $nombre = strtolower($nombre);
        if ( empty($nombre) || mb_strlen($nombre) < 3 || mb_strlen($nombre) > 15 ) {
            $result['name'] = "El nombre tiene que tener\n una longitud de al menos\n 3 caracteres\n y menos de 15 caracteres.";
        }
        
        $password = $this->test_input($datos['pass']) ?? null;
        //$password = $datos['pass'] ?? null;
        if ( empty($password) || mb_strlen($password) < 4 ) {
            $result['pass'] = "El password tiene que tener\n una longitud de al menos\n 4 caracteres.";
        }
        
        if (count($result) === 0) {
            $bd = new UserDAO('complucine');
            if($bd){
                $this->user = $bd->selectUser($nombre, $password);
                if ($this->user) {
                    $this->user->setPass(null);
                    $_SESSION["user"] = serialize($this->user);
                    $_SESSION["nombre"] = $this->user->getName();
                    $_SESSION["rol"] = $this->user->getRol();
                    $_SESSION["login"] = true;
                    $result = 'validate.php';
                } else {
                    $result[] = "El usuario o el password\nno coinciden.";
                }
            } else {
                $result[] = "Error al conectar con la BD.";
            }
        }
        return $result;
    }
    //Returns validation response:
    static public function getReply() {
        
        if(isset($_SESSION["login"])){
            $name = strtoupper($_SESSION['nombre']);
            $reply = "Bienvenido {$name}
                        {$name}, has iniciado sesión correctamente.
                        Usa los botones para navegar
                        
                        \n";
        }   
        else if(!isset($_SESSION["login"])){
            $reply = "ERROR
".
                        "El usuario o contraseña no son válidos.
                        Vuelve a intetarlo o regístrate si no lo habías hecho previamente.
                        
                        \n";
        }
        return $reply;
    }
}
?>