Refactor password reset - clientcontact

This commit is contained in:
David Bomba 2021-02-15 09:54:27 +11:00
parent 5ad5606ea2
commit 08e280e651
4 changed files with 70 additions and 15 deletions

View File

@ -0,0 +1,54 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Mail\ClientContact;
class ClientContactResetPasswordObject
{
public $client_contact;
public $token;
private $company;
/**
*
*/
public function __construct($token, $client_contact)
{
$this->token = $token;
$this->client_contact = $client_contact;
$this->company = $client_contact->company;
}
public function build()
{
$data = [
'title' => ctrans('texts.your_password_reset_link'),
'message' => ctrans('texts.reset_password'),
'url' => route('client.password.reset', ['token' => $this->token, 'email' => $this->client_contact->email]),
'button' => ctrans('texts.reset'),
'signature' => $this->company->settings->email_signature,
'settings' => $this->company->settings,
'logo' => $this->company->present()->logo(),
];
$mail_obj = new \stdClass;
$mail_obj->subject = ctrans('texts.your_password_reset_link');
$mail_obj->data = $data;
$mail_obj->markdown = 'email.admin.generic';
$mail_obj->tag = $this->company->company_key;
return $mail_obj;
}
}

View File

@ -11,6 +11,10 @@
namespace App\Models;
use App\Jobs\Mail\NinjaMailer;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Mail\ClientContact\ClientContactResetPasswordObject;
use App\Models\Presenters\ClientContactPresenter;
use App\Notifications\ClientContactResetPassword;
use App\Utils\Traits\MakesHash;
@ -151,7 +155,15 @@ class ClientContact extends Authenticatable implements HasLocalePreference
public function sendPasswordResetNotification($token)
{
$this->notify(new ClientContactResetPassword($token));
$nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer((new ClientContactResetPasswordObject($token, $this))->build());
$nmo->to_user = $this;
$nmo->company = $this->company;
$nmo->settings = $this->company->settings;
NinjaMailerJob::dispatch($nmo);
//$this->notify(new ClientContactResetPassword($token));
}
public function preferredLocale()

View File

@ -22,6 +22,7 @@ use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;
//@deprecated for mail
class ClientContactRequestCancellation extends Notification
{
// use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
@ -67,19 +68,6 @@ class ClientContactRequestCancellation extends Notification
*/
public function toMail($notifiable)
{
if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable, $this->client_contact);
}
$client_contact_name = $this->client_contact->present()->name();
$client_name = $this->client_contact->client->present()->name();
$recurring_invoice_number = $this->recurring_invoice->number;
return (new MailMessage)
->subject('Request for recurring invoice cancellation from '.$client_contact_name)
->markdown('email.support.cancellation', [
'message' => "Contact [{$client_contact_name}] from Client [{$client_name}] requested to cancel Recurring Invoice [#{$recurring_invoice_number}]",
]);
}
/**

View File

@ -19,6 +19,7 @@ use Illuminate\Notifications\Notification;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
//@deprecated
class ClientContactResetPassword extends Notification
{
// use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
@ -55,7 +56,7 @@ class ClientContactResetPassword extends Notification
*/
public function via($notifiable)
{
return ['mail'];
return [];
}
/**