2019-09-23 07:59:01 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @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-03-05 08:14:57 +01:00
|
|
|
use App\Events\Misc\InvitationWasViewed;
|
2019-09-23 07:59:01 +02:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Models\InvoiceInvitation;
|
|
|
|
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;
|
|
|
|
|
2019-11-16 04:12:29 +01:00
|
|
|
public function router(string $entity, string $invitation_key)
|
2019-09-23 07:59:01 +02:00
|
|
|
{
|
2019-11-16 04:12:29 +01:00
|
|
|
$key = $entity.'_id';
|
2020-03-06 14:41:15 +01:00
|
|
|
|
2019-11-21 09:38:57 +01:00
|
|
|
$entity_obj = 'App\Models\\'.ucfirst($entity).'Invitation';
|
2019-09-23 07:59:01 +02:00
|
|
|
|
2019-11-16 04:12:29 +01:00
|
|
|
$invitation = $entity_obj::whereRaw("BINARY `key`= ?", [$invitation_key])->first();
|
2019-09-23 07:59:01 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
if ($invitation) {
|
2020-03-06 14:41:15 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
if ((bool)$invitation->contact->client->getSetting('enable_client_portal_password') !== false) {
|
2019-11-04 01:22:59 +01:00
|
|
|
$this->middleware('auth:contact');
|
2019-12-30 22:59:12 +01:00
|
|
|
} else {
|
2019-11-21 09:38:57 +01:00
|
|
|
auth()->guard('contact')->login($invitation->contact, false);
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2020-03-04 12:09:43 +01:00
|
|
|
|
2020-03-10 23:20:09 +01:00
|
|
|
if(!request()->has('silent')){
|
2020-03-04 12:09:43 +01:00
|
|
|
|
|
|
|
$invitation->markViewed();
|
|
|
|
|
|
|
|
event(new InvitationWasViewed($entity, $invitation));
|
|
|
|
|
|
|
|
}
|
2019-11-04 01:22:59 +01:00
|
|
|
|
2019-11-16 04:12:29 +01:00
|
|
|
return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]);
|
2020-03-06 14:41:15 +01:00
|
|
|
|
|
|
|
} else
|
2019-12-30 22:59:12 +01:00
|
|
|
abort(404);
|
2020-03-06 14:41:15 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function routerForDownload(string $entity, string $invitation_key)
|
|
|
|
{
|
2020-03-11 12:05:05 +01:00
|
|
|
return redirect('client/'.$entity.'/'.$invitation_key.'/download_pdf');
|
2019-09-23 07:59:01 +02:00
|
|
|
}
|
2019-11-06 23:57:09 +01:00
|
|
|
|
2019-11-16 04:12:29 +01:00
|
|
|
public function routerForIframe(string $entity, string $client_hash, string $invitation_key)
|
|
|
|
{
|
|
|
|
}
|
2019-09-23 07:59:01 +02:00
|
|
|
}
|