2020-09-23 03:45:07 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2022-04-27 05:20:41 +02:00
|
|
|
* @copyright Copyright (c) 2022. 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;
|
2021-07-29 12:30:45 +02:00
|
|
|
use App\Models\RecurringInvoice;
|
2020-09-23 03:45:07 +02:00
|
|
|
use Auth;
|
|
|
|
|
|
|
|
class ContactHashLoginController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Logs a user into the client portal using their contact_key
|
|
|
|
* @param string $contact_key The contact key
|
|
|
|
* @return Auth|Redirect
|
|
|
|
*/
|
|
|
|
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
|
|
|
}
|
2021-05-11 03:55:47 +02:00
|
|
|
|
|
|
|
public function errorPage()
|
|
|
|
{
|
|
|
|
return render('generic.error', ['title' => session()->get('title'), 'notification' => session()->get('notification')]);
|
|
|
|
}
|
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
|
|
|
}
|