From cb834d10bb42af4fb1e7b812477caf73a3b513a3 Mon Sep 17 00:00:00 2001 From: pajri Date: Thu, 29 Dec 2022 09:22:28 +0700 Subject: [PATCH] WIP email notification --- Modules/Internal/Emails/SendVerifyEmail.php | 37 +++++++++++ Modules/Internal/Events/ForgetPassword.php | 32 ++++++++++ .../Http/Controllers/Api/AuthController.php | 6 ++ .../Internal/Listeners/SendVerifyEmail.php | 31 ++++++++++ .../Notifications/NotifyVerifyEmail.php | 61 +++++++++++++++++++ .../Providers/EventServiceProvider.php | 35 +++++++++++ .../Providers/InternalServiceProvider.php | 8 ++- Modules/Internal/module.json | 3 +- 8 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 Modules/Internal/Emails/SendVerifyEmail.php create mode 100644 Modules/Internal/Events/ForgetPassword.php create mode 100644 Modules/Internal/Listeners/SendVerifyEmail.php create mode 100644 Modules/Internal/Notifications/NotifyVerifyEmail.php create mode 100644 Modules/Internal/Providers/EventServiceProvider.php diff --git a/Modules/Internal/Emails/SendVerifyEmail.php b/Modules/Internal/Emails/SendVerifyEmail.php new file mode 100644 index 00000000..4dd6f5a8 --- /dev/null +++ b/Modules/Internal/Emails/SendVerifyEmail.php @@ -0,0 +1,37 @@ +data = $data; + } + + /** + * Build the message. + * + * @return $this + */ + public function build() + { + $this->subject('Verify Email') + ->markdown('email_user'); + + return $this; + } +} diff --git a/Modules/Internal/Events/ForgetPassword.php b/Modules/Internal/Events/ForgetPassword.php new file mode 100644 index 00000000..86be3a9a --- /dev/null +++ b/Modules/Internal/Events/ForgetPassword.php @@ -0,0 +1,32 @@ +data = $data; + } + + /** + * Get the channels the event should be broadcast on. + * + * @return array + */ + public function broadcastOn() + { + return new PrivateChannel('channel-name'); + } +} diff --git a/Modules/Internal/Http/Controllers/Api/AuthController.php b/Modules/Internal/Http/Controllers/Api/AuthController.php index ed86e0e0..709710dc 100755 --- a/Modules/Internal/Http/Controllers/Api/AuthController.php +++ b/Modules/Internal/Http/Controllers/Api/AuthController.php @@ -7,6 +7,9 @@ use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Mail; +use Modules\Internal\Emails\SendVerifyEmail; +use Modules\Internal\Events\ForgetPassword; class AuthController extends Controller { @@ -84,6 +87,9 @@ class AuthController extends Controller return response(['message' => 'User Tidak Ditemukan'], 404); } + + Mail::to($user->email)->send(new SendVerifyEmail($user)); + return response()->json($user); } diff --git a/Modules/Internal/Listeners/SendVerifyEmail.php b/Modules/Internal/Listeners/SendVerifyEmail.php new file mode 100644 index 00000000..409346b3 --- /dev/null +++ b/Modules/Internal/Listeners/SendVerifyEmail.php @@ -0,0 +1,31 @@ +data); + } +} diff --git a/Modules/Internal/Notifications/NotifyVerifyEmail.php b/Modules/Internal/Notifications/NotifyVerifyEmail.php new file mode 100644 index 00000000..6d6f9c5d --- /dev/null +++ b/Modules/Internal/Notifications/NotifyVerifyEmail.php @@ -0,0 +1,61 @@ +line('The introduction to the notification.') + ->action('Notification Action', 'https://laravel.com') + ->line('Thank you for using our application!'); + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } +} diff --git a/Modules/Internal/Providers/EventServiceProvider.php b/Modules/Internal/Providers/EventServiceProvider.php new file mode 100644 index 00000000..f8a3dfbe --- /dev/null +++ b/Modules/Internal/Providers/EventServiceProvider.php @@ -0,0 +1,35 @@ + [ + SendVerifyEmail::class, + ], + ]; + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + // + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return []; + } +} diff --git a/Modules/Internal/Providers/InternalServiceProvider.php b/Modules/Internal/Providers/InternalServiceProvider.php index 1860e70d..24616a21 100755 --- a/Modules/Internal/Providers/InternalServiceProvider.php +++ b/Modules/Internal/Providers/InternalServiceProvider.php @@ -7,6 +7,11 @@ use Illuminate\Database\Eloquent\Factory; class InternalServiceProvider extends ServiceProvider { + protected $listen = [ + ForgetPassword::class => [ + SendVerifyEmail::class, + ], + ]; /** * @var string $moduleName */ @@ -51,7 +56,8 @@ class InternalServiceProvider extends ServiceProvider module_path($this->moduleName, 'Config/config.php') => config_path($this->moduleNameLower . '.php'), ], 'config'); $this->mergeConfigFrom( - module_path($this->moduleName, 'Config/config.php'), $this->moduleNameLower + module_path($this->moduleName, 'Config/config.php'), + $this->moduleNameLower ); } diff --git a/Modules/Internal/module.json b/Modules/Internal/module.json index 32eb0af3..ba46db3d 100755 --- a/Modules/Internal/module.json +++ b/Modules/Internal/module.json @@ -5,7 +5,8 @@ "keywords": [], "priority": 0, "providers": [ - "Modules\\Internal\\Providers\\InternalServiceProvider" + "Modules\\Internal\\Providers\\InternalServiceProvider", + "Modules\\Internal\\Providers\\EventServiceProvider" ], "aliases": {}, "files": [],