diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b761af5d4211b4d5e536b24fdcfc0eb8c442a879..be7c7da2eaa7ddfe9ac46bae46341029cb462f13 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,7 +11,7 @@ before_script: - apt-get update -yqq - apt-get install -yqq git libpq-dev libcurl4-gnutls-dev libicu-dev libvpx-dev libjpeg-dev libpng-dev libxpm-dev zlib1g-dev libfreetype6-dev libxml2-dev libexpat1-dev libbz2-dev libgmp3-dev libldap2-dev unixodbc-dev libsqlite3-dev libaspell-dev libsnmp-dev libpcre3-dev libtidy-dev # Install PHP extensions -- docker-php-ext-install mbstring pdo_pgsql curl json intl gd xml zip bz2 opcache +- docker-php-ext-install mbstring pdo_pgsql curl json intl gd xml zip bz2 opcache bcmath # Install & enable Xdebug for code coverage reports - pecl install xdebug - docker-php-ext-enable xdebug diff --git a/app/Http/Controllers/RandomFormController.php b/app/Http/Controllers/RandomFormController.php index 46ac3c089dfb9c99174505042f1ad803b24f5c37..5500a9d7b41c26d96e6d77318232dce280623fc1 100644 --- a/app/Http/Controllers/RandomFormController.php +++ b/app/Http/Controllers/RandomFormController.php @@ -4,6 +4,7 @@ namespace Korko\SecretSanta\Http\Controllers; use Facades\Korko\SecretSanta\Libs\HatSolver as Solver; use Facades\Korko\SecretSanta\Libs\SmsTools as SmsTools; +use Hashids; use Illuminate\Http\Request; use Korko\SecretSanta\Draw; use Korko\SecretSanta\Exceptions\SolverException; @@ -112,7 +113,7 @@ class RandomFormController extends Controller $key = openssl_random_pseudo_bytes(32); $participant = $this->addParticipant($santa, $key, $expirationDate); - return route('dearsanta', ['santa' => $participant->id]).'#'.bin2hex($key); + return route('dearsanta', ['santa' => Hashids::encode($participant->id)]).'#'.bin2hex($key); } private function getDraw($expirationDate) diff --git a/app/Http/Middleware/Unhash.php b/app/Http/Middleware/Unhash.php new file mode 100644 index 0000000000000000000000000000000000000000..9d9381e1d21dea535fa9198c76aad4f8f7a1642a --- /dev/null +++ b/app/Http/Middleware/Unhash.php @@ -0,0 +1,28 @@ +decode($value), 0, $value); + } +} diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 5ee2b329823d980d47ab38a0cc4fd3eedab58385..3717b4639ecc54c0b1e4f57b4d22486bba7f16fd 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -2,8 +2,10 @@ namespace Korko\SecretSanta\Providers; +use Hashids; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Route; +use Korko\SecretSanta\Participant; class RouteServiceProvider extends ServiceProvider { @@ -23,7 +25,12 @@ class RouteServiceProvider extends ServiceProvider */ public function boot() { - // + Route::bind('participant', function ($value) { + if (($ids = Hashids::decode($value)) && ($participant = Participant::find($ids[0]))) { + return $participant; + } + abort(404); + }); parent::boot(); } diff --git a/composer.json b/composer.json index 0cf589c2f3195ed6018af9e6a4425c20f44a410f..69cf586999434a8b52b6b4661c0245e0b90afe7a 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,8 @@ "korko/validator": "dev-master", "laravel/framework": "5.4.*", "mariuzzo/laravel-js-localization": "^1.4", - "spatie/laravel-blade-javascript": "^1.0" + "spatie/laravel-blade-javascript": "^1.0", + "vinkla/hashids": "^3.2" }, "require-dev": { "fzaninotto/faker": "~1.4", diff --git a/composer.lock b/composer.lock index 0ab3ea8efdc57715414cbe03f8020905d15a178f..56d40455fa6b3f2c80f64ce421db7be849aaba97 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "ba12ccb32b630e493051fcfe758b36e4", + "content-hash": "d8c37e4862d036f35273ce42606cba2f", "packages": [ { "name": "anhskohbo/no-captcha", @@ -228,6 +228,66 @@ ], "time": "2018-03-08T01:11:30+00:00" }, + { + "name": "graham-campbell/manager", + "version": "v3.0.0", + "source": { + "type": "git", + "url": "https://github.com/GrahamCampbell/Laravel-Manager.git", + "reference": "bf9da58aa32676209961558eaac5d6625f6f1399" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/GrahamCampbell/Laravel-Manager/zipball/bf9da58aa32676209961558eaac5d6625f6f1399", + "reference": "bf9da58aa32676209961558eaac5d6625f6f1399", + "shasum": "" + }, + "require": { + "illuminate/contracts": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*", + "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*", + "php": "^7.0" + }, + "require-dev": { + "graham-campbell/analyzer": "^1.1", + "graham-campbell/testbench-core": "^2.0", + "mockery/mockery": "dev-master#c90a17247147543081e4d00f46911e422b49e583", + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "GrahamCampbell\\Manager\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "graham@alt-three.com" + } + ], + "description": "Manager Provides Some Manager Functionality For Laravel 5", + "keywords": [ + "Graham Campbell", + "GrahamCampbell", + "Laravel Manager", + "Laravel-Manager", + "connector", + "framework", + "interface", + "laravel", + "manager" + ], + "time": "2017-08-06T17:54:13+00:00" + }, { "name": "guzzlehttp/guzzle", "version": "6.3.3", @@ -409,6 +469,72 @@ ], "time": "2017-03-20T17:10:46+00:00" }, + { + "name": "hashids/hashids", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/ivanakimov/hashids.php.git", + "reference": "7a945a5192d4a5c8888364970feece9bc26179df" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ivanakimov/hashids.php/zipball/7a945a5192d4a5c8888364970feece9bc26179df", + "reference": "7a945a5192d4a5c8888364970feece9bc26179df", + "shasum": "" + }, + "require": { + "php": "^5.6.4 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7 || ^6.3" + }, + "suggest": { + "ext-bcmatch": "Required to use BC Math arbitrary precision mathematics (*).", + "ext-gmp": "Required to use GNU multiple precision mathematics (*)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "autoload": { + "psr-4": { + "Hashids\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ivan Akimov", + "email": "ivan@barreleye.com", + "homepage": "https://twitter.com/IvanAkimov" + }, + { + "name": "Vincent Klaiber", + "email": "hello@vinkla.com", + "homepage": "https://vinkla.com" + } + ], + "description": "Generate short, unique, non-sequential ids (like YouTube and Bitly) from numbers", + "homepage": "http://hashids.org/php", + "keywords": [ + "bitly", + "decode", + "encode", + "hash", + "hashid", + "hashids", + "ids", + "obfuscate", + "youtube" + ], + "time": "2017-10-28T11:24:20+00:00" + }, { "name": "korko/callr", "version": "1.1.0", @@ -2361,6 +2487,78 @@ "homepage": "https://github.com/tijsverkoyen/CssToInlineStyles", "time": "2017-11-27T11:13:29+00:00" }, + { + "name": "vinkla/hashids", + "version": "3.2.0", + "source": { + "type": "git", + "url": "https://github.com/vinkla/laravel-hashids.git", + "reference": "2e00b90236742618e8ac55a0f31407a81b54ae70" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/vinkla/laravel-hashids/zipball/2e00b90236742618e8ac55a0f31407a81b54ae70", + "reference": "2e00b90236742618e8ac55a0f31407a81b54ae70", + "shasum": "" + }, + "require": { + "graham-campbell/manager": "^3.0", + "hashids/hashids": "^2.0", + "illuminate/contracts": "5.3.* || 5.4.* || 5.5.*", + "illuminate/support": "5.3.* || 5.4.* || 5.5.*", + "php": "^7.0" + }, + "require-dev": { + "graham-campbell/analyzer": "^1.1", + "graham-campbell/testbench": "^4.0", + "mockery/mockery": "dev-master#c90a17247147543081e4d00f46911e422b49e583", + "phpunit/phpunit": "^6.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + }, + "laravel": { + "providers": [ + "Vinkla\\Hashids\\HashidsServiceProvider" + ], + "aliases": { + "Hashids": "Vinkla\\Hashids\\Facades\\Hashids" + } + } + }, + "autoload": { + "psr-4": { + "Vinkla\\Hashids\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Vincent Klaiber", + "email": "hello@vinkla.com", + "homepage": "https://vinkla.com" + } + ], + "description": "A Hashids bridge for Laravel", + "keywords": [ + "bitly", + "decrypt", + "encrypt", + "hash", + "hashid", + "hashids", + "ids", + "laravel", + "obfuscate", + "youtube" + ], + "time": "2017-08-07T13:01:20+00:00" + }, { "name": "vlucas/phpdotenv", "version": "v2.5.1", diff --git a/config/app.php b/config/app.php index ab6b64cca647e4eeea42df1906679e37aba3f7e3..ef9c3f35938d89bb2522914f34e490cbad70d0f8 100644 --- a/config/app.php +++ b/config/app.php @@ -187,6 +187,7 @@ return [ League\StatsD\Laravel5\Provider\StatsdServiceProvider::class, Mariuzzo\LaravelJsLocalization\LaravelJsLocalizationServiceProvider::class, Spatie\BladeJavaScript\BladeJavaScriptServiceProvider::class, + Vinkla\Hashids\HashidsServiceProvider::class, ], @@ -218,6 +219,7 @@ return [ 'File' => Illuminate\Support\Facades\File::class, 'Gate' => Illuminate\Support\Facades\Gate::class, 'Hash' => Illuminate\Support\Facades\Hash::class, + 'Hashids' => Vinkla\Hashids\Facades\Hashids::class, 'Lang' => Illuminate\Support\Facades\Lang::class, 'Log' => Illuminate\Support\Facades\Log::class, 'Mail' => Illuminate\Support\Facades\Mail::class, diff --git a/config/captcha.php b/config/captcha.php index a267acc4fcda3b74e1f6c955cb8d90621f39db2b..1ea5777faff3d5ba88ebf4da9d550c906a3b9494 100644 --- a/config/captcha.php +++ b/config/captcha.php @@ -1,7 +1,7 @@ env('NOCAPTCHA_SECRET'), + 'secret' => env('NOCAPTCHA_SECRET'), 'sitekey' => env('NOCAPTCHA_SITEKEY'), 'options' => [ 'timeout' => 30, diff --git a/config/hashids.php b/config/hashids.php new file mode 100644 index 0000000000000000000000000000000000000000..f4f78ead7e7660781d8d82b1a1ebe624298a2d76 --- /dev/null +++ b/config/hashids.php @@ -0,0 +1,49 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +return [ + + /* + |-------------------------------------------------------------------------- + | Default Connection Name + |-------------------------------------------------------------------------- + | + | Here you may specify which of the connections below you wish to use as + | your default connection for all work. Of course, you may use many + | connections at once using the manager class. + | + */ + + 'default' => 'main', + + /* + |-------------------------------------------------------------------------- + | Hashids Connections + |-------------------------------------------------------------------------- + | + | Here are each of the connections setup for your application. Example + | configuration has been included, but you may add as many connections as + | you would like. + | + */ + + 'connections' => [ + + 'main' => [ + 'salt' => 'secretsanta', + 'length' => '5', + ], + + ], + +]; diff --git a/routes/web.php b/routes/web.php index 2bd3986f72f1ce6177bd76b8154c89ad2a5bfc11..8f057b06679fa9560582c049840c085a6d3dc634 100644 --- a/routes/web.php +++ b/routes/web.php @@ -14,9 +14,10 @@ Route::get('/', 'RandomFormController@view'); Route::post('/', 'RandomFormController@handle'); +Route::pattern('participant', '[0-9a-zA-Z]{'.config('hashids.connections')[config('hashids.default')]['length'].'}'); Route::get('/dearsanta/{participant}', 'DearSantaController@view')->name('dearsanta'); Route::post('/dearsanta/{participant}', 'DearSantaController@handle'); if ($this->app->environment('local', 'dev', 'testing')) { - Route::get('logs', '\Rap2hpoutre\LaravelLogViewer\LogViewerController@index'); + Route::get('/logs', '\Rap2hpoutre\LaravelLogViewer\LogViewerController@index'); }