Skip to content

Commit 39552d1

Browse files
committed
wip
1 parent 898e29f commit 39552d1

File tree

15 files changed

+447
-105
lines changed

15 files changed

+447
-105
lines changed

composer.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
],
2323
"require": {
2424
"php": "^8.1",
25-
"backstage/laravel-users": "^0.1.0",
25+
"backstage/laravel-users": "^0.1.1",
2626
"filament/filament": "^4.0",
2727
"laravel/sanctum": ">=3.3.3",
2828
"spatie/laravel-package-tools": "^1.15.0",
29-
"spatie/laravel-permission": ">=6.0"
29+
"spatie/laravel-permission": ">=6.0",
30+
"lorisleiva/laravel-actions": ">=2.8"
3031
},
3132
"require-dev": {
3233
"laravel/pint": "^1.0",
@@ -97,5 +98,11 @@
9798
}
9899
},
99100
"minimum-stability": "dev",
100-
"prefer-stable": true
101+
"prefer-stable": true,
102+
"repositories": {
103+
"backstage/laravel-users": {
104+
"type": "vcs",
105+
"url": "git@github.com:backstagephp/laravel-users.git"
106+
}
107+
}
101108
}
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
<x-filament-panels::page.simple>
2-
3-
<x-filament-panels::form id="form" wire:submit="register">
4-
{{ $this->registerForm }}
5-
6-
<x-filament-panels::form.actions
7-
:actions="$this->getCachedFormActions()"
8-
:full-width="$this->hasFullWidthFormActions()"
9-
/>
10-
</x-filament-panels::form>
2+
{{ $this->form }}
113
</x-filament-panels::page.simple>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Backstage\Filament\Users\Actions;
4+
5+
use Illuminate\Support\Uri;
6+
use Filament\Facades\Filament;
7+
use Illuminate\Database\Eloquent\Model;
8+
use Lorisleiva\Actions\Concerns\AsAction;
9+
use Backstage\Filament\Users\Pages\RegisterFromInvitationPage;
10+
11+
class GenerateSignedRegistrationUri
12+
{
13+
use AsAction;
14+
15+
public function handle(Model $user): string
16+
{
17+
$dedicatedPanel = Filament::getPanel('register');
18+
19+
$routename = RegisterFromInvitationPage::getRouteName($dedicatedPanel);
20+
21+
$encryptedUserId = encrypt($user->getKey());
22+
23+
$signedRouteUri = Uri::signedRoute($routename, [
24+
'userId' => $encryptedUserId,
25+
]);
26+
27+
$url = Uri::to($signedRouteUri)->__toString();
28+
29+
return $url;
30+
}
31+
}

src/Events/FilamentUserCreated.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Backstage\Filament\Users\Events;
4+
5+
use Backstage\Filament\Users\Models\User;
6+
use Illuminate\Bus\Queueable;
7+
use Illuminate\Foundation\Events\Dispatchable;
8+
use Illuminate\Queue\SerializesModels;
9+
10+
class FilamentUserCreated
11+
{
12+
use Dispatchable;
13+
use Queueable;
14+
use SerializesModels;
15+
16+
protected User $user;
17+
18+
/**
19+
* The user instance.
20+
*
21+
* @var User
22+
*/
23+
public function __construct(User $user)
24+
{
25+
$this->user = $user;
26+
}
27+
28+
/**
29+
* Get the user instance.
30+
*
31+
* @return User
32+
*/
33+
public function getUser(): User
34+
{
35+
return $this->user;
36+
}
37+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Backstage\Filament\Users\Listeners;
4+
5+
use Backstage\Filament\Users\Events\FilamentUserCreated;
6+
use Backstage\Filament\Users\Notifications\UserInvitationNotification;
7+
use Backstage\Laravel\Users\Events\Auth\UserCreated;
8+
use Backstage\Laravel\Users\Notifications\Invitation;
9+
10+
class SendFilamentInvitationMail
11+
{
12+
public function handle(FilamentUserCreated $event)
13+
{
14+
$user = $event->getUser();
15+
16+
$invitation = new UserInvitationNotification;
17+
18+
$user->notify($invitation);
19+
}
20+
}

src/Models/User.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Backstage\Filament\Users\Models;
44

55
use Backstage\Filament\Users\Concerns\Conditionals\HasSubNavigationPreference;
6+
use Backstage\Filament\Users\Events\FilamentUserCreated;
67
use Backstage\Laravel\Users\Eloquent\Models\User as BaseUser;
78
use Filament\Models\Contracts\FilamentUser;
89
use Filament\Panel;
@@ -11,8 +12,25 @@ class User extends BaseUser implements FilamentUser
1112
{
1213
use HasSubNavigationPreference;
1314

15+
protected function casts(): array
16+
{
17+
return [
18+
'email_verified_at' => 'datetime',
19+
'password' => 'hashed',
20+
];
21+
}
22+
1423
public function canAccessPanel(Panel $panel): bool
1524
{
1625
return true;
1726
}
27+
28+
protected static function boot()
29+
{
30+
parent::boot();
31+
32+
static::created(function (self $user) {
33+
event(new FilamentUserCreated($user));
34+
});
35+
}
1836
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace Backstage\Filament\Users\Notifications;
4+
5+
use Illuminate\Support\Uri;
6+
use Illuminate\Bus\Queueable;
7+
use Filament\Facades\Filament;
8+
use Illuminate\Notifications\Notification;
9+
use Backstage\Laravel\Users\Eloquent\Models\User;
10+
use Illuminate\Notifications\Messages\MailMessage;
11+
use Backstage\Filament\Users\Pages\RegisterFromInvitationPage;
12+
use Backstage\Filament\Users\Actions\GenerateSignedRegistrationUri;
13+
14+
class UserInvitationNotification extends Notification
15+
{
16+
use Queueable;
17+
18+
/**
19+
* Create a new notification instance.
20+
*/
21+
public function __construct() {}
22+
23+
/**
24+
* Get the notification's delivery channels.
25+
*
26+
* @return array<int, string>
27+
*/
28+
public function via(User $notifiable): array
29+
{
30+
return config('users.events.auth.user_created.notification_delivery_channels', ['mail']);
31+
}
32+
33+
/**
34+
* Get the mail representation of the notification.
35+
*/
36+
public function toMail(User $notifiable): MailMessage
37+
{
38+
/**
39+
* Mask the $dedicatedPanel variable as string to get the route name for the RegisterFromInvitationPage.
40+
*
41+
* @var string $dedicatedPanel
42+
*/
43+
$url = GenerateSignedRegistrationUri::run(user: $notifiable);
44+
45+
return (new MailMessage)
46+
->subject(__('Welcome to Our Platform'))
47+
->greeting(__('Hello :name!', ['name' => $notifiable->getAttribute('name')]))
48+
->line(__('We are excited to have you on board.'))
49+
->action(__('Register'), $url)
50+
->line(__('If you did not sign up, request this invitation, or expect to receive it, please ignore this email.'));
51+
}
52+
53+
public function toArray(User $notifiable): array
54+
{
55+
return [];
56+
}
57+
}

0 commit comments

Comments
 (0)