mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Send change of email to both old and new email address
This commit is contained in:
parent
9d276ffa70
commit
a367c64278
@ -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);
|
||||
}
|
||||
|
107
app/Jobs/User/UserEmailChanged.php
Normal file
107
app/Jobs/User/UserEmailChanged.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Jobs\User;
|
||||
|
||||
use App\Jobs\Mail\BaseMailerJob;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\User\UserNotificationMailer;
|
||||
use App\Models\Company;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class UserEmailChanged extends BaseMailerJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $new_email;
|
||||
|
||||
protected $old_email;
|
||||
|
||||
protected $company;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function __construct(string $new_email, string $old_email, Company $company)
|
||||
{
|
||||
$this->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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Jobs\User;
|
||||
|
||||
use App\Jobs\Mail\BaseMailerJob;
|
||||
use App\Models\Company;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class UserEmailChangedNew extends BaseMailerJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $email;
|
||||
|
||||
protected $company;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function __construct(string $email, Company $company)
|
||||
{
|
||||
$this->email = $email;
|
||||
$this->company = $company;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Jobs\User;
|
||||
|
||||
use App\Jobs\Mail\BaseMailerJob;
|
||||
use App\Models\Company;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class UserEmailChangedOld extends BaseMailerJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable;
|
||||
|
||||
protected $email;
|
||||
|
||||
protected $company;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function __construct(string $email, Company $company)
|
||||
{
|
||||
$this->email = $email;
|
||||
$this->company = $company;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
46
app/Mail/User/UserNotificationMailer.php
Normal file
46
app/Mail/User/UserNotificationMailer.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Mail\User;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Mail\Mailable;
|
||||
|
||||
class UserNotificationMailer extends Mailable
|
||||
{
|
||||
|
||||
public $mail_obj;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($mail_obj)
|
||||
{
|
||||
$this->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);
|
||||
});
|
||||
}
|
||||
}
|
28
app/Services/Recurring/RecurringService.php
Normal file
28
app/Services/Recurring/RecurringService.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Services\Recurring;
|
||||
|
||||
use App\Models\RecurringInvoice;
|
||||
|
||||
class RecurringService
|
||||
{
|
||||
|
||||
protected $recurring_entity;
|
||||
|
||||
public function __construct($recurring_entity)
|
||||
{
|
||||
$this->recurring_entity = $recurring_entity;
|
||||
}
|
||||
|
||||
//set schedules - update next_send_dates
|
||||
}
|
10
composer.lock
generated
10
composer.lock
generated
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user