2020-09-23 03:45:07 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. 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;
|
|
|
|
|
2023-04-26 03:21:20 +02:00
|
|
|
use Auth;
|
|
|
|
use App\Models\RecurringInvoice;
|
2020-09-23 03:45:07 +02:00
|
|
|
use App\Http\Controllers\Controller;
|
2023-04-26 03:21:20 +02:00
|
|
|
use Illuminate\Support\Facades\Redirect;
|
2022-02-21 10:31:02 +01:00
|
|
|
use App\Http\ViewComposers\PortalComposer;
|
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
|
2023-04-26 03:21:20 +02:00
|
|
|
* @return Redirect
|
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') {
|
2021-07-29 12:30:02 +02:00
|
|
|
$recurring_invoice = RecurringInvoice::where('client_id', auth()->guard('contact')->client->id)
|
|
|
|
->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
|
|
|
}
|
2023-02-20 07:23:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generic error page for client portal.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
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';
|
2022-06-21 11:57:17 +02:00
|
|
|
} elseif (auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_RECURRING_INVOICES) {
|
2022-02-21 10:31:02 +01:00
|
|
|
return '/client/recurring_invoices';
|
2022-06-21 11:57:17 +02:00
|
|
|
} elseif (auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_QUOTES) {
|
2022-02-21 10:31:02 +01:00
|
|
|
return '/client/quotes';
|
2022-06-21 11:57:17 +02:00
|
|
|
} elseif (auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_CREDITS) {
|
2022-02-21 10:31:02 +01:00
|
|
|
return '/client/credits';
|
2022-06-21 11:57:17 +02:00
|
|
|
} elseif (auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_TASKS) {
|
2022-02-21 10:31:02 +01:00
|
|
|
return '/client/tasks';
|
2022-06-21 11:57:17 +02:00
|
|
|
} elseif (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
|
|
|
}
|