diff --git a/LICENSE b/LICENSE index 4402d56..07f258e 100755 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2018-2020 jeremykenedy +Copyright (c) 2018-2023 jeremykenedy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 2b51da9..47a53a7 100755 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Table of contents: | Locked Page | ### Requirements -* [Laravel 5.3, 5.4, 5.5+ ,6+, 7+, and 8+](https://laravel.com/docs/installation) +* [Laravel 5.3, 5.4, 5.5+ ,6+, 7+, 8+, 9+, and 10+](https://laravel.com/docs/installation) ### Installation Instructions 1. From your projects root folder in terminal run: diff --git a/composer.json b/composer.json index b326c93..845caf5 100755 --- a/composer.json +++ b/composer.json @@ -15,14 +15,15 @@ } ], "require": { - "php": "^7.3|^8.0", - "laravel/framework": "6.*|7.*|8.*|9.*" + "php": "^7.3|^8.0|^8.1|^8.2", + "laravel/framework": "6.*|7.*|8.*|9.*|10.*" }, "require-dev": { - "orchestra/testbench": "^6.0", - "laravel/tinker": "^2.4", "illuminate/support": "^8.5", - "laravel/laravel": "^8.0" + "laravel/laravel": "^8.0", + "laravel/tinker": "^2.4", + "orchestra/testbench": "^6.0", + "suin/phpcs-psr4-sniff": "^3.0" }, "autoload": { "psr-4": { @@ -42,7 +43,10 @@ } }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } }, "minimum-stability": "stable", "prefer-stable": true diff --git a/src/App/Http/Controllers/TwoStepController.php b/src/App/Http/Controllers/TwoStepController.php index 412c1bb..ce7cc3a 100755 --- a/src/App/Http/Controllers/TwoStepController.php +++ b/src/App/Http/Controllers/TwoStepController.php @@ -28,11 +28,13 @@ public function __construct() { $this->middleware('auth'); - $this->middleware(function ($request, $next) { - $this->setUser2StepData(); + $this->middleware( + function ($request, $next) { + $this->setUser2StepData(); - return $next($request); - }); + return $next($request); + } + ); } /** @@ -146,12 +148,14 @@ public function verify(Request $request) } if ($request->ajax()) { - $validator = Validator::make($request->all(), [ + $validator = Validator::make( + $request->all(), [ 'v_input_1' => 'required|min:1|max:1', 'v_input_2' => 'required|min:1|max:1', 'v_input_3' => 'required|min:1|max:1', 'v_input_4' => 'required|min:1|max:1', - ]); + ] + ); if ($validator->fails()) { $returnData = $this->invalidCodeReturnData($validator->errors()); diff --git a/src/App/Http/Middleware/Laravel2step.php b/src/App/Http/Middleware/Laravel2step.php index 8b843c3..06e3f4c 100644 --- a/src/App/Http/Middleware/Laravel2step.php +++ b/src/App/Http/Middleware/Laravel2step.php @@ -25,23 +25,23 @@ public function handle($request, Closure $next) $nextUri = config('app.url').'/'.$uri; switch ($uri) { - case 'verification/needed': - case 'password/reset': - case 'register': - case 'logout': - case 'login': - case '/': - break; - - default: - session(['nextUri' => $nextUri]); - - if (config('laravel2step.laravel2stepEnabled')) { - if ($this->twoStepVerification($request) !== true) { - return redirect('verification/needed'); - } + case 'verification/needed': + case 'password/reset': + case 'register': + case 'logout': + case 'login': + case '/': + break; + + default: + session(['nextUri' => $nextUri]); + + if (config('laravel2step.laravel2stepEnabled')) { + if ($this->twoStepVerification($request) !== true) { + return redirect('verification/needed'); } - break; + } + break; } return $response; diff --git a/src/Laravel2stepServiceProvider.php b/src/Laravel2stepServiceProvider.php index 238f063..58ea008 100755 --- a/src/Laravel2stepServiceProvider.php +++ b/src/Laravel2stepServiceProvider.php @@ -49,28 +49,40 @@ private function publishFiles() { $publishTag = 'laravel2step'; - $this->publishes([ + $this->publishes( + [ __DIR__.'/config/laravel2step.php' => base_path('config/laravel2step.php'), - ], $publishTag); + ], $publishTag + ); - $this->publishes([ + $this->publishes( + [ __DIR__.'/database/migrations/' => base_path('/database/migrations'), - ], $publishTag); + ], $publishTag + ); - $this->publishes([ + $this->publishes( + [ __DIR__.'/public/css' => public_path('css/laravel2step'), - ], $publishTag); + ], $publishTag + ); - $this->publishes([ + $this->publishes( + [ __DIR__.'/resources/assets/scss' => resource_path('assets/scss/laravel2step'), - ], $publishTag); + ], $publishTag + ); - $this->publishes([ + $this->publishes( + [ __DIR__.'/resources/views' => resource_path('views/vendor/laravel2step'), - ], $publishTag); + ], $publishTag + ); - $this->publishes([ + $this->publishes( + [ __DIR__.'/resources/lang' => base_path('resources/lang/vendor/laravel2step'), - ], $publishTag); + ], $publishTag + ); } } diff --git a/src/database/migrations/2017_12_09_070937_create_two_step_auth_table.php b/src/database/migrations/2017_12_09_070937_create_two_step_auth_table.php index 63576a0..5552f79 100644 --- a/src/database/migrations/2017_12_09_070937_create_two_step_auth_table.php +++ b/src/database/migrations/2017_12_09_070937_create_two_step_auth_table.php @@ -20,17 +20,19 @@ public function up() $tableCheck = Schema::connection($connection)->hasTable($table); if (!$tableCheck) { - Schema::connection($connection)->create($table, function (Blueprint $table) { - $table->increments('id'); - $table->unsignedBigInteger('userId')->unsigned()->index(); - $table->foreign('userId')->references('id')->on('users')->onDelete('cascade'); - $table->string('authCode')->nullable(); - $table->integer('authCount'); - $table->boolean('authStatus')->default(false); - $table->dateTime('authDate')->nullable(); - $table->dateTime('requestDate')->nullable(); - $table->timestamps(); - }); + Schema::connection($connection)->create( + $table, function (Blueprint $table) { + $table->increments('id'); + $table->unsignedBigInteger('userId')->unsigned()->index(); + $table->foreign('userId')->references('id')->on('users')->onDelete('cascade'); + $table->string('authCode')->nullable(); + $table->integer('authCount'); + $table->boolean('authStatus')->default(false); + $table->dateTime('authDate')->nullable(); + $table->dateTime('requestDate')->nullable(); + $table->timestamps(); + } + ); } } diff --git a/src/routes/web.php b/src/routes/web.php index c77aa38..25d835a 100755 --- a/src/routes/web.php +++ b/src/routes/web.php @@ -5,10 +5,14 @@ | Laravel 2-Step Verification Web Routes |-------------------------------------------------------------------------- | +| Here are the routes for two step verification middleware. +| */ -Route::group(['prefix' => 'verification', 'as' => 'laravel2step::', 'namespace' => 'jeremykenedy\laravel2step\App\Http\Controllers', 'middleware' => ['web']], function () { - Route::get('/needed', ['uses' => 'TwoStepController@showVerification'])->name('verificationNeeded'); - Route::post('/verify', ['uses' => 'TwoStepController@verify'])->name('verify'); - Route::post('/resend', ['uses' => 'TwoStepController@resend'])->name('resend'); -}); +Route::group( + ['prefix' => 'verification', 'as' => 'laravel2step::', 'namespace' => 'jeremykenedy\laravel2step\App\Http\Controllers', 'middleware' => ['web']], function () { + Route::get('/needed', ['uses' => 'TwoStepController@showVerification'])->name('verificationNeeded'); + Route::post('/verify', ['uses' => 'TwoStepController@verify'])->name('verify'); + Route::post('/resend', ['uses' => 'TwoStepController@resend'])->name('resend'); + } +);