From 133daf4e364b5a3499efbcfff8d10f7733fbb956 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Wed, 20 Jun 2018 09:31:44 +0200 Subject: [PATCH] Add user verification on registration --- Changelog | 1 + .../Controllers/Auth/RegisterController.php | 22 +++- app/Http/Kernel.php | 1 + composer.json | 1 + composer.lock | 65 ++++++++- config/app.php | 3 +- config/themes.php | 123 ------------------ 7 files changed, 86 insertions(+), 130 deletions(-) delete mode 100644 config/themes.php diff --git a/Changelog b/Changelog index f8149c9dc..24a296db8 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-06-20 DariusIII + * Chg: Add user verification on registration * Chg: Add check if rating is set in Movie class updateMovieInfo function 2018-06-19 DariusIII * Chg: Update imdbphp/imdbphp diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index c56001a46..a5a1388ca 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -6,12 +6,15 @@ use App\Models\User; use App\Models\Settings; use App\Models\UserRole; use App\Models\Invitation; +use Illuminate\Auth\Events\Registered; use Illuminate\Http\Request; use Blacklight\utility\Utility; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Password; use Illuminate\Foundation\Auth\RegistersUsers; +use Jrean\UserVerification\Facades\UserVerification; +use Jrean\UserVerification\Traits\VerifiesUsers; class RegisterController extends Controller { @@ -28,6 +31,8 @@ class RegisterController extends Controller use RegistersUsers; + use VerifiesUsers; + /** * Where to redirect users after registration. * @@ -42,7 +47,7 @@ class RegisterController extends Controller */ public function __construct() { - $this->middleware('guest'); + $this->middleware('guest', ['except' => ['getVerification', 'getVerificationError']]); } /** @@ -152,7 +157,7 @@ class RegisterController extends Controller break; } - $ret = $this->create( + $user = $this->create( [ 'username' => $userName, 'password' => $password, @@ -164,11 +169,18 @@ class RegisterController extends Controller ] ); - if ($ret->id > 0) { - Auth::loginUsingId($ret->id); + event(new Registered($user)); + + UserVerification::generate($user); + + UserVerification::send($user, 'User verification required'); + + if ($user->id > 0) { + Auth::loginUsingId($user->id); User::updateSiteAccessed(Auth::id(), (int) Settings::settingValue('..storeuserips') === 1 ? $request->getClientIp() : ''); - return redirect()->intended($this->redirectPath()); + return $this->registered($request, $user) + ?: redirect($this->redirectPath()); } break; case 'view': { diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 3691b3fe3..2a041f188 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -59,5 +59,6 @@ class Kernel extends HttpKernel 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'admin' => \App\Http\Middleware\IsAdmin::class, + 'isVerified' => \Jrean\UserVerification\Middleware\IsVerified::class, ]; } diff --git a/composer.json b/composer.json index 5b410dab8..8db1fb217 100755 --- a/composer.json +++ b/composer.json @@ -136,6 +136,7 @@ "intervention/imagecache": "^2.3", "james-heinrich/getid3": "1.9.*", "joshpinkney/tv-maze-php-api": "dev-master", + "jrean/laravel-user-verification": "^6.0", "kevinlebrun/colors.php": "^1.0", "laravel/framework": "5.6.*", "laravel/scout": "^4.0", diff --git a/composer.lock b/composer.lock index 02011f578..944170b9b 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": "016d2121392c4c0ea3207cfb7252f6b9", + "content-hash": "1dcf6a9645d4d8cccaaed914b8bf0ba8", "packages": [ { "name": "adrenth/thetvdb2", @@ -3266,6 +3266,69 @@ "description": "TVMaze-API-Wrapper", "time": "2018-01-09T14:46:56+00:00" }, + { + "name": "jrean/laravel-user-verification", + "version": "v6.0.1", + "source": { + "type": "git", + "url": "https://github.com/jrean/laravel-user-verification.git", + "reference": "216ec2d003fa61092c129970d21b26b1774359f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jrean/laravel-user-verification/zipball/216ec2d003fa61092c129970d21b26b1774359f7", + "reference": "216ec2d003fa61092c129970d21b26b1774359f7", + "shasum": "" + }, + "require": { + "illuminate/support": "5.6.*", + "php": ">=7.1.3" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^1.12", + "fzaninotto/faker": "^1.6", + "mockery/mockery": "^0.9.5", + "phpunit/phpunit": "^5.5", + "satooshi/php-coveralls": "^1.0", + "sllh/php-cs-fixer-styleci-bridge": "^2.1" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Jrean\\UserVerification\\UserVerificationServiceProvider" + ], + "aliases": { + "UserVerification": "Jrean\\UserVerification\\Facades\\UserVerification" + } + } + }, + "autoload": { + "psr-4": { + "Jrean\\UserVerification\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jean Ragouin", + "email": "go@askjong.com" + } + ], + "description": "User Email Verification For Laravel 5.*", + "keywords": [ + "email activation", + "email verification", + "framework", + "laravel", + "user activation", + "user verification" + ], + "time": "2018-05-22T05:58:48+00:00" + }, { "name": "kevinlebrun/colors.php", "version": "1.0.3", diff --git a/config/app.php b/config/app.php index be2395ba3..91af2b3c0 100644 --- a/config/app.php +++ b/config/app.php @@ -158,6 +158,7 @@ return [ App\Providers\AuthServiceProvider::class, // App\Providers\BroadcastServiceProvider::class, App\Providers\EventServiceProvider::class, + Jrean\UserVerification\UserVerificationServiceProvider::class, App\Providers\RouteServiceProvider::class, App\Providers\YencServiceProvider::class, Way\Generators\GeneratorsServiceProvider::class, @@ -214,7 +215,7 @@ return [ 'URL' => Illuminate\Support\Facades\URL::class, 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, - + 'UserVerification' => Jrean\UserVerification\Facades\UserVerification::class, ], ]; diff --git a/config/themes.php b/config/themes.php deleted file mode 100644 index fe7d8dc36..000000000 --- a/config/themes.php +++ /dev/null @@ -1,123 +0,0 @@ - 'resources/views/themes', // eg: base_path('resources/themes') - - /* - |-------------------------------------------------------------------------- - | Set behavior if an asset is not found in a Theme hierarchy. - | Available options: THROW_EXCEPTION | LOG_ERROR | IGNORE - |-------------------------------------------------------------------------- - */ - - 'asset_not_found' => 'LOG_ERROR', - - /* - |-------------------------------------------------------------------------- - | Do we want a theme activated by default? Can be set at runtime with: - | Theme::set('theme-name'); - |-------------------------------------------------------------------------- - */ - - 'default' => 'Gentele', - - /* - |-------------------------------------------------------------------------- - | Cache theme.json configuration files that are located in each theme's folder - | in order to avoid searching theme settings in the filesystem for each request - |-------------------------------------------------------------------------- - */ - - 'cache' => true, - - /* - |-------------------------------------------------------------------------- - | Define available themes. Format: - | - | 'theme-name' => [ - | 'extends' => 'theme-to-extend', // optional - | 'views-path' => 'path-to-views', // defaults to: resources/views/theme-name - | 'asset-path' => 'path-to-assets', // defaults to: public/theme-name - | - | // You can add your own custom keys - | // Use Theme::getSetting('key') & Theme::setSetting('key', 'value') to access them - | 'key' => 'value', - | ], - | - |-------------------------------------------------------------------------- - */ - - 'themes' => [ - 'Charisma' => [ - 'extends' => null, - 'views-path' => 'resources/views/themes/Charisma', - 'asset-path' => 'public/assets/Charisma', - ], - 'Gamma' => [ - 'extends' => null, - 'views-path' => 'resources/views/themes/Gamma', - 'asset-path' => 'public/assets/Gamma', - ], - 'Gentele' => [ - 'extends' => null, - 'views-path' => 'resources/views/themes/Gentele', - 'asset-path' => 'public/assets', - ], - 'Omicron' => [ - 'extends' => null, - 'views-path' => 'resources/views/themes/Omicron', - 'asset-path' => 'public/assets/Omicron', - ], - 'admin' => [ - 'extends' => null, - 'views-path' => 'resources/views/themes/admin', - 'asset-path' => 'public/assets', - ], - - // Add your themes here. These settings will override theme.json settings defined for each theme - - /* - |---------------------------[ Example Structure ]-------------------------- - | - | // Full theme Syntax: - | - | 'example1' => [ - | 'extends' => null, // doesn't extend any theme - | 'views-path' => example, // = resources/views/example_theme - | 'asset-path' => example, // = public/example_theme - | ], - | - | // Use all Defaults: - | - | 'example2', // Assets =\public\example2, Views =\resources\views\example2 - | // Note that if you use all default values, you can omit declaration completely. - | // i.e. defaults will be used when you call Theme::set('undefined-theme') - | - | - | // This theme shares the views with example2 but defines its own assets in \public\example3 - | - | 'example3' => [ - | 'views-path' => 'example', - | ], - | - | // This theme extends example1 and may override SOME views\assets in its own paths - | - | 'example4' => [ - | 'extends' => 'example1', - | ], - | - |-------------------------------------------------------------------------- - */ - ], - -];