1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00
invoiceninja/app/Http/Controllers/ClientPortal/InvitationController.php

89 lines
2.6 KiB
PHP
Raw Normal View History

2019-09-23 07:59:01 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
2019-09-23 07:59:01 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Controllers\ClientPortal;
2020-07-17 03:18:40 +02:00
use App\Events\Invoice\InvoiceWasViewed;
use App\Events\Misc\InvitationWasViewed;
2019-09-23 07:59:01 +02:00
use App\Http\Controllers\Controller;
use App\Models\InvoiceInvitation;
2020-07-08 14:02:16 +02:00
use App\Utils\Ninja;
2019-09-23 07:59:01 +02:00
use App\Utils\Traits\MakesDates;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
/**
* Class InvitationController
* @package App\Http\Controllers\ClientPortal\InvitationController
*/
class InvitationController extends Controller
{
use MakesHash;
use MakesDates;
public function router(string $entity, string $invitation_key)
2019-09-23 07:59:01 +02:00
{
$key = $entity.'_id';
$entity_obj = 'App\Models\\'.ucfirst($entity).'Invitation';
2019-09-23 07:59:01 +02:00
$invitation = $entity_obj::whereRaw("BINARY `key`= ?", [$invitation_key])->first();
2019-09-23 07:59:01 +02:00
if ($invitation) {
2020-07-17 03:18:40 +02:00
if ((bool)$invitation->contact->client->getSetting('enable_client_portal_password') !== false) {
$this->middleware('auth:contact');
} else {
auth()->guard('contact')->login($invitation->contact, true);
}
if (!request()->has('silent') && !$invitation->viewed_date) {
// if (!request()->has('silent')) {
$invitation->markViewed();
2020-07-14 00:06:28 +02:00
event(new InvitationWasViewed($invitation->{$entity}, $invitation, $invitation->{$entity}->company, Ninja::eventVars()));
2020-07-17 03:18:40 +02:00
2020-07-28 11:49:09 +02:00
$this->fireEntityViewedEvent($invitation, $entity);
}
return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]);
} else {
abort(404);
}
}
2020-07-17 03:18:40 +02:00
private function fireEntityViewedEvent($invitation, $entity_string)
{
switch ($entity_string) {
case 'invoice':
event(new InvoiceWasViewed($invitation, $invitation->company, Ninja::eventVars()));
break;
default:
# code...
break;
}
}
public function routerForDownload(string $entity, string $invitation_key)
{
return redirect('client/'.$entity.'/'.$invitation_key.'/download_pdf');
2019-09-23 07:59:01 +02:00
}
public function routerForIframe(string $entity, string $client_hash, string $invitation_key)
{
}
2019-09-23 07:59:01 +02:00
}