Laravel Spark User Verification

Ian Fagg
Ian Fagg
Aug 8, 2017 · 2 min read

Update routes:

// Overwrite Spark’s Register function so we can add User Verification…
Route::post(‘/register’, ‘Auth\RegisterController@register’);
// Overwrite Spark’s login function so we can add User Verification…Route::post(‘/login’, ‘Auth\LoginController@login’);// To stop un-verified users getting a reset email…Route::post(‘/password/email’, ‘Auth\PasswordController@sendResetLinkEmail’);

Create RegisterController:

namespace App\Http\Controllers\Auth;
use Illuminate\Auth\Events\Registered;
use Jrean\UserVerification\Traits\VerifiesUsers;
use Jrean\UserVerification\Facades\UserVerification;
use VerifiesUsers;
$this->middleware(‘guest’, [‘except’ => [‘getVerification’, ‘getVerificationError’]]);
$this->redirectTo = Spark::afterLoginRedirect();
$this->redirectAfterVerification = ‘/login’;
public function register(RegisterRequest $request)
{
$user = Spark::interact(Register::class, [$request]);
UserVerification::generate($user);
event(new UserRegistered($user));
UserVerification::send($user, ‘verification’);
return response()->json([
‘redirect’ => ‘/login’
]);
}

Create LoginController:

Update Login view:

@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif

Create PasswordController:

Update EventServiceProvider:

// User Verification Events...
'Jrean\UserVerification\Events\VerificationEmailSent' => [
'App\Listeners\AlertVerificationEmailSent',
],
'Jrean\UserVerification\Events\UserVerified' => [
'App\Listeners\AlertUserVerified',
],

Create AlertUserVerified listener:

Create AlertVerificationEmailSent listener:

Conclusion

NOTE:

Ian Fagg

Written by

Ian Fagg

Web developer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade