2020-09-23 03:45:07 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-23 03:45:07 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-09-23 03:45:07 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\ClientPortal;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2022-02-21 10:31:02 +01:00
|
|
|
use App\Http\ViewComposers\PortalComposer;
|
2023-10-26 04:57:44 +02:00
|
|
|
use App\Models\RecurringInvoice;
|
|
|
|
use Illuminate\Support\Facades\Redirect;
|
2020-09-23 03:45:07 +02:00
|
|
|
|
|
|
|
class ContactHashLoginController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Logs a user into the client portal using their contact_key
|
|
|
|
* @param string $contact_key The contact key
|
2024-06-16 00:30:25 +02:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2020-09-23 03:45:07 +02:00
|
|
|
*/
|
|
|
|
public function login(string $contact_key)
|
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
if (request()->has('subscription') && request()->subscription == 'true') {
|
2023-08-04 08:40:44 +02:00
|
|
|
|
|
|
|
/** @var \App\Models\ClientContact $client_contact **/
|
|
|
|
$client_contact = auth()->guard('contact');
|
|
|
|
|
|
|
|
/** @var \App\Models\RecurringInvoice $recurring_invoice **/
|
|
|
|
$recurring_invoice = RecurringInvoice::where('client_id', $client_contact->client->id)
|
2021-07-29 12:30:02 +02:00
|
|
|
->whereNotNull('subscription_id')
|
|
|
|
->whereNull('deleted_at')
|
|
|
|
->first();
|
|
|
|
|
2021-07-29 12:31:20 +02:00
|
|
|
return redirect()->route('client.recurring_invoice.show', $recurring_invoice->hashed_id);
|
2021-07-29 12:30:02 +02:00
|
|
|
}
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
return redirect($this->setRedirectPath());
|
2020-09-23 03:45:07 +02:00
|
|
|
}
|
2021-03-31 02:07:54 +02:00
|
|
|
|
|
|
|
public function magicLink(string $magic_link)
|
|
|
|
{
|
2022-02-21 10:31:02 +01:00
|
|
|
return redirect($this->setRedirectPath());
|
2021-03-31 02:07:54 +02:00
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-02-20 07:23:39 +01:00
|
|
|
/**
|
|
|
|
* Generic error page for client portal.
|
|
|
|
*
|
2024-06-16 00:30:25 +02:00
|
|
|
* @return \Illuminate\View\View
|
2023-02-20 07:23:39 +01:00
|
|
|
*/
|
2021-05-11 03:55:47 +02:00
|
|
|
public function errorPage()
|
|
|
|
{
|
2023-02-20 07:23:39 +01:00
|
|
|
return render('generic.error', [
|
2023-02-22 07:37:16 +01:00
|
|
|
'title' => session()->get('title'),
|
|
|
|
'notification' => session()->get('notification'),
|
|
|
|
'account' => auth()->guard('contact')?->user()?->user?->account,
|
2023-02-20 07:23:39 +01:00
|
|
|
'company' => auth()->guard('contact')?->user()?->user?->company
|
|
|
|
]);
|
2021-05-11 03:55:47 +02:00
|
|
|
}
|
2022-02-21 10:31:02 +01:00
|
|
|
|
2022-02-27 21:45:42 +01:00
|
|
|
private function setRedirectPath()
|
2022-02-21 10:31:02 +01:00
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
if (auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_INVOICES) {
|
2022-02-21 10:31:02 +01:00
|
|
|
return '/client/invoices';
|
2024-06-16 06:35:56 +02:00
|
|
|
} elseif ((bool)(auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_RECURRING_INVOICES)) {
|
2022-02-21 10:31:02 +01:00
|
|
|
return '/client/recurring_invoices';
|
2024-06-16 06:35:56 +02:00
|
|
|
} elseif ((bool)(auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_QUOTES)) {
|
2022-02-21 10:31:02 +01:00
|
|
|
return '/client/quotes';
|
2024-06-16 06:35:56 +02:00
|
|
|
} elseif ((bool)(auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_CREDITS)) {
|
2022-02-21 10:31:02 +01:00
|
|
|
return '/client/credits';
|
2024-06-16 06:35:56 +02:00
|
|
|
} elseif ((bool)(auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_TASKS)) {
|
2022-02-21 10:31:02 +01:00
|
|
|
return '/client/tasks';
|
2024-06-16 06:35:56 +02:00
|
|
|
} elseif ((bool)(auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_EXPENSES)) {
|
2022-02-21 10:31:02 +01:00
|
|
|
return '/client/expenses';
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2022-02-21 10:31:02 +01:00
|
|
|
}
|
2020-09-23 03:45:07 +02:00
|
|
|
}
|