This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release Version 0.2.0 version bump updates
- Loading branch information
Showing
34 changed files
with
1,383 additions
and
21 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
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,142 @@ | ||
.. _events: | ||
|
||
|
||
Laravel Events | ||
============== | ||
|
||
This package provides a number of `events`_ allowing you to respond to user | ||
actions as they happen. | ||
|
||
|
||
Available Events | ||
---------------- | ||
|
||
The following events (and their corresponding classes) are triggered during | ||
Stormpath operations: | ||
|
||
+-----------------------------------+------------------------------------------------------+ | ||
| Class | Description | | ||
+===================================+======================================================+ | ||
| ``UserIsRegistering`` | A potential new user has completed the registration | | ||
| (cancellable) | form and submitted it. The form data has passed | | ||
| | validation. | | ||
+-----------------------------------+------------------------------------------------------+ | ||
| ``UserHasRegistered`` | A new user has registered. | | ||
+-----------------------------------+------------------------------------------------------+ | ||
| ``UserIsLoggingIn`` | A user has completed the login form and submitted it.| | ||
| (cancellable) | The form data has passed the initial validation, but | | ||
| | the user has not been authenticated yet. | | ||
+-----------------------------------+------------------------------------------------------+ | ||
| ``UserHasLoggedIn`` | A user has successfully logged in. | | ||
+-----------------------------------+------------------------------------------------------+ | ||
| ``UserIsLoggingOut`` | A user has visited the ``logout`` URL but has not | | ||
| (cancellable) | been logged out yet. | | ||
+-----------------------------------+------------------------------------------------------+ | ||
| ``UserHasLoggedOut`` | A user has successfully logged out. | | ||
+-----------------------------------+------------------------------------------------------+ | ||
| ``UserHasRequestedPasswordReset`` | A user has completed the password reset form and the | | ||
| | password reset email has been sent. | | ||
+-----------------------------------+------------------------------------------------------+ | ||
| ``UserHasResetPassword`` | A user has successfully reset their password. | | ||
+-----------------------------------+------------------------------------------------------+ | ||
|
||
Note that all of the class names above are in the ``Stormpath\Laravel\Events`` | ||
namespace. | ||
|
||
|
||
Listening for Events | ||
-------------------- | ||
|
||
To register your listeners for these events, follow the | ||
`Laravel documentation for Registering Events`_. For example, to register a | ||
listener for the "registered" event, add the following to your | ||
``EventServiceProvider``:: | ||
|
||
protected $listen = [ | ||
'Stormpath\Laravel\Events\UserHasRegistered' => [ | ||
'App\Listeners\HandleNewUserRegistration', | ||
], | ||
]; | ||
|
||
where ``App\Listeners\HandleNewUserRegistration`` is a class in your application | ||
which handles the event when it is fired. The listener class is defined | ||
according to the `Laravel documentation on defining listeners`_. | ||
|
||
|
||
Terminating Event Actions | ||
------------------------- | ||
|
||
There may be times when it is necessary to halt processing based on some | ||
processing you are doing in your listener. To do this, simply return ``false`` | ||
from the ``handle`` method of your listener. Note that this will only have an | ||
effect for the events that are marked as "cancellable" in the table above. | ||
|
||
For example, maybe you want to prevent a user from registering if their first | ||
name is "Bob". Your handler should look like this:: | ||
|
||
public function handle(UserIsRegistering $event) | ||
{ | ||
// get the form data that the user has submitted | ||
// | ||
$data = $event->getData(); | ||
|
||
// check the givenName field | ||
// | ||
if ($data['givenName']=='Bob') { | ||
return false; | ||
} | ||
|
||
// the name is not Bob, so just carry on... | ||
} | ||
|
||
This will abort the registration request. When this is done, a | ||
``Stormpath\Laravel\Exceptions\ActionAbortedException`` will be thrown. In the | ||
example above, you might catch that exception & redirect the user to a page that | ||
says "No Bobs Allowed!" | ||
|
||
|
||
Event Class Parameters | ||
---------------------- | ||
|
||
Most of the event classes include data related to the event occurring. The | ||
important data is retrieved via an accessor function. | ||
|
||
+-----------------------------------+----------------+------------------------------------------------------+ | ||
| Class | Accessor | Description | | ||
+===================================+================+======================================================+ | ||
| ``UserIsRegistering`` | ``getData`` | ``array`` - The form data entered by the user | | ||
+-----------------------------------+----------------+------------------------------------------------------+ | ||
| ``UserHasRegistered`` | ``getAccount`` | ``Stormpath\Resource\Account`` - The account object | | ||
| | | for the newly-registered user | | ||
+-----------------------------------+----------------+------------------------------------------------------+ | ||
| ``UserIsLoggingIn`` | ``getData`` | ``array`` - The form data entered by the user | | ||
+-----------------------------------+----------------+------------------------------------------------------+ | ||
| ``UserHasLoggedIn`` | ``getAccount`` | ``Stormpath\Resource\Account`` - The account object | | ||
| | | for the user who has just logged in | | ||
+-----------------------------------+----------------+------------------------------------------------------+ | ||
| ``UserIsLoggingOut`` | n/a | No parameters | | ||
+-----------------------------------+----------------+------------------------------------------------------+ | ||
| ``UserHasLoggedOut`` | n/a | No parameters | | ||
+-----------------------------------+----------------+------------------------------------------------------+ | ||
| ``UserHasRequestedPasswordReset`` | ``getData`` | ``array`` - The form data entered by the user | | ||
+-----------------------------------+----------------+------------------------------------------------------+ | ||
| ``UserHasResetPassword`` | n/a | No parameters | | ||
+-----------------------------------+----------------+------------------------------------------------------+ | ||
|
||
So, for example, if you want to do something with a user who has just logged | ||
out, the handler might look like this:: | ||
|
||
public function handle(UserHasLoggedOut $event) | ||
{ | ||
// get the user account | ||
// | ||
$user = $event->getAccount(); | ||
|
||
// do something with the user... | ||
} | ||
|
||
|
||
|
||
.. _events: https://laravel.com/docs/5.2/events | ||
.. _Laravel documentation for Registering Events: https://laravel.com/docs/5.2/events#registering-events-and-listeners | ||
.. _Laravel documentation on defining listeners: https://laravel.com/docs/5.2/events#defining-listeners |
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
Empty file.
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,35 @@ | ||
<?php | ||
|
||
namespace Stormpath\Laravel\Events; | ||
|
||
use Stormpath\Resource\Account; | ||
|
||
class UserHasLoggedIn | ||
{ | ||
/** | ||
* The account property | ||
* | ||
* @var Account | ||
*/ | ||
private $account = null; | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @param array $data The form data from the log in request | ||
*/ | ||
public function __construct(Account $account) | ||
{ | ||
$this->account = $account; | ||
} | ||
|
||
/** | ||
* Get the account associated with this event | ||
* | ||
* @return Account The account associated with this event | ||
*/ | ||
public function getAccount() | ||
{ | ||
return $this->account; | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace Stormpath\Laravel\Events; | ||
|
||
use Stormpath\Resource\Account; | ||
|
||
class UserHasRegistered | ||
{ | ||
/** | ||
* The account property | ||
* | ||
* @var Account | ||
*/ | ||
private $account = null; | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @param array $data The form data from the registration request | ||
*/ | ||
public function __construct(Account $account) | ||
{ | ||
$this->account = $account; | ||
} | ||
|
||
/** | ||
* Get the account associated with this event | ||
* | ||
* @return Account The account associated with this event | ||
*/ | ||
public function getAccount() | ||
{ | ||
return $this->account; | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
namespace Stormpath\Laravel\Events; | ||
|
||
|
||
class UserHasRequestedPasswordReset | ||
{ | ||
/** | ||
* The form data | ||
* | ||
* @var array | ||
*/ | ||
private $data = null; | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @param array $data The form data from the registration request | ||
*/ | ||
public function __construct(array $data) | ||
{ | ||
$this->data = $data; | ||
} | ||
|
||
/** | ||
* Get the form data provided with this event | ||
* | ||
* @return array The form data | ||
*/ | ||
public function getData() | ||
{ | ||
return $this->data; | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace Stormpath\Laravel\Events; | ||
|
||
|
||
class UserHasResetPassword | ||
{ | ||
/** | ||
* Create a new event instance. | ||
* | ||
* @param array $data The form data from the registration request | ||
*/ | ||
public function __construct() | ||
{ | ||
} | ||
} |
Oops, something went wrong.