1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Http/Middleware/ContactRegister.php
2020-05-28 17:48:03 +02:00

46 lines
1.2 KiB
PHP

<?php
namespace App\Http\Middleware;
use App\Models\Company;
use Closure;
class ContactRegister
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
/**
* Notes:
*
* 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) {
$company = Company::where('subdomain', $request->subdomain)->firstOrFail();
abort_unless($company->getSetting('enable_client_registration'), 404);
return $next($request);
}
abort_unless($request->company_key, 404);
$company = Company::where('company_key', $request->company_key)->firstOrFail();
abort_unless($company->getSetting('enable_client_registration'), 404);
// abort_unless(true, 404);
return $next($request);
}
}