Skip to content

Commit

Permalink
Send an event when the user's email is verified
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ThomHurks committed Sep 4, 2018
1 parent 6a8ab13 commit 045cbfd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
28 changes: 28 additions & 0 deletions src/Illuminate/Auth/Events/Verified.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Illuminate\Auth\Events;

use Illuminate\Queue\SerializesModels;

class Verified
{
use SerializesModels;

/**
* The verified user.
*
* @var \Illuminate\Contracts\Auth\MustVerifyEmail
*/
public $user;

/**
* Create a new event instance.
*
* @param \Illuminate\Contracts\Auth\MustVerifyEmail $user
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
}
4 changes: 2 additions & 2 deletions src/Illuminate/Auth/MustVerifyEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Illuminate/Foundation/Auth/VerifiesEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Foundation\Auth;

use Illuminate\Auth\Events\Verified;
use Illuminate\Http\Request;

trait VerifiesEmails
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 045cbfd

Please sign in to comment.