Added more user events
This commit is contained in:
41
app/Bus/Events/User/UserFailedTwoAuthEvent.php
Normal file
41
app/Bus/Events/User/UserFailedTwoAuthEvent.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Bus\Events\User;
|
||||
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
|
||||
/**
|
||||
* This is the user failed two auth event class.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
*/
|
||||
final class UserFailedTwoAuthEvent implements UserEventInterface
|
||||
{
|
||||
/**
|
||||
* The user that failed two auth.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Models\User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Create a new user failed two auth event instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\User $user
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
41
app/Bus/Events/User/UserLoggedInEvent.php
Normal file
41
app/Bus/Events/User/UserLoggedInEvent.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Bus\Events\User;
|
||||
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
|
||||
/**
|
||||
* This is the user logged in event class.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
*/
|
||||
final class UserLoggedInEvent implements UserEventInterface
|
||||
{
|
||||
/**
|
||||
* The user that logged in.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Models\User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Create a new user logged in event instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\User $user
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
41
app/Bus/Events/User/UserLoggedOutEvent.php
Normal file
41
app/Bus/Events/User/UserLoggedOutEvent.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Bus\Events\User;
|
||||
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
|
||||
/**
|
||||
* This is the user logged out event class.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
*/
|
||||
final class UserLoggedOutEvent implements UserEventInterface
|
||||
{
|
||||
/**
|
||||
* The user that logged out.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Models\User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Create a new user logged out event instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\User $user
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
41
app/Bus/Events/User/UserPassedTwoAuthEvent.php
Normal file
41
app/Bus/Events/User/UserPassedTwoAuthEvent.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Bus\Events\User;
|
||||
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
|
||||
/**
|
||||
* This is the user passed two auth event class.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
*/
|
||||
final class UserPassedTwoAuthEvent implements UserEventInterface
|
||||
{
|
||||
/**
|
||||
* The user that passed two auth.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Models\User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Create a new user passed two auth event instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\User $user
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,18 @@ class EventServiceProvider extends ServiceProvider
|
||||
'CachetHQ\Cachet\Bus\Events\Subscriber\SubscriberHasVerifiedEvent' => [
|
||||
//
|
||||
],
|
||||
'CachetHQ\Cachet\Bus\Events\User\UserFailedTwoAuthEvent' => [
|
||||
//
|
||||
],
|
||||
'CachetHQ\Cachet\Bus\Events\User\UserLoggedInEvent' => [
|
||||
//
|
||||
],
|
||||
'CachetHQ\Cachet\Bus\Events\User\UserLoggedOutEvent' => [
|
||||
//
|
||||
],
|
||||
'CachetHQ\Cachet\Bus\Events\User\UserPassedTwoAuthEvent' => [
|
||||
//
|
||||
],
|
||||
'CachetHQ\Cachet\Bus\Events\User\UserWasAddedEvent' => [
|
||||
//
|
||||
],
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Bus\Events\User\UserFailedTwoAuthEvent;
|
||||
use CachetHQ\Cachet\Bus\Events\User\UserLoggedOutEvent;
|
||||
use CachetHQ\Cachet\Bus\Events\User\UserPassedTwoAuthEvent;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -62,6 +65,8 @@ class AuthController extends Controller
|
||||
// We probably want to add support for "Remember me" here.
|
||||
Auth::attempt($loginData);
|
||||
|
||||
event(new UserLoggedInEvent(Auth::user()));
|
||||
|
||||
return Redirect::intended('dashboard');
|
||||
}
|
||||
|
||||
@@ -99,8 +104,14 @@ class AuthController extends Controller
|
||||
$valid = Google2FA::verifyKey(Auth::user()->google_2fa_secret, $code);
|
||||
|
||||
if ($valid) {
|
||||
event(new UserPassedTwoAuthEvent(Auth::user()));
|
||||
|
||||
event(new UserLoggedInEvent(Auth::user()));
|
||||
|
||||
return Redirect::intended('dashboard');
|
||||
} else {
|
||||
event(new UserFailedTwoAuthEvent(Auth::user()));
|
||||
|
||||
// Failed login, log back out.
|
||||
Auth::logout();
|
||||
|
||||
@@ -118,6 +129,8 @@ class AuthController extends Controller
|
||||
*/
|
||||
public function logoutAction()
|
||||
{
|
||||
event(new UserLoggedOutEvent(Auth::user()));
|
||||
|
||||
Auth::logout();
|
||||
|
||||
return Redirect::to('/');
|
||||
|
||||
Reference in New Issue
Block a user