1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Http/Controllers/ClientPortal/ContactHashLoginController.php

82 lines
3.1 KiB
PHP
Raw Normal View History

<?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)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Controllers\ClientPortal;
use App\Http\Controllers\Controller;
use App\Http\ViewComposers\PortalComposer;
2023-10-26 04:57:44 +02:00
use App\Models\RecurringInvoice;
use Illuminate\Support\Facades\Redirect;
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
*/
public function login(string $contact_key)
{
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
}
return redirect($this->setRedirectPath());
}
2021-03-31 02:07:54 +02:00
public function magicLink(string $magic_link)
{
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-27 21:45:42 +01:00
private function setRedirectPath()
{
if (auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_INVOICES) {
return '/client/invoices';
2024-06-16 06:35:56 +02:00
} elseif ((bool)(auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_RECURRING_INVOICES)) {
return '/client/recurring_invoices';
2024-06-16 06:35:56 +02:00
} elseif ((bool)(auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_QUOTES)) {
return '/client/quotes';
2024-06-16 06:35:56 +02:00
} elseif ((bool)(auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_CREDITS)) {
return '/client/credits';
2024-06-16 06:35:56 +02:00
} elseif ((bool)(auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_TASKS)) {
return '/client/tasks';
2024-06-16 06:35:56 +02:00
} elseif ((bool)(auth()->guard('contact')->user()->company->enabled_modules & PortalComposer::MODULE_EXPENSES)) {
return '/client/expenses';
}
}
}