diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index c479b1c58ba3..b553e825616c 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -370,11 +370,13 @@ class UserController extends BaseController */ public function update(UpdateUserRequest $request, User $user) { - event(new UserEmailAddressChangedOldEmail($user->email, auth()->user()->company(), Ninja::eventVars())); + $old_email = $user->email; + $new_email = $request->input('email'); $user = $this->user_repo->save($request->all(), $user); - event(new UserEmailAddressChangedNewEmail($user->email, auth()->user()->company(), Ninja::eventVars())); + if($user) + UserEmailChanged::dispatch($new_email, $old_email, auth()->user()->company()); return $this->itemResponse($user); } diff --git a/app/Jobs/User/UserEmailChanged.php b/app/Jobs/User/UserEmailChanged.php new file mode 100644 index 000000000000..49ca7c17efca --- /dev/null +++ b/app/Jobs/User/UserEmailChanged.php @@ -0,0 +1,107 @@ +new_email = $new_email; + $this->old_email = $old_email; + $this->company = $company; + } + + public function handle() + { + //Set DB + MultiDB::setDb($this->company->db); + + //if we need to set an email driver do it now + $this->setMailDriver($this->company->settings->email_sending_method); + + $mail_obj = new \stdClass; + $mail_obj->subject = ctrans('texts.email_address_changed'); + $mail_obj->markdown = 'email.admin.generic'; + $mail_obj->from = [$this->company->owner()->email, $this->company->owner()->present()->name()]; + $mail_obj->tag = $this->company->company_key; + $mail_obj->data = $this->getData(); + + //send email + Mail::to($this->old_email) + ->send(new UserNotificationMailer($mail_obj)); + + Mail::to($this->new_email) + ->send(new UserNotificationMailer($mail_obj)); + + + //catch errors + if (count(Mail::failures()) > 0) { + $this->logMailError(Mail::failures()); + } + + } + + private function getData() + { + $data = [ + 'title' => ctrans('texts.email_address_changed'), + 'message' => ctrans( + 'texts.email_address_changed_message', + ['old_email' => $this->old_email, + 'new_email' => $this->new_email, + ] + ), + 'url' => config('ninja.app_url'), + 'button' => ctrans('texts.account_login'), + 'signature' => $this->company->owner()->signature, + 'logo' => $this->company->present()->logo(), + ]; + } + + private function logMailError($errors) + { + SystemLogger::dispatch( + $errors, + SystemLog::CATEGORY_MAIL, + SystemLog::EVENT_MAIL_SEND, + SystemLog::TYPE_FAILURE, + $this->company + ); + } + +} diff --git a/app/Jobs/User/UserEmailChangedNew.php b/app/Jobs/User/UserEmailChangedNew.php deleted file mode 100644 index dabf71e83604..000000000000 --- a/app/Jobs/User/UserEmailChangedNew.php +++ /dev/null @@ -1,51 +0,0 @@ -email = $email; - $this->company = $company; - } - - /** - * Execute the job. - * - * @return void - */ - public function handle() - { - - } -} diff --git a/app/Jobs/User/UserEmailChangedOld.php b/app/Jobs/User/UserEmailChangedOld.php deleted file mode 100644 index 098f34e266e1..000000000000 --- a/app/Jobs/User/UserEmailChangedOld.php +++ /dev/null @@ -1,51 +0,0 @@ -email = $email; - $this->company = $company; - } - - /** - * Execute the job. - * - * @return void - */ - public function handle() - { - - } -} diff --git a/app/Mail/User/UserNotificationMailer.php b/app/Mail/User/UserNotificationMailer.php new file mode 100644 index 000000000000..755067bf84cd --- /dev/null +++ b/app/Mail/User/UserNotificationMailer.php @@ -0,0 +1,46 @@ +mail_obj = $mail_obj; + } + + /** + * Build the message. + * + * @return $this + */ + public function build() + { + return $this->from($this->mail_obj->from[0], $this->mail_obj->from[1]) //todo + ->subject($this->mail_obj->subject) + ->markdown($this->mail_obj->markdown, $this->mail_obj->data) + ->withSwiftMessage(function ($message) { + $message->getHeaders()->addTextHeader('Tag', $this->mail_obj->tag); + }); + } +} diff --git a/app/Services/Recurring/RecurringService.php b/app/Services/Recurring/RecurringService.php new file mode 100644 index 000000000000..353a37ac3b7f --- /dev/null +++ b/app/Services/Recurring/RecurringService.php @@ -0,0 +1,28 @@ +recurring_entity = $recurring_entity; + } + + //set schedules - update next_send_dates +} diff --git a/composer.lock b/composer.lock index 9c525997c685..d001e3a70818 100644 --- a/composer.lock +++ b/composer.lock @@ -5841,16 +5841,16 @@ }, { "name": "spatie/browsershot", - "version": "3.37.1", + "version": "3.37.2", "source": { "type": "git", "url": "https://github.com/spatie/browsershot.git", - "reference": "7d526a458ce870a07669bd2416313a4d62f3f15d" + "reference": "32d2984079ed8fe690f4dc5b7b6c205ae0a7b0fd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/browsershot/zipball/7d526a458ce870a07669bd2416313a4d62f3f15d", - "reference": "7d526a458ce870a07669bd2416313a4d62f3f15d", + "url": "https://api.github.com/repos/spatie/browsershot/zipball/32d2984079ed8fe690f4dc5b7b6c205ae0a7b0fd", + "reference": "32d2984079ed8fe690f4dc5b7b6c205ae0a7b0fd", "shasum": "" }, "require": { @@ -5899,7 +5899,7 @@ "type": "github" } ], - "time": "2020-07-08T07:20:45+00:00" + "time": "2020-07-21T22:40:58+00:00" }, { "name": "spatie/image",