diff --git a/composer.json b/composer.json index 3872a57..7ba1876 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ "slim/twig-view": "^2.3", "google/recaptcha": "^1.1", "kanellov/slim-twig-flash": "^0.2.0", - "phpmailer/phpmailer": "~6.0" + "phpmailer/phpmailer": "~6.0", + "tuupola/slim-basic-auth": "^3.2" }, "require-dev": { "phpunit/phpunit": ">=4.8 < 6.0" diff --git a/composer.lock b/composer.lock index 618983c..802f749 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1812fa080861f1fd00320ca0ab0acdb8", + "content-hash": "39b38af13b004d514b8fa19e295ad0d9", "packages": [ { "name": "container-interop/container-interop", @@ -428,6 +428,58 @@ ], "time": "2017-02-14T16:28:37+00:00" }, + { + "name": "psr/http-factory", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "378bfe27931ecc54ff824a20d6f6bfc303bbd04c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/378bfe27931ecc54ff824a20d6f6bfc303bbd04c", + "reference": "378bfe27931ecc54ff824a20d6f6bfc303bbd04c", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "time": "2018-07-30T21:54:04+00:00" + }, { "name": "psr/http-message", "version": "1.0.1", @@ -478,6 +530,112 @@ ], "time": "2016-08-06T14:39:51+00:00" }, + { + "name": "psr/http-server-handler", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-server-handler.git", + "reference": "439d92054dc06097f2406ec074a2627839955a02" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-server-handler/zipball/439d92054dc06097f2406ec074a2627839955a02", + "reference": "439d92054dc06097f2406ec074a2627839955a02", + "shasum": "" + }, + "require": { + "php": ">=7.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Server\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP server-side request handler", + "keywords": [ + "handler", + "http", + "http-interop", + "psr", + "psr-15", + "psr-7", + "request", + "response", + "server" + ], + "time": "2018-01-22T17:04:15+00:00" + }, + { + "name": "psr/http-server-middleware", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-server-middleware.git", + "reference": "ea17eb1fb2c8df6db919cc578451a8013c6a0ae5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-server-middleware/zipball/ea17eb1fb2c8df6db919cc578451a8013c6a0ae5", + "reference": "ea17eb1fb2c8df6db919cc578451a8013c6a0ae5", + "shasum": "" + }, + "require": { + "php": ">=7.0", + "psr/http-message": "^1.0", + "psr/http-server-handler": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Server\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP server-side middleware", + "keywords": [ + "http", + "http-interop", + "middleware", + "psr", + "psr-15", + "psr-7", + "request", + "response" + ], + "time": "2018-01-22T17:08:31+00:00" + }, { "name": "psr/log", "version": "1.0.2", @@ -812,6 +970,170 @@ ], "time": "2018-08-06T14:22:27+00:00" }, + { + "name": "tuupola/callable-handler", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/tuupola/callable-handler.git", + "reference": "8b9d87f88056d4234af317d65612d7b6307a747a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tuupola/callable-handler/zipball/8b9d87f88056d4234af317d65612d7b6307a747a", + "reference": "8b9d87f88056d4234af317d65612d7b6307a747a", + "shasum": "" + }, + "require": { + "php": "^7.1", + "psr/http-server-middleware": "^1.0" + }, + "require-dev": { + "codedungeon/phpunit-result-printer": "^0.4.4", + "overtrue/phplint": "^1.0", + "phpunit/phpunit": "^6.5", + "squizlabs/php_codesniffer": "^3.2", + "tuupola/http-factory": "^0.4.0|^1.0", + "zendframework/zend-diactoros": "^1.6.0|^2.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Tuupola\\Middleware\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mika Tuupola", + "email": "tuupola@appelsiini.net", + "homepage": "https://appelsiini.net/", + "role": "Developer" + } + ], + "description": "Compatibility layer for PSR-7 double pass and PSR-15 middlewares.", + "homepage": "https://github.com/tuupola/callable-handler", + "keywords": [ + "middleware", + "psr-15", + "psr-7" + ], + "time": "2018-10-12T09:59:35+00:00" + }, + { + "name": "tuupola/http-factory", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/tuupola/http-factory.git", + "reference": "dd38c41facebdec20b5b4a120cd6380e30720ce8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tuupola/http-factory/zipball/dd38c41facebdec20b5b4a120cd6380e30720ce8", + "reference": "dd38c41facebdec20b5b4a120cd6380e30720ce8", + "shasum": "" + }, + "require": { + "php": "^7.1", + "psr/http-factory": "^1.0" + }, + "conflict": { + "nyholm/psr7": "<1.0" + }, + "require-dev": { + "http-interop/http-factory-tests": "^0.5.0", + "overtrue/phplint": "^1.0", + "phpunit/phpunit": "^6.5", + "squizlabs/php_codesniffer": "^3.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Tuupola\\Http\\Factory\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mika Tuupola", + "email": "tuupola@appelsiini.net", + "homepage": "https://appelsiini.net/", + "role": "Developer" + } + ], + "description": "Lightweight autodiscovering PSR-17 HTTP factories", + "homepage": "https://github.com/tuupola/http-factory", + "keywords": [ + "http", + "psr-17", + "psr-7" + ], + "time": "2018-10-12T09:32:20+00:00" + }, + { + "name": "tuupola/slim-basic-auth", + "version": "3.2.1", + "source": { + "type": "git", + "url": "https://github.com/tuupola/slim-basic-auth.git", + "reference": "40f5efe991ac4e2441ee05b830375c02432ff3f8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tuupola/slim-basic-auth/zipball/40f5efe991ac4e2441ee05b830375c02432ff3f8", + "reference": "40f5efe991ac4e2441ee05b830375c02432ff3f8", + "shasum": "" + }, + "require": { + "php": "^7.1", + "psr/http-message": "^1.0.1", + "psr/http-server-middleware": "^1.0", + "tuupola/callable-handler": "^0.3.0|^0.4.0|^1.0", + "tuupola/http-factory": "^0.4.0|^1.0" + }, + "require-dev": { + "codedungeon/phpunit-result-printer": "^0.19.14", + "equip/dispatch": "^2.0", + "overtrue/phplint": "^1.1", + "phpstan/phpstan": "^0.9.2", + "phpunit/phpunit": "^7.0", + "squizlabs/php_codesniffer": "^3.2", + "zendframework/zend-diactoros": "^1.3|^2.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Tuupola\\Middleware\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mika Tuupola", + "email": "tuupola@appelsiini.net", + "homepage": "https://appelsiini.net/" + } + ], + "description": "PSR-7 and PSR-15 HTTP Basic Authentication Middleware", + "homepage": "https://appelsiini.net/projects/slim-basic-auth", + "keywords": [ + "auth", + "middleware", + "psr-15", + "psr-7" + ], + "time": "2018-10-15T12:48:00+00:00" + }, { "name": "twig/twig", "version": "v2.5.0", diff --git a/src/routes.php b/src/routes.php index 5f12a4c..e68c9ee 100644 --- a/src/routes.php +++ b/src/routes.php @@ -4,6 +4,13 @@ use Slim\Http\Request; use Slim\Http\Response; // Routes +$app->add(new Tuupola\Middleware\HttpBasicAuthentication([ + "path" => ["/inscriptos", "inscriptoscsv"], /* or ["/admin", "/api"] */ + "realm" => "Protected", + "users" => [ + "admin" => "puntofijo" + ] +])); $app->get('/', function (Request $request, Response $response, array $args) { $this->logger->info("GDDWorkshop '/' route"); @@ -61,9 +68,17 @@ $app->get('/program', function (Request $request, Response $response, array $arg }); $app->get('/inscriptos', function(Request $request, Response $response, array $args){ - $dbfile = $this->settings['db']['path']; - exec('sqlite3 -header -csv '.$dbfile.' "select * from registro" > "inscriptos.csv"'); - $file = 'inscriptos.csv'; + $this->logger->info("GDDWorkshop '/practicalinfo' route"); + $db = $this->db; + $data = $db->getAll(); + return $this->renderer->render($response, 'inscriptos.html', ["registros" => $data]); +}); + +$app->get('/inscriptoscsv', function(Request $request, Response $response, array $args){ + $this->logger->info("GDDWorkshop '/practicalinfo' route"); + $dbfile = $this->settings['db']['path']; + exec('sqlite3 -header -csv '.$dbfile.' "select * from registro" > "inscriptos.csv"'); + $file = 'inscriptos.csv'; $fh = fopen($file,"rb"); $stream = new \Slim\Http\Stream($fh); return $response->withHeader('Content-Type', 'application/force-download') @@ -77,14 +92,14 @@ $app->get('/inscriptos', function(Request $request, Response $response, array $a ->withHeader('Pragma', 'public') ->withBody($stream); }); -/* + $mw = function ($request, $response, $next) { $response->getBody()->write('BEFORE'); $response = $next($request, $response); $response->getBody()->write('AFTER'); return $response; -};*/ +}; // API ROUTES $app->group('/api', function($app){ diff --git a/templates/inscriptos.html b/templates/inscriptos.html new file mode 100644 index 0000000..5c752a5 --- /dev/null +++ b/templates/inscriptos.html @@ -0,0 +1,166 @@ + + + + + Surface Dynamics Workshop 2018 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + {% for reg in registros %} + + + + + + + + + + + + + + + {% endfor %} + +
Nombree-MailTítuloCiudadPaísAfiliaciónLlegadaSalidaCarta InvitaciónPreferencia de habitaciónCompañero de cuartoFecha de registro
{{ reg.nombre | title }} {{ reg.apellido | title }}{{ reg.email }}{{ reg.titulo | default("No especificado") }}{{ reg.ciudad | default("No especificado") }}{{ reg.pais }}{{ reg.afiliacion | default("No especificado") }}{{ reg.fechaLlegada | default("No especificado") }}{{ reg.fechaPartida | default("No especificado") }}{{ reg.cartaInvitacion ? 'Si' : 'No' }}{{ reg.roomingPref }}{{ reg.roomate|default("No especificado") }}{{ reg.fechaRegistro }}
+
+
+
+ +
+ +
+ + + + +