From e38aa039d56cc8ff01ca2c451e0cf4a1923048db Mon Sep 17 00:00:00 2001 From: spektra2147 Date: Wed, 30 Nov 2022 16:15:06 +0300 Subject: [PATCH] fix notifications --- app/Notification/ActivateYourAccount.php | 69 +++++++++++++ app/Notification/PasswordInvalidated.php | 72 ++++++++++++++ app/Notification/ResetYourPassword.php | 72 ++++++++++++++ app/Notification/UserHasBeenActivated.php | 52 ++++++++++ app/Notification/UserHasRegistered.php | 110 +++++++++++++++++++++ app/Notification/UserPendingActivation.php | 68 +++++++++++++ config/app.php | 17 +++- 7 files changed, 459 insertions(+), 1 deletion(-) create mode 100644 app/Notification/ActivateYourAccount.php create mode 100644 app/Notification/PasswordInvalidated.php create mode 100644 app/Notification/ResetYourPassword.php create mode 100644 app/Notification/UserHasBeenActivated.php create mode 100644 app/Notification/UserHasRegistered.php create mode 100644 app/Notification/UserPendingActivation.php diff --git a/app/Notification/ActivateYourAccount.php b/app/Notification/ActivateYourAccount.php new file mode 100644 index 000000000..7ce86f62c --- /dev/null +++ b/app/Notification/ActivateYourAccount.php @@ -0,0 +1,69 @@ + + * @author Ryan Thompson + */ +class ActivateYourAccount extends Notification implements ShouldQueue +{ + + use Queueable; + + /** + * Redirect here after activating. + * + * @var string + */ + public $redirect; + + /** + * Create a new UserHasRegistered instance. + * + * @param $redirect + */ + public function __construct($redirect = '/') + { + $this->redirect = $redirect; + } + + /** + * Get the notification's delivery channels. + * + * @param UserInterface $notifiable + * @return array + */ + public function via(UserInterface $notifiable) + { + return ['mail']; + } + + /** + * Return the mail message. + * + * @param UserInterface $notifiable + * @return MailMessage + */ + public function toMail(UserInterface $notifiable) + { + $data = $notifiable->attributesToArray(); + + return (new MailMessage()) + ->view('anomaly.module.users::notifications.activate_your_account') + ->subject(trans('anomaly.module.users::notification.activate_your_account.subject', $data)) + ->greeting(trans('anomaly.module.users::notification.activate_your_account.greeting', $data)) + ->line(trans('anomaly.module.users::notification.activate_your_account.instructions', $data)) + ->action( + trans('anomaly.module.users::notification.activate_your_account.button', $data), + $notifiable->route('activate', ['redirect' => $this->redirect]) + ); + } +} diff --git a/app/Notification/PasswordInvalidated.php b/app/Notification/PasswordInvalidated.php new file mode 100644 index 000000000..40eaeaec0 --- /dev/null +++ b/app/Notification/PasswordInvalidated.php @@ -0,0 +1,72 @@ + + * @author Ryan Thompson + */ +class PasswordInvalidated extends Notification implements ShouldQueue +{ + + use Queueable; + + /** + * Redirect here after activating. + * + * @var string + */ + public $redirect; + + /** + * Create a new UserHasRegistered instance. + * + * @param $redirect + */ + public function __construct($redirect = '/') + { + $this->redirect = $redirect; + } + + /** + * Get the notification's delivery channels. + * + * @param UserInterface $notifiable + * @return array + */ + public function via(UserInterface $notifiable) + { + return ['mail']; + } + + /** + * Return the mail message. + * + * @param UserInterface $notifiable + * @return MailMessage + */ + public function toMail(UserInterface $notifiable) + { + $data = $notifiable->attributesToArray(); + + return (new MailMessage()) + ->error() + ->view('anomaly.module.users::notifications.password_invalidated') + ->subject(trans('anomaly.module.users::notification.password_invalidated.subject', $data)) + ->greeting(trans('anomaly.module.users::notification.password_invalidated.greeting', $data)) + ->line(trans('anomaly.module.users::notification.password_invalidated.notice', $data)) + ->line(trans('anomaly.module.users::notification.password_invalidated.warning', $data)) + ->line(trans('anomaly.module.users::notification.password_invalidated.instructions', $data)) + ->action( + trans('anomaly.module.users::notification.password_invalidated.button', $data), + $notifiable->route('reset', ['redirect' => $this->redirect]) + ); + } +} diff --git a/app/Notification/ResetYourPassword.php b/app/Notification/ResetYourPassword.php new file mode 100644 index 000000000..6ba3afa10 --- /dev/null +++ b/app/Notification/ResetYourPassword.php @@ -0,0 +1,72 @@ + + * @author Ryan Thompson + */ +class ResetYourPassword extends Notification implements ShouldQueue +{ + + use Queueable; + + /** + * Redirect here after activating. + * + * @var string + */ + public $redirect; + + /** + * Create a new UserHasRegistered instance. + * + * @param $redirect + */ + public function __construct($redirect = '/') + { + $this->redirect = $redirect; + } + + /** + * Get the notification's delivery channels. + * + * @param UserInterface $notifiable + * @return array + */ + public function via(UserInterface $notifiable) + { + return ['mail']; + } + + /** + * Return the mail message. + * + * @param UserInterface $notifiable + * @return MailMessage + */ + public function toMail(UserInterface $notifiable) + { + $data = $notifiable->attributesToArray(); + + return (new MailMessage()) + ->error() + ->view('anomaly.module.users::notifications.reset_your_password') + ->subject(trans('anomaly.module.users::notification.reset_your_password.subject', $data)) + ->greeting(trans('anomaly.module.users::notification.reset_your_password.greeting', $data)) + ->line(trans('anomaly.module.users::notification.reset_your_password.notice', $data)) + ->line(trans('anomaly.module.users::notification.reset_your_password.warning', $data)) + ->line(trans('anomaly.module.users::notification.reset_your_password.instructions', $data)) + ->action( + trans('anomaly.module.users::notification.reset_your_password.button', $data), + $notifiable->route('reset', ['redirect' => $this->redirect]) + ); + } +} diff --git a/app/Notification/UserHasBeenActivated.php b/app/Notification/UserHasBeenActivated.php new file mode 100644 index 000000000..2db7a87b9 --- /dev/null +++ b/app/Notification/UserHasBeenActivated.php @@ -0,0 +1,52 @@ + + * @author Ryan Thompson + */ +class UserHasBeenActivated extends Notification implements ShouldQueue +{ + + use Queueable; + + /** + * Get the notification's delivery channels. + * + * @param UserInterface $notifiable + * @return array + */ + public function via(UserInterface $notifiable) + { + return ['mail']; + } + + /** + * Return the mail message. + * + * @param UserInterface $notifiable + * @return MailMessage + */ + public function toMail(UserInterface $notifiable) + { + $data = $notifiable->attributesToArray(); + + return (new MailMessage()) + ->view('anomaly.module.users::notifications.user_has_been_activated') + ->subject(trans('anomaly.module.users::notification.user_has_been_activated.subject', $data)) + ->greeting(trans('anomaly.module.users::notification.user_has_been_activated.greeting', $data)) + ->line(trans('anomaly.module.users::notification.user_has_been_activated.instructions', $data)) + ->action( + trans('anomaly.module.users::notification.user_has_been_activated.button', $data), + route('anomaly.module.users::login') + ); + } +} diff --git a/app/Notification/UserHasRegistered.php b/app/Notification/UserHasRegistered.php new file mode 100644 index 000000000..a070044d2 --- /dev/null +++ b/app/Notification/UserHasRegistered.php @@ -0,0 +1,110 @@ + + * @author Ryan Thompson + */ +class UserHasRegistered extends Notification implements ShouldQueue +{ + + use Queueable; + + /** + * The user who registered. + * + * @var UserInterface + */ + public $user; + + /** + * Create a new UserHasRegistered instance. + * + * @param UserInterface $user + */ + public function __construct(UserInterface $user) + { + $this->user = $user; + } + + /** + * Get the notification's delivery channels. + * + * @return array + */ + public function via() + { + return ['mail', 'slack']; + } + + /** + * Return the mail message. + * + * @param AnonymousNotifiable $notifiable + * @return MailMessage + */ + public function toMail(AnonymousNotifiable $notifiable) + { + $data = $this->user->attributesToArray(); + + return (new MailMessage()) + ->view('anomaly.module.users::notifications.user_has_registered') + ->subject(trans('anomaly.module.users::notification.user_has_registered.subject', $data)) + ->line(trans('anomaly.module.users::notification.user_has_registered.instructions', $data)) + ->action( + trans('anomaly.module.users::notification.user_has_registered.button', $data), + $this->user->route('view') + ); + } + + /** + * Return the slack message. + * + * @param UserInterface $notifiable + * + * @return SlackMessage + */ + public function toSlack(UserInterface $notifiable) + { + return (new SlackMessage()) + ->success() + ->content('Hmm.. What\'s Ryan up to?') + ->attachment( + function ($attachment) { + $attachment + ->title('Testing out teh goodies!', 'http://pyrocms.com/') + ->fields( + [ + 'Username' => $this->user->getUsername(), + 'Eamil' => $this->user->getEmail(), + ] + ); + } + ); + } + + /** + * Return the array storage data. + * + * @param Notifiable $notifiable + * + * @return array + */ + public function toDatabase(UserInterface $notifiable) + { + return [ + 'user' => $this->user, + ]; + } +} diff --git a/app/Notification/UserPendingActivation.php b/app/Notification/UserPendingActivation.php new file mode 100644 index 000000000..324e812b1 --- /dev/null +++ b/app/Notification/UserPendingActivation.php @@ -0,0 +1,68 @@ + + * @author Ryan Thompson + */ +class UserPendingActivation extends Notification implements ShouldQueue +{ + + use Queueable; + + /** + * The user pending activation. + * + * @var UserInterface + */ + public $user; + + /** + * Create a new UserPendingActivation instance. + * + * @param UserInterface $user + */ + public function __construct(UserInterface $user) + { + $this->user = $user; + } + + /** + * Get the notification's delivery channels. + * + * @return array + */ + public function via() + { + return ['mail']; + } + + /** + * Return the mail message. + * + * @param AnonymousNotifiable $notifiable + * @return MailMessage + */ + public function toMail(AnonymousNotifiable $notifiable) + { + $data = $this->user->attributesToArray(); + + return (new MailMessage()) + ->view('anomaly.module.users::notifications.user_pending_activation') + ->subject(trans('anomaly.module.users::notification.user_pending_activation.subject', $data)) + ->line(trans('anomaly.module.users::notification.user_pending_activation.instructions', $data)) + ->action( + trans('anomaly.module.users::notification.user_pending_activation.button', $data), + url('admin/users?view=pending') + ); + } +} diff --git a/config/app.php b/config/app.php index 027fc29a0..92ea8017d 100644 --- a/config/app.php +++ b/config/app.php @@ -260,6 +260,21 @@ return [ 'URL' => Illuminate\Support\Facades\URL::class, 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, - 'Sentry' => Sentry\Laravel\Facade::class + 'Sentry' => Sentry\Laravel\Facade::class, + + + /** + * Todo + * 30.11.2022 + * It has been added for the use of 'with' in the PyroCMS Users Model file. + * Translate(trans) function does not accept nested arrays. + */ + 'Anomaly\UsersModule\User\Notification\ActivateYourAccount' => \App\Notification\ActivateYourAccount::class, + 'Anomaly\UsersModule\User\Notification\PasswordInvalidated' => \App\Notification\PasswordInvalidated::class, + 'Anomaly\UsersModule\User\Notification\ResetYourPassword' => \App\Notification\ResetYourPassword::class, + 'Anomaly\UsersModule\User\Notification\UserHasBeenActivated' => \App\Notification\UserHasBeenActivated::class, + 'Anomaly\UsersModule\User\Notification\UserHasRegistered' => \App\Notification\UserHasRegistered::class, + 'Anomaly\UsersModule\User\Notification\UserPendingActivation' => \App\Notification\UserPendingActivation::class, + ], ];