diff --git a/app/Http/Controllers/ClientPortal/EmailPreferencesController.php b/app/Http/Controllers/ClientPortal/EmailPreferencesController.php index e8400553ef..5ed1311b0e 100644 --- a/app/Http/Controllers/ClientPortal/EmailPreferencesController.php +++ b/app/Http/Controllers/ClientPortal/EmailPreferencesController.php @@ -19,38 +19,38 @@ use App\Jobs\Mail\NinjaMailerObject; use App\Mail\Admin\ClientUnsubscribedObject; use App\Models\ClientContact; use Illuminate\Http\Request; +use Illuminate\Support\Str; class EmailPreferencesController extends Controller { - public function index(ClientContact $clientContact, Request $request): \Illuminate\View\View + public function index(string $entity, string $invitation_key, Request $request): \Illuminate\View\View { - if (!$request->hasValidSignature()) { - abort(404); - } + $class = "\\App\\Models\\".ucfirst(Str::camel($entity)).'Invitation'; + $invitation = $class::where('key', $invitation_key)->firstOrFail(); - $data['recieve_emails'] = $clientContact->is_locked ? false : true; - $data['logo'] = $clientContact->company->present()->logo(); + $data['receive_emails'] = $invitation->contact->is_locked ? false : true; + $data['company'] = $invitation->company; return $this->render('generic.email_preferences', $data); } - public function update(ClientContact $clientContact, Request $request): \Illuminate\Http\RedirectResponse + public function update(string $entity, string $invitation_key, Request $request): \Illuminate\Http\RedirectResponse { - if (!$request->hasValidSignature()) { - abort(404); - } + + $class = "\\App\\Models\\" . ucfirst(Str::camel($entity)) . 'Invitation'; + $invitation = $class::withTrashed()->where('key', $invitation_key)->firstOrFail(); - $clientContact->is_locked = $request->has('recieve_emails') ? false : true; - $clientContact->save(); + $invitation->contact->is_locked = $request->has('receive_emails') ? false : true; + $invitation->contact->push(); - if ($clientContact->is_locked) { + if ($invitation->contact->is_locked) { $nmo = new NinjaMailerObject(); - $nmo->mailable = new NinjaMailer((new ClientUnsubscribedObject($clientContact, $clientContact->company))->build()); - $nmo->company = $clientContact->company; - $nmo->to_user = $clientContact->company->owner(); - $nmo->settings = $clientContact->company->settings; + $nmo->mailable = new NinjaMailer((new ClientUnsubscribedObject($invitation->contact, $invitation->contact->company))->build()); + $nmo->company = $invitation->contact->company; + $nmo->to_user = $invitation->contact->company->owner(); + $nmo->settings = $invitation->contact->company->settings; - (new NinjaMailerJob($nmo))->handle(); + NinjaMailerJob::dispatch($nmo); } return back()->with('message', ctrans('texts.updated_settings')); diff --git a/app/Mail/TemplateEmail.php b/app/Mail/TemplateEmail.php index 2abd4d52e7..f9f4b1562a 100644 --- a/app/Mail/TemplateEmail.php +++ b/app/Mail/TemplateEmail.php @@ -139,7 +139,7 @@ class TemplateEmail extends Mailable 'whitelabel' => $this->client->user->account->isPaid() ? true : false, 'logo' => $this->company->present()->logo($settings), 'links' => $this->build_email->getAttachmentLinks(), - 'email_preferences' => URL::signedRoute('client.email_preferences', ['invitation_key' => $this->invitation->key, 'clientContact' => $this->contact->hashed_id]), + 'email_preferences' => URL::signedRoute('client.email_preferences', ['entity' => $this->invitation->getEntityString(), 'invitation_key' => $this->invitation->key]), ]); foreach ($this->build_email->getAttachments() as $file) { diff --git a/app/Models/CreditInvitation.php b/app/Models/CreditInvitation.php index 545585bcc5..8365627028 100644 --- a/app/Models/CreditInvitation.php +++ b/app/Models/CreditInvitation.php @@ -97,6 +97,11 @@ class CreditInvitation extends BaseModel return self::class; } + public function getEntityString(): string + { + return 'credit'; + } + public function entityType() { return Credit::class; diff --git a/app/Models/InvoiceInvitation.php b/app/Models/InvoiceInvitation.php index 2f5c6c08a1..58c191fc4a 100644 --- a/app/Models/InvoiceInvitation.php +++ b/app/Models/InvoiceInvitation.php @@ -97,6 +97,11 @@ class InvoiceInvitation extends BaseModel return self::class; } + public function getEntityString(): string + { + return 'invoice'; + } + public function entityType() { return Invoice::class; diff --git a/app/Models/PurchaseOrderInvitation.php b/app/Models/PurchaseOrderInvitation.php index a1702ea6b9..7584256f72 100644 --- a/app/Models/PurchaseOrderInvitation.php +++ b/app/Models/PurchaseOrderInvitation.php @@ -97,6 +97,11 @@ class PurchaseOrderInvitation extends BaseModel return self::class; } + public function getEntityString(): string + { + return 'purchase_order'; + } + public function entityType() { return PurchaseOrder::class; diff --git a/app/Models/QuoteInvitation.php b/app/Models/QuoteInvitation.php index 65aef2e255..e1c3c72697 100644 --- a/app/Models/QuoteInvitation.php +++ b/app/Models/QuoteInvitation.php @@ -78,6 +78,11 @@ class QuoteInvitation extends BaseModel return self::class; } + public function getEntityString(): string + { + return 'quote'; + } + public function entityType() { return Quote::class; diff --git a/app/Models/RecurringInvoiceInvitation.php b/app/Models/RecurringInvoiceInvitation.php index 34928a155c..a5fe7868db 100644 --- a/app/Models/RecurringInvoiceInvitation.php +++ b/app/Models/RecurringInvoiceInvitation.php @@ -91,6 +91,12 @@ class RecurringInvoiceInvitation extends BaseModel return self::class; } + + public function getEntityString(): string + { + return 'recurring_invoice'; + } + public function entityType() { return RecurringInvoice::class; diff --git a/lang/en/texts.php b/lang/en/texts.php index d8625e588a..4a0f3c5c20 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -5215,6 +5215,7 @@ $lang = array( 'participant_name' => 'Participant name', 'client_unsubscribed' => 'Client changed e-mail preferences', 'client_unsubscribed_help' => 'Client :client changed preferences and unsubscribed from e-mails.', + 'resubscribe' => 'Resubscribe', ); return $lang; diff --git a/resources/views/email/template/client.blade.php b/resources/views/email/template/client.blade.php index 7a4177cdc2..2986b35345 100644 --- a/resources/views/email/template/client.blade.php +++ b/resources/views/email/template/client.blade.php @@ -240,7 +240,7 @@ style="padding-top: 10px;padding-bottom: 10px; background-color: #242424; border: 1px solid #c2c2c2; border-top-color: #242424; border-bottom-color: #242424;">

- {{ ctrans('texts.email_preferences') }} + {{ ctrans('texts.unsubscribe') }}

diff --git a/resources/views/portal/ninja2020/generic/email_preferences.blade.php b/resources/views/portal/ninja2020/generic/email_preferences.blade.php index 2c32ee9db0..492c42e2fc 100644 --- a/resources/views/portal/ninja2020/generic/email_preferences.blade.php +++ b/resources/views/portal/ninja2020/generic/email_preferences.blade.php @@ -4,9 +4,9 @@ ctrans('texts.preferences')) @section('body')
Invoice Ninja logo

{{ ctrans('texts.email_settings') }} @@ -15,13 +15,13 @@ ctrans('texts.preferences')) @section('body')
@csrf @method('put') -