1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 17:01:33 +02:00
invoiceninja/app/Http/Middleware/ContactRegister.php

46 lines
1.2 KiB
PHP
Raw Normal View History

2020-05-28 17:39:38 +02:00
<?php
namespace App\Http\Middleware;
use App\Models\Company;
use Closure;
2020-10-28 11:10:49 +01:00
use Illuminate\Http\Request;
2020-05-28 17:39:38 +02:00
class ContactRegister
{
/**
* Handle an incoming request.
*
2020-10-28 11:10:49 +01:00
* @param Request $request
* @param Closure $next
2020-05-28 17:39:38 +02:00
* @return mixed
*/
public function handle($request, Closure $next)
{
/*
2020-05-28 17:39:38 +02:00
* Notes:
*
2020-05-28 17:39:38 +02:00
* 1. If request supports subdomain (for hosted) check domain and continue request.
* 2. If request doesn't support subdomain and doesn' have company_key, abort
* 3. firstOrFail() will abort with 404 if company with company_key wasn't found.
* 4. Abort if setting isn't enabled.
*/
if ($request->subdomain) {
2020-05-28 17:48:03 +02:00
$company = Company::where('subdomain', $request->subdomain)->firstOrFail();
abort_unless($company->getSetting('enable_client_registration'), 404);
return $next($request);
2020-05-28 17:39:38 +02:00
}
abort_unless($request->company_key, 404);
$company = Company::where('company_key', $request->company_key)->firstOrFail();
2020-06-28 00:24:08 +02:00
abort_unless($company->client_can_register, 404);
2020-05-28 17:39:38 +02:00
return $next($request);
}
}