mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Improvements for unsubscribe links
This commit is contained in:
parent
4328413a15
commit
f6402f87a5
@ -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);
|
||||
}
|
||||
|
||||
$clientContact->is_locked = $request->has('recieve_emails') ? false : true;
|
||||
$clientContact->save();
|
||||
$class = "\\App\\Models\\" . ucfirst(Str::camel($entity)) . 'Invitation';
|
||||
$invitation = $class::withTrashed()->where('key', $invitation_key)->firstOrFail();
|
||||
|
||||
if ($clientContact->is_locked) {
|
||||
$invitation->contact->is_locked = $request->has('receive_emails') ? false : true;
|
||||
$invitation->contact->push();
|
||||
|
||||
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'));
|
||||
|
@ -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) {
|
||||
|
@ -97,6 +97,11 @@ class CreditInvitation extends BaseModel
|
||||
return self::class;
|
||||
}
|
||||
|
||||
public function getEntityString(): string
|
||||
{
|
||||
return 'credit';
|
||||
}
|
||||
|
||||
public function entityType()
|
||||
{
|
||||
return Credit::class;
|
||||
|
@ -97,6 +97,11 @@ class InvoiceInvitation extends BaseModel
|
||||
return self::class;
|
||||
}
|
||||
|
||||
public function getEntityString(): string
|
||||
{
|
||||
return 'invoice';
|
||||
}
|
||||
|
||||
public function entityType()
|
||||
{
|
||||
return Invoice::class;
|
||||
|
@ -97,6 +97,11 @@ class PurchaseOrderInvitation extends BaseModel
|
||||
return self::class;
|
||||
}
|
||||
|
||||
public function getEntityString(): string
|
||||
{
|
||||
return 'purchase_order';
|
||||
}
|
||||
|
||||
public function entityType()
|
||||
{
|
||||
return PurchaseOrder::class;
|
||||
|
@ -78,6 +78,11 @@ class QuoteInvitation extends BaseModel
|
||||
return self::class;
|
||||
}
|
||||
|
||||
public function getEntityString(): string
|
||||
{
|
||||
return 'quote';
|
||||
}
|
||||
|
||||
public function entityType()
|
||||
{
|
||||
return Quote::class;
|
||||
|
@ -91,6 +91,12 @@ class RecurringInvoiceInvitation extends BaseModel
|
||||
return self::class;
|
||||
}
|
||||
|
||||
|
||||
public function getEntityString(): string
|
||||
{
|
||||
return 'recurring_invoice';
|
||||
}
|
||||
|
||||
public function entityType()
|
||||
{
|
||||
return RecurringInvoice::class;
|
||||
|
@ -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;
|
||||
|
@ -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;">
|
||||
<a href="{{ $email_preferences }}">
|
||||
<p style="text-align: center; color: #ffffff; font-size: 10px; font-family: Verdana, Geneva, Tahoma, sans-serif;">
|
||||
{{ ctrans('texts.email_preferences') }}
|
||||
{{ ctrans('texts.unsubscribe') }}
|
||||
</p>
|
||||
</a>
|
||||
</div>
|
||||
|
@ -4,9 +4,9 @@ ctrans('texts.preferences')) @section('body')
|
||||
<div class="m-auto md:w-1/3 lg:w-1/5">
|
||||
<div class="flex flex-col items-center">
|
||||
<img
|
||||
src="{{ $logo }}"
|
||||
src="{{ $company->present()->logo() }}"
|
||||
class="border-gray-100 h-18 pb-4"
|
||||
alt="Invoice Ninja logo"
|
||||
alt="{{ $company->present()->name() }}"
|
||||
/>
|
||||
<h1 class="text-center text-2xl mt-10">
|
||||
{{ ctrans('texts.email_settings') }}
|
||||
@ -15,13 +15,13 @@ ctrans('texts.preferences')) @section('body')
|
||||
<form class="my-4" method="post">
|
||||
@csrf @method('put')
|
||||
|
||||
<label for="recieve_emails">
|
||||
<input type="checkbox" name="recieve_emails"
|
||||
id="recieve_emails"
|
||||
{{ $recieve_emails ? 'checked' : '' }} />
|
||||
<label for="receive_emails">
|
||||
<input type="checkbox" name="receive_emails"
|
||||
id="receive_emails"
|
||||
{{ $receive_emails ? 'checked' : '' }} />
|
||||
|
||||
<span>
|
||||
{{ ctrans('texts.recieve_emails') }}
|
||||
{{ ctrans('texts.resubscribe') }}
|
||||
</span>
|
||||
</label>
|
||||
|
||||
|
@ -133,6 +133,9 @@ Route::group(['middleware' => ['invite_db'], 'prefix' => 'client', 'as' => 'clie
|
||||
Route::get('{entity}/{invitation_key}/download', [App\Http\Controllers\ClientPortal\InvitationController::class, 'routerForDownload'])->middleware('token_auth');
|
||||
Route::get('pay/{invitation_key}', [App\Http\Controllers\ClientPortal\InvitationController::class, 'payInvoice'])->name('pay.invoice');
|
||||
|
||||
Route::get('email_preferences/{entity}/{invitation_key}', [EmailPreferencesController::class, 'index'])->name('email_preferences')->middleware('signed');
|
||||
Route::put('email_preferences/{entity}/{invitation_key}', [EmailPreferencesController::class, 'update']);
|
||||
|
||||
Route::get('unsubscribe/{entity}/{invitation_key}', [App\Http\Controllers\ClientPortal\InvitationController::class, 'unsubscribe'])->name('unsubscribe');
|
||||
});
|
||||
|
||||
@ -162,5 +165,3 @@ Route::fallback(function () {
|
||||
})->middleware('throttle:404');
|
||||
|
||||
// Fix me: Move into invite_db middleware group.
|
||||
Route::get('client/email_preferences/{clientContact}/{invitation_key}', [EmailPreferencesController::class, 'index'])->name('client.email_preferences');
|
||||
Route::put('client/email_preferences/{clientContact}/{invitation_key}', [EmailPreferencesController::class, 'update']);
|
||||
|
Loading…
Reference in New Issue
Block a user