Commit 22c2c384 authored by Taylor Otwell's avatar Taylor Otwell

Merge pull request #1485 from laravie/feature/auth-events

Add 'laravel.auth: login' and 'laravel.auth: logout' events.
parents 8541ff50 590872d3
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
use Laravel\Str; use Laravel\Str;
use Laravel\Cookie; use Laravel\Cookie;
use Laravel\Config; use Laravel\Config;
use Laravel\Event;
use Laravel\Session; use Laravel\Session;
use Laravel\Crypter; use Laravel\Crypter;
...@@ -112,6 +113,8 @@ abstract class Driver { ...@@ -112,6 +113,8 @@ abstract class Driver {
if ($remember) $this->remember($token); if ($remember) $this->remember($token);
Event::fire('laravel.auth: login');
return true; return true;
} }
...@@ -128,6 +131,8 @@ abstract class Driver { ...@@ -128,6 +131,8 @@ abstract class Driver {
Session::forget($this->token()); Session::forget($this->token());
Event::fire('laravel.auth: logout');
$this->token = null; $this->token = null;
} }
......
...@@ -17,6 +17,9 @@ class AuthTest extends PHPUnit_Framework_TestCase { ...@@ -17,6 +17,9 @@ class AuthTest extends PHPUnit_Framework_TestCase {
public function setUp() public function setUp()
{ {
$_SERVER['auth.login.stub'] = null; $_SERVER['auth.login.stub'] = null;
$_SERVER['test.user.login'] = null;
$_SERVER['test.user.logout'] = null;
Cookie::$jar = array(); Cookie::$jar = array();
Config::$items = array(); Config::$items = array();
Auth::driver()->user = null; Auth::driver()->user = null;
...@@ -30,6 +33,9 @@ class AuthTest extends PHPUnit_Framework_TestCase { ...@@ -30,6 +33,9 @@ class AuthTest extends PHPUnit_Framework_TestCase {
public function tearDown() public function tearDown()
{ {
$_SERVER['auth.login.stub'] = null; $_SERVER['auth.login.stub'] = null;
$_SERVER['test.user.login'] = null;
$_SERVER['test.user.logout'] = null;
Cookie::$jar = array(); Cookie::$jar = array();
Config::$items = array(); Config::$items = array();
Auth::driver()->user = null; Auth::driver()->user = null;
...@@ -300,6 +306,37 @@ class AuthTest extends PHPUnit_Framework_TestCase { ...@@ -300,6 +306,37 @@ class AuthTest extends PHPUnit_Framework_TestCase {
$this->assertTrue(Cookie::$jar['laravel_auth_drivers_fluent_remember']['expiration'] < time()); $this->assertTrue(Cookie::$jar['laravel_auth_drivers_fluent_remember']['expiration'] < time());
} }
/**
* Test `laravel.auth: login` and `laravel.auth: logout` is called properly
*
* @group laravel
*/
public function testAuthEventIsCalledProperly()
{
Session::$instance = new Payload($this->getMock('Laravel\\Session\\Drivers\\Driver'));
Event::listen('laravel.auth: login', function ()
{
$_SERVER['test.user.login'] = 'foo';
});
Event::listen('laravel.auth: logout', function ()
{
$_SERVER['test.user.logout'] = 'foo';
});
$this->assertNull($_SERVER['test.user.login']);
$this->assertNull($_SERVER['test.user.logout']);
Auth::login(1, true);
$this->assertEquals('foo', $_SERVER['test.user.login']);
Auth::logout();
$this->assertEquals('foo', $_SERVER['test.user.logout']);
}
} }
class AuthUserReturnsNull extends Laravel\Auth\Drivers\Driver { class AuthUserReturnsNull extends Laravel\Auth\Drivers\Driver {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment