1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Http/Controllers/ClientPortal/NinjaPlanController.php

62 lines
2.0 KiB
PHP
Raw Normal View History

2021-09-01 06:02:57 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Controllers\ClientPortal;
use App\Http\Controllers\Controller;
use App\Http\Requests\ClientPortal\Uploads\StoreUploadRequest;
use App\Libraries\MultiDB;
2021-10-03 04:36:43 +02:00
use App\Models\Account;
2021-09-01 06:02:57 +02:00
use App\Models\ClientContact;
2021-09-01 07:03:01 +02:00
use App\Models\Company;
2021-09-01 06:02:57 +02:00
use App\Utils\Ninja;
use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
2021-09-09 08:59:23 +02:00
use Illuminate\Support\Facades\Auth;
2021-09-01 06:02:57 +02:00
class NinjaPlanController extends Controller
{
2021-10-03 04:36:43 +02:00
public function index(string $contact_key, string $account_or_company_key)
2021-09-01 06:02:57 +02:00
{
2021-10-03 04:36:43 +02:00
MultiDB::findAndSetDbByCompanyKey($account_or_company_key);
$company = Company::where('company_key', $account_or_company_key)->first();
if(!$company){
MultiDB::findAndSetDbByAccountKey($account_or_company_key);
$account = Account::where('key', $account_or_company_key)->first();
}
else
$account = $company->account;
2021-09-03 15:24:18 +02:00
2021-09-11 08:26:00 +02:00
if (MultiDB::findAndSetDbByContactKey($contact_key) && $client_contact = ClientContact::where('contact_key', $contact_key)->first())
2021-09-01 07:03:01 +02:00
{
2021-09-03 15:24:18 +02:00
nlog("Ninja Plan Controller - Found and set Client Contact");
2021-09-01 07:03:01 +02:00
Auth::guard('contact')->login($client_contact,true);
2021-09-01 06:02:57 +02:00
/* Current paid users get pushed straight to subscription overview page*/
2021-09-01 06:36:22 +02:00
if($account->isPaidHostedClient())
2021-09-01 06:02:57 +02:00
return redirect('/client/subscriptions');
/* Users that are not paid get pushed to a custom purchase page */
return $this->render('subscriptions.ninja_plan', ['settings' => $client_contact->company->settings]);
}
return redirect()->route('client.catchall');
}
}