{
diff --git a/src/Backoffice/Users/App/Notifications/UserRegistered.php b/src/Backoffice/Users/App/Notifications/UserRegistered.php
new file mode 100644
index 00000000000..fa78a14bee8
--- /dev/null
+++ b/src/Backoffice/Users/App/Notifications/UserRegistered.php
@@ -0,0 +1,35 @@
+
+ */
+ public function via(object $notifiable): array
+ {
+ return ['mail'];
+ }
+
+ public function toMail(User $notifiable): MailMessage
+ {
+ return (new MailMessage())
+ ->line("Welcome $notifiable->name, to our application Example.")
+ ->action('Our web', url('/'))
+ ->line('Thank you for using our application!');
+ }
+}
diff --git a/src/Backoffice/Users/Domain/Actions/StoreUserAction.php b/src/Backoffice/Users/Domain/Actions/StoreUserAction.php
index c2781dc539c..37c0f6cf2db 100644
--- a/src/Backoffice/Users/Domain/Actions/StoreUserAction.php
+++ b/src/Backoffice/Users/Domain/Actions/StoreUserAction.php
@@ -4,22 +4,24 @@
namespace Lightit\Backoffice\Users\Domain\Actions;
-use Illuminate\Contracts\Hashing\Hasher;
+use Lightit\Backoffice\Users\App\Notifications\UserRegistered;
use Lightit\Backoffice\Users\Domain\DataTransferObjects\UserDto;
use Lightit\Backoffice\Users\Domain\Models\User;
class StoreUserAction
{
- public function __construct(private readonly Hasher $hasher)
- {
- }
-
public function execute(UserDto $userDto): User
{
- return User::create([
+ $user = new User([
'name' => $userDto->getName(),
'email' => $userDto->getEmail(),
- 'password' => $this->hasher->make($userDto->getPassword()),
+ 'password' => $userDto->getPassword(),
]);
+
+ $user->save();
+
+ $user->notify(new UserRegistered());
+
+ return $user;
}
}
diff --git a/src/Backoffice/Users/Domain/Models/User.php b/src/Backoffice/Users/Domain/Models/User.php
index bf3f5125dda..68f2ebc5ef2 100644
--- a/src/Backoffice/Users/Domain/Models/User.php
+++ b/src/Backoffice/Users/Domain/Models/User.php
@@ -18,7 +18,7 @@
* @property string $name
* @property string $email
* @property \Illuminate\Support\Carbon|null $email_verified_at
- * @property mixed $password
+ * @property string $password
* @property string|null $remember_token
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
diff --git a/src/Shared/App/Exceptions/ExceptionHandler.php b/src/Shared/App/Exceptions/ExceptionHandler.php
index cd9a13bf9e4..ebfac1298f4 100644
--- a/src/Shared/App/Exceptions/ExceptionHandler.php
+++ b/src/Shared/App/Exceptions/ExceptionHandler.php
@@ -24,10 +24,10 @@
use Illuminate\Validation\ValidationException;
use Sentry\Laravel\Integration;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
-use Throwable;
class ExceptionHandler
{
+ /** @var array */
private array $noConvert = [];
protected function convertDefaultException(Exception $exception): void
@@ -36,7 +36,7 @@ protected function convertDefaultException(Exception $exception): void
AuthenticationException::class => UnauthenticatedException::class,
AuthorizationException::class => UnauthorizedException::class,
NotFoundHttpException::class => PageNotFoundException::class,
- ModelNotFoundException::class => PageNotFoundException::class,
+ ModelNotFoundException::class => ModelNotFoundHttpException::class,
BaseRelationNotFoundException::class => RelationNotFoundException::class,
ValidationException::class => function ($exception) {
throw new ValidationFailedException($exception->validator);
@@ -44,17 +44,10 @@ protected function convertDefaultException(Exception $exception): void
], array_flip($this->noConvert)));
}
- protected function getReportable(Exceptions $exceptions): void
- {
- $exceptions->reportable(function (Throwable $e) {
- Integration::captureUnhandledException($e);
- });
- }
-
public function getClosure(): Closure
{
return function (Exceptions $exceptions) {
- $this->getReportable($exceptions);
+ Integration::handles($exceptions);
$exceptions->render(function (Exception $exception) {
$this->convertDefaultException($exception);
diff --git a/src/Shared/App/Exceptions/ModelNotFoundHttpException.php b/src/Shared/App/Exceptions/ModelNotFoundHttpException.php
new file mode 100644
index 00000000000..21ff1096e1a
--- /dev/null
+++ b/src/Shared/App/Exceptions/ModelNotFoundHttpException.php
@@ -0,0 +1,24 @@
+create();
+ Notification::fake();
+
+ $data = StoreUserRequestFactory::new()->create([
+ 'password' => 'passw0rd'
+ ]);
postJson(url('/api/users'), $data)
->assertCreated();
@@ -21,5 +30,11 @@
'name' => $data['name'],
'email' => $data['email']
]);
+
+ $user = User::query()->firstOrFail();
+
+ assertTrue(Hash::check('passw0rd', $user->password));
+
+ Notification::assertSentTo($user, UserRegistered::class);
});
});