-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from rickwest/confirmed
Dispatch a Confirmed event and confirmed method on successful confirmation.
- Loading branch information
Showing
5 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace BeyondCode\EmailConfirmation\Events; | ||
|
||
use Illuminate\Queue\SerializesModels; | ||
|
||
/** | ||
* Class Confirmed | ||
* @package BeyondCode\EmailConfirmation\Events | ||
*/ | ||
class Confirmed | ||
{ | ||
use SerializesModels; | ||
|
||
/** | ||
* The authenticated user. | ||
* | ||
* @var \Illuminate\Contracts\Auth\Authenticatable | ||
*/ | ||
public $user; | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @param \Illuminate\Contracts\Auth\Authenticatable $user | ||
* @return void | ||
*/ | ||
public function __construct($user) | ||
{ | ||
$this->user = $user; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ | |
|
||
namespace BeyondCode\EmailConfirmation\Tests; | ||
|
||
use BeyondCode\EmailConfirmation\Events\Confirmed; | ||
use Illuminate\Auth\Notifications\ResetPassword; | ||
use Illuminate\Support\Facades\Event; | ||
use Illuminate\Support\Facades\Notification; | ||
use BeyondCode\EmailConfirmation\Tests\Models\User; | ||
use BeyondCode\EmailConfirmation\Notifications\ConfirmEmail; | ||
|
@@ -141,4 +143,37 @@ public function it_does_not_allow_reset_password_request_for_unconfirmed_users() | |
|
||
Notification::assertNotSentTo($user, ResetPassword::class); | ||
} | ||
|
||
/** @test */ | ||
public function it_dispatches_confirmed_event_on_successful_confirmation() | ||
{ | ||
Event::fake(); | ||
|
||
$user = User::create([ | ||
'email' => '[email protected]', | ||
'password' => bcrypt('test123'), | ||
'confirmed_at' => null, | ||
'confirmation_code' => 'abcdefg' | ||
]); | ||
|
||
$response = $this->get('/register/confirm/abcdefg'); | ||
|
||
Event::assertDispatched(Confirmed::class, function ($e) use ($user) { | ||
return $e->user->email === $user->email; | ||
}); | ||
|
||
$response->assertRedirect('/login'); | ||
} | ||
|
||
/** @test */ | ||
public function it_does_not_dispatch_confirmed_event_on_failed_confirmation() | ||
{ | ||
Event::fake(); | ||
|
||
$response = $this->get('/register/confirm/foo'); | ||
|
||
Event::assertNotDispatched(Confirmed::class); | ||
|
||
$response->assertStatus(404); | ||
} | ||
} |