Initial commit
This commit is contained in:
65
app/Events/UserForcedLogout.php
Normal file
65
app/Events/UserForcedLogout.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class UserForcedLogout implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $userId;
|
||||
public $guard;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct($userId, $guard = 'web')
|
||||
{
|
||||
$this->userId = $userId;
|
||||
$this->guard = $guard;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new PrivateChannel('user.logout.' . $this->userId),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The event's broadcast name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function broadcastAs()
|
||||
{
|
||||
return 'forced-logout';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data to broadcast.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function broadcastWith()
|
||||
{
|
||||
return [
|
||||
'user_id' => $this->userId,
|
||||
'guard' => $this->guard,
|
||||
// Send translation key instead of translated message so it translates in user's locale
|
||||
'message_key' => 'For security and maintenance, a system administrator has logged you out of your account. Sorry for this inconvenience and thanks for your patience.',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user