diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index dda593be..c6b35469 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -69,4 +69,13 @@ class LoginController extends Controller { $this->guard()->logout(); } + + public function authenticated(Request $request, $user) + { + if (!$user->verified) { + auth()->logout(); + return response()->json(['warning','You need to confirm your account first. We have sent you an activation code, please check your email.']); + //return back()->with('warning', 'You need to confirm your account. We have sent you an activation code, please check your email.'); + } + } } diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index ecfc4151..c9508eda 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -3,11 +3,13 @@ namespace App\Http\Controllers\Auth; use App\User; +use App\VerifyUser; use App\Role; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Validator; use Illuminate\Foundation\Auth\RegistersUsers; +use App\Notifications\VerifyEmail; class RegisterController extends Controller { @@ -32,7 +34,9 @@ class RegisterController extends Controller */ protected function registered(Request $request, $user) { - return $user; + $this->guard()->logout(); + return response()->json(['status'=>'We sent you an activation code. Check your email and click on the link to verify.'],200); + return $user; } /** @@ -66,7 +70,35 @@ class RegisterController extends Controller $user->save(); $user->attachRole($role); + $verifyUser = VerifyUser::create([ + 'user_id' => $user->id, + 'token' => str_random(40) + ]); + + //Notification::send($user, new VerifyUser($user)); + $user->notify(new VerifyEmail($verifyUser)); return $user; - + + } + + public function verifyUser($token) + { + $verifyUser = VerifyUser::where('token', $token)->first(); + if(isset($verifyUser) ){ + $user = $verifyUser->user; + if(!$user->verified) { + $verifyUser->user->verified = 1; + $verifyUser->user->save(); + return response()->json(['status' => 'Your e-mail is verified. You can now login'], 400); + //$status = "Your e-mail is verified. You can now login."; + }else{ + return response()->json(['status' => 'Your e-mail is already verified. Please login.'], 400); + //$status = "Your e-mail is already verified. You can now login."; + } + }else{ + return response()->json(['warning' => 'Sorry your email cannot be identified.'], 400); + //return redirect('/login')->with('warning', "Sorry your email cannot be identified."); + } + //return response()->json(['status']); } } diff --git a/app/Notifications/VerifyEmail.php b/app/Notifications/VerifyEmail.php new file mode 100644 index 00000000..6535d394 --- /dev/null +++ b/app/Notifications/VerifyEmail.php @@ -0,0 +1,70 @@ +verifyUser = $verifyUser; + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['mail']; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return \Illuminate\Notifications\Messages\MailMessage + */ + public function toMail($notifiable) + { + $verifyUser = $this->verifyUser; + $url = url('/user/verify/'.$verifyUser->token); + $greeting = sprintf('Greetings %s!', $notifiable->name); + return (new MailMessage) + ->greeting($greeting) + ->subject("Email Verification") + ->line('Please verify your email to complete your registration with Exchange.') + ->action('Verify Your Email', $url) + ->line('Thank you for using our application!'); + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } +} diff --git a/app/User.php b/app/User.php index 4ceda42b..58699496 100644 --- a/app/User.php +++ b/app/User.php @@ -12,7 +12,7 @@ use Zizaco\Entrust\Traits\EntrustUserTrait; class User extends Authenticatable implements JWTSubject { use Notifiable; - use EntrustUserTrait; + use EntrustUserTrait; /** * The attributes that are mass assignable. @@ -102,4 +102,9 @@ class User extends Authenticatable implements JWTSubject return $this->hasMany('App\Booking'); } + public function verifyUser() + { + return $this->hasOne('App\VerifyUser'); + } + } diff --git a/app/VerifyUser.php b/app/VerifyUser.php new file mode 100644 index 00000000..c5baaef7 --- /dev/null +++ b/app/VerifyUser.php @@ -0,0 +1,15 @@ +belongsTo('App\User', 'user_id'); + } +} diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 689cbeea..a0d5c859 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -18,6 +18,7 @@ class CreateUsersTable extends Migration $table->string('name'); $table->string('email')->unique(); $table->string('password'); + $table->boolean('verified')->default(false); $table->rememberToken(); $table->timestamps(); }); diff --git a/database/migrations/2018_06_19_055333_create_verify_users_table.php b/database/migrations/2018_06_19_055333_create_verify_users_table.php new file mode 100644 index 00000000..b08b5bf6 --- /dev/null +++ b/database/migrations/2018_06_19_055333_create_verify_users_table.php @@ -0,0 +1,33 @@ +increments('id'); + $table->integer('user_id'); + $table->string('token'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('verify_users'); + } +} diff --git a/resources/assets/js/pages/auth/EmailVerification.vue b/resources/assets/js/pages/auth/EmailVerification.vue new file mode 100644 index 00000000..83868813 --- /dev/null +++ b/resources/assets/js/pages/auth/EmailVerification.vue @@ -0,0 +1,31 @@ + + + diff --git a/resources/assets/js/pages/auth/register.vue b/resources/assets/js/pages/auth/register.vue index be69fc71..486055ad 100644 --- a/resources/assets/js/pages/auth/register.vue +++ b/resources/assets/js/pages/auth/register.vue @@ -87,7 +87,7 @@ export default { const { data } = await this.form.post('/api/register') // Log in the user. - const { data: { token } } = await this.form.post('/api/login') + //const { data: { token } } = await this.form.post('/api/login') // Save the token. this.$store.dispatch('auth/saveToken', { token }) diff --git a/resources/assets/js/router/routes.js b/resources/assets/js/router/routes.js index 4597f12c..2fa40ae2 100644 --- a/resources/assets/js/router/routes.js +++ b/resources/assets/js/router/routes.js @@ -5,6 +5,8 @@ const PasswordEmail = () => import('~/pages/auth/password/email').then(m => m.de const PasswordReset = () => import('~/pages/auth/password/reset').then(m => m.default || m) const NotFound = () => import('~/pages/errors/404').then(m => m.default || m) +const EmailVerification = () => import('~/pages/auth/EmailVerification').then(m => m.default || m) + const Home = () => import('~/pages/home').then(m => m.default || m) const Settings = () => import('~/pages/settings/index').then(m => m.default || m) const SettingsProfile = () => import('~/pages/settings/profile').then(m => m.default || m) @@ -20,6 +22,8 @@ export default [ { path: '/password/reset', name: 'password.request', component: PasswordEmail }, { path: '/password/reset/:token', name: 'password.reset', component: PasswordReset }, + { path: '/user/verify/:token', name: 'email.verification', component: EmailVerification }, + { path: '/home', name: 'home', component: Home }, { path: '/settings', component: Settings, diff --git a/routes/api.php b/routes/api.php index bec708df..dfad4e89 100644 --- a/routes/api.php +++ b/routes/api.php @@ -49,7 +49,7 @@ Route::group(['middleware' => 'guest:api'], function () { Route::post('register', 'Auth\RegisterController@register'); Route::post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail'); Route::post('password/reset', 'Auth\ResetPasswordController@reset'); - + Route::get('user/verify/{token}', 'RegisterController@verifyUser'); Route::post('oauth/{driver}', 'Auth\OAuthController@redirectToProvider'); Route::get('oauth/{driver}/callback', 'Auth\OAuthController@handleProviderCallback')->name('oauth.callback'); }); diff --git a/routes/web.php b/routes/web.php index d4ecc79a..c440a077 100644 --- a/routes/web.php +++ b/routes/web.php @@ -12,7 +12,7 @@ */ Route::get('/', function () { - return view('welcome'); + return view('index'); }); /*Route for the booking */ diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 30abb800..d836e248 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -34,6 +34,7 @@ return array( 'App\\Http\\Middleware\\TrustProxies' => $baseDir . '/app/Http/Middleware/TrustProxies.php', 'App\\Http\\Middleware\\VerifyCsrfToken' => $baseDir . '/app/Http/Middleware/VerifyCsrfToken.php', 'App\\Notifications\\ResetPassword' => $baseDir . '/app/Notifications/ResetPassword.php', + 'App\\Notifications\\VerifyEmail' => $baseDir . '/app/Notifications/VerifyEmail.php', 'App\\OAuthProvider' => $baseDir . '/app/OAuthProvider.php', 'App\\Permission' => $baseDir . '/app/Permission.php', 'App\\Providers\\AppServiceProvider' => $baseDir . '/app/Providers/AppServiceProvider.php', @@ -47,6 +48,7 @@ return array( 'App\\SettingCredit' => $baseDir . '/app/SettingCredit.php', 'App\\SettingSupplier' => $baseDir . '/app/SettingSupplier.php', 'App\\User' => $baseDir . '/app/User.php', + 'App\\VerifyUser' => $baseDir . '/app/VerifyUser.php', 'BookTableSeeder' => $baseDir . '/database/seeds/BookTableSeeder.php', 'Carbon\\Carbon' => $vendorDir . '/nesbot/carbon/src/Carbon/Carbon.php', 'Carbon\\CarbonInterval' => $vendorDir . '/nesbot/carbon/src/Carbon/CarbonInterval.php', @@ -3726,7 +3728,6 @@ return array( 'Tests\\DuskTestCase' => $baseDir . '/tests/DuskTestCase.php', 'Tests\\Feature\\LocaleTest' => $baseDir . '/tests/Feature/LocaleTest.php', 'Tests\\Feature\\LoginTest' => $baseDir . '/tests/Feature/LoginTest.php', - 'Tests\\Feature\\OAuthTest' => $baseDir . '/tests/Feature/OAuthTest.php', 'Tests\\Feature\\RegisterTest' => $baseDir . '/tests/Feature/RegisterTest.php', 'Tests\\Feature\\SettingsTest' => $baseDir . '/tests/Feature/SettingsTest.php', 'Tests\\TestCase' => $baseDir . '/tests/TestCase.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 20eedeed..306ccb65 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,22 +4,22 @@ namespace Composer\Autoload; -class ComposerStaticInitebee75b176540aeb1d879b30f69e9dfc +class ComposerStaticInite450fcd5b0627496bb38e1386c9a81ad { public static $files = array ( '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php', '25072dd6e2470089de65ae7bf11d3109' => __DIR__ . '/..' . '/symfony/polyfill-php72/bootstrap.php', '667aeda72477189d0494fecd327c3641' => __DIR__ . '/..' . '/symfony/var-dumper/Resources/functions/dump.php', - 'a0edc8309cc5e1d60e3047b5df6b7052' => __DIR__ . '/..' . '/guzzlehttp/psr7/src/functions_include.php', '2c102faa651ef8ea5874edb585946bce' => __DIR__ . '/..' . '/swiftmailer/swiftmailer/lib/swift_required.php', + 'a0edc8309cc5e1d60e3047b5df6b7052' => __DIR__ . '/..' . '/guzzlehttp/psr7/src/functions_include.php', 'c964ee0ededf28c96ebd9db5099ef910' => __DIR__ . '/..' . '/guzzlehttp/promises/src/functions_include.php', - '37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php', '5255c38a0faeba867671b61dfda6d864' => __DIR__ . '/..' . '/paragonie/random_compat/lib/random.php', + '37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php', 'bd9634f2d41831496de0d3dfe4c94881' => __DIR__ . '/..' . '/symfony/polyfill-php56/bootstrap.php', 'f0906e6318348a765ffb6eb24e0d0938' => __DIR__ . '/..' . '/laravel/framework/src/Illuminate/Foundation/helpers.php', '58571171fd5812e6e447dce228f52f4d' => __DIR__ . '/..' . '/laravel/framework/src/Illuminate/Support/helpers.php', - '6124b4c8570aa390c21fafd04a26c69f' => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php', '801c31d8ed748cfa537fa45402288c95' => __DIR__ . '/..' . '/psy/psysh/src/functions.php', + '6124b4c8570aa390c21fafd04a26c69f' => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php', 'f18cc91337d49233e5754e93f3ed9ec3' => __DIR__ . '/..' . '/laravelcollective/html/src/helpers.php', ); @@ -140,8 +140,8 @@ class ComposerStaticInitebee75b176540aeb1d879b30f69e9dfc 'phpDocumentor\\Reflection\\' => array ( 0 => __DIR__ . '/..' . '/phpdocumentor/reflection-common/src', - 1 => __DIR__ . '/..' . '/phpdocumentor/reflection-docblock/src', - 2 => __DIR__ . '/..' . '/phpdocumentor/type-resolver/src', + 1 => __DIR__ . '/..' . '/phpdocumentor/type-resolver/src', + 2 => __DIR__ . '/..' . '/phpdocumentor/reflection-docblock/src', ), 'Zizaco\\Entrust\\' => array ( @@ -433,6 +433,7 @@ class ComposerStaticInitebee75b176540aeb1d879b30f69e9dfc 'App\\Http\\Middleware\\TrustProxies' => __DIR__ . '/../..' . '/app/Http/Middleware/TrustProxies.php', 'App\\Http\\Middleware\\VerifyCsrfToken' => __DIR__ . '/../..' . '/app/Http/Middleware/VerifyCsrfToken.php', 'App\\Notifications\\ResetPassword' => __DIR__ . '/../..' . '/app/Notifications/ResetPassword.php', + 'App\\Notifications\\VerifyEmail' => __DIR__ . '/../..' . '/app/Notifications/VerifyEmail.php', 'App\\OAuthProvider' => __DIR__ . '/../..' . '/app/OAuthProvider.php', 'App\\Permission' => __DIR__ . '/../..' . '/app/Permission.php', 'App\\Providers\\AppServiceProvider' => __DIR__ . '/../..' . '/app/Providers/AppServiceProvider.php', @@ -446,6 +447,7 @@ class ComposerStaticInitebee75b176540aeb1d879b30f69e9dfc 'App\\SettingCredit' => __DIR__ . '/../..' . '/app/SettingCredit.php', 'App\\SettingSupplier' => __DIR__ . '/../..' . '/app/SettingSupplier.php', 'App\\User' => __DIR__ . '/../..' . '/app/User.php', + 'App\\VerifyUser' => __DIR__ . '/../..' . '/app/VerifyUser.php', 'BookTableSeeder' => __DIR__ . '/../..' . '/database/seeds/BookTableSeeder.php', 'Carbon\\Carbon' => __DIR__ . '/..' . '/nesbot/carbon/src/Carbon/Carbon.php', 'Carbon\\CarbonInterval' => __DIR__ . '/..' . '/nesbot/carbon/src/Carbon/CarbonInterval.php', @@ -4125,7 +4127,6 @@ class ComposerStaticInitebee75b176540aeb1d879b30f69e9dfc 'Tests\\DuskTestCase' => __DIR__ . '/../..' . '/tests/DuskTestCase.php', 'Tests\\Feature\\LocaleTest' => __DIR__ . '/../..' . '/tests/Feature/LocaleTest.php', 'Tests\\Feature\\LoginTest' => __DIR__ . '/../..' . '/tests/Feature/LoginTest.php', - 'Tests\\Feature\\OAuthTest' => __DIR__ . '/../..' . '/tests/Feature/OAuthTest.php', 'Tests\\Feature\\RegisterTest' => __DIR__ . '/../..' . '/tests/Feature/RegisterTest.php', 'Tests\\Feature\\SettingsTest' => __DIR__ . '/../..' . '/tests/Feature/SettingsTest.php', 'Tests\\TestCase' => __DIR__ . '/../..' . '/tests/TestCase.php', @@ -4321,10 +4322,10 @@ class ComposerStaticInitebee75b176540aeb1d879b30f69e9dfc public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInitebee75b176540aeb1d879b30f69e9dfc::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInitebee75b176540aeb1d879b30f69e9dfc::$prefixDirsPsr4; - $loader->prefixesPsr0 = ComposerStaticInitebee75b176540aeb1d879b30f69e9dfc::$prefixesPsr0; - $loader->classMap = ComposerStaticInitebee75b176540aeb1d879b30f69e9dfc::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInite450fcd5b0627496bb38e1386c9a81ad::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInite450fcd5b0627496bb38e1386c9a81ad::$prefixDirsPsr4; + $loader->prefixesPsr0 = ComposerStaticInite450fcd5b0627496bb38e1386c9a81ad::$prefixesPsr0; + $loader->classMap = ComposerStaticInite450fcd5b0627496bb38e1386c9a81ad::$classMap; }, null, ClassLoader::class); }