From 045cbfd95c611928aef1b877d1a3dc60d5f19580 Mon Sep 17 00:00:00 2001 From: Thom Hurks Date: Wed, 5 Sep 2018 01:16:37 +0200 Subject: [PATCH] Send an event when the user's email is verified Upon user email verification we may like to take certain immediate actions. For example, once we have verified that the user has a valid email from a certain company domain, we may assign a role automatically. --- src/Illuminate/Auth/Events/Verified.php | 28 +++++++++++++++++++ src/Illuminate/Auth/MustVerifyEmail.php | 4 +-- .../Foundation/Auth/VerifiesEmails.php | 5 +++- 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 src/Illuminate/Auth/Events/Verified.php diff --git a/src/Illuminate/Auth/Events/Verified.php b/src/Illuminate/Auth/Events/Verified.php new file mode 100644 index 000000000000..1d6e4c0f3448 --- /dev/null +++ b/src/Illuminate/Auth/Events/Verified.php @@ -0,0 +1,28 @@ +user = $user; + } +} diff --git a/src/Illuminate/Auth/MustVerifyEmail.php b/src/Illuminate/Auth/MustVerifyEmail.php index d20418880863..4d3bbe29f2b2 100644 --- a/src/Illuminate/Auth/MustVerifyEmail.php +++ b/src/Illuminate/Auth/MustVerifyEmail.php @@ -17,11 +17,11 @@ public function hasVerifiedEmail() /** * Mark the given user's email as verified. * - * @return void + * @return bool */ public function markEmailAsVerified() { - $this->forceFill(['email_verified_at' => $this->freshTimestamp()])->save(); + return $this->forceFill(['email_verified_at' => $this->freshTimestamp()])->save(); } /** diff --git a/src/Illuminate/Foundation/Auth/VerifiesEmails.php b/src/Illuminate/Foundation/Auth/VerifiesEmails.php index c35f8272dfe9..7622a9446142 100644 --- a/src/Illuminate/Foundation/Auth/VerifiesEmails.php +++ b/src/Illuminate/Foundation/Auth/VerifiesEmails.php @@ -2,6 +2,7 @@ namespace Illuminate\Foundation\Auth; +use Illuminate\Auth\Events\Verified; use Illuminate\Http\Request; trait VerifiesEmails @@ -30,7 +31,9 @@ public function show(Request $request) public function verify(Request $request) { if ($request->route('id') == $request->user()->getKey()) { - $request->user()->markEmailAsVerified(); + if ($request->user()->markEmailAsVerified()) { + event(new Verified($request->user())); + } } return redirect($this->redirectPath());