Initial commit

This commit is contained in:
Ronald Huynen
2026-03-23 21:37:59 +01:00
commit 2547717edb
2193 changed files with 972171 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Events\Auth;
use App\Models\Admin;
use App\Models\Bank;
use App\Models\Organization;
use App\Models\User;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class RegisteredByAdmin
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;
/**
* The newly registered profile instance.
* @var \App\Models\User|\App\Models\Organization|\App\Models\Bank|\App\Models\Admin
*/
public $profile;
/**
* The plain-text password, if one was generated.
* @var string|null
*/
public ?string $plainPassword; // Add this property
/**
* Create a new event instance.
*
* @param \App\Models\User|\App\Models\Organization|\App\Models\Bank|\App\Models\Admin $profile
* @param string|null $plainPassword The generated plain-text password, if applicable.
* @return void
*/
// Add $plainPassword to the constructor
public function __construct(User|Organization|Bank|Admin $profile, ?string $plainPassword = null)
{
$this->profile = $profile;
$this->plainPassword = $plainPassword; // Assign it
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Auth;
class ProfileSwitchEvent implements ShouldBroadcastNow
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;
public $activeProfile;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($activeProfile)
{
$this->activeProfile = $activeProfile;
$this->checkVerification();
}
public function checkVerification()
{
// Use the query method which is clearly available
$profile = getActiveProfile();
if ($profile && method_exists($profile, 'hasVerifiedEmail') && ! $profile->hasVerifiedEmail()) {
$profile->sendEmailVerificationNotification();
session(['notification.alert' => 'Your profiles email address is unverified. We have just sent you a new verification email. The link in this email will expire within 60 minutes.']);
}
activity()
->useLog('Active profile')
->performedOn($profile)
->causedBy(Auth::guard('web')->user())
->withProperties([
'attributes' => [
'last_login_at' => now()->toDateTimeString(),
],
'old' => [
'last_login_at' => ($profile->last_login_at instanceof \Carbon\Carbon)
? $profile->last_login_at->toDateTimeString()
: $profile->last_login_at,
],
])
->event('switched')
->log('Switched to ' . $profile->name);
}
public function broadcastQueue()
{
return 'broadcastable';
}
public function broadcastWith()
{
return [
'userId' => $this->activeProfile['userId'],
'type' => $this->activeProfile['type'],
'id' => $this->activeProfile['id'],
'name' => $this->activeProfile['name'],
'photo' => $this->activeProfile['photo']
];
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('switch-profile.' . $this->activeProfile['userId']);
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Events;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class ProfileVerified
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;
public $profileModel;
/**
* Create a new event instance.
* To update the email_verified_at record of the profile's model
*
* @param mixed $profileModel
* @return void
*/
public function __construct($profileModel)
{
$this->profileModel = $profileModel;
}
}

View 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.',
];
}
}

View File

@@ -0,0 +1,46 @@
<?php
// 5. Event Broadcasting for Real-time Updates
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class UserPresenceUpdated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $user;
public $guard;
public $status; // 'online' or 'offline'
public function __construct($user, $guard, $status = 'online')
{
$this->user = $user;
$this->guard = $guard;
$this->status = $status;
}
public function broadcastOn()
{
return new PresenceChannel("presence-{$this->guard}-users");
}
public function broadcastWith()
{
return [
'user' => [
'id' => $this->user->id,
'name' => $this->user->name,
'avatar' => $this->user->avatar ?? null,
],
'guard' => $this->guard,
'status' => $this->status,
'timestamp' => now(),
];
}
}

View File

@@ -0,0 +1,55 @@
<?php
// app/Events/WireChatUserTyping.php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class WireChatUserTyping implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $conversationId;
public $user;
public $action; // 'start' or 'stop'
public $timestamp;
public function __construct($conversationId, $user, $action = 'start')
{
$this->conversationId = $conversationId;
$this->user = $user;
$this->action = $action;
$this->timestamp = now();
}
public function broadcastOn()
{
// Broadcast to the conversation channel (similar to WireChat's MessageCreated event)
return new PrivateChannel("conversation.{$this->conversationId}");
}
public function broadcastWith()
{
return [
'conversation_id' => $this->conversationId,
'user' => [
'id' => $this->user->id,
'name' => $this->user->name,
'type' => $this->user->getMorphClass(),
'avatar' => $this->user->avatar ?? null,
],
'action' => $this->action,
'timestamp' => $this->timestamp,
];
}
public function broadcastAs()
{
return 'WireChatUserTyping';
}
}