2019-07-12 07:03:30 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-07-12 07:03:30 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-07-12 07:03:30 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use App\Libraries\MultiDB;
|
|
|
|
use Closure;
|
2020-10-28 11:10:49 +01:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use stdClass;
|
2019-07-12 07:03:30 +02:00
|
|
|
|
|
|
|
class SetDomainNameDb
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param Request $request
|
|
|
|
* @param Closure $next
|
2019-07-12 07:03:30 +02:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
$error = [
|
2019-09-24 00:37:38 +02:00
|
|
|
'message' => 'Invalid token',
|
2020-10-28 11:10:49 +01:00
|
|
|
'errors' => new stdClass,
|
2019-09-24 00:37:38 +02:00
|
|
|
];
|
2019-12-30 22:59:12 +01:00
|
|
|
/*
|
2019-07-12 07:03:30 +02:00
|
|
|
* Use the host name to set the active DB
|
|
|
|
**/
|
2019-12-30 22:59:12 +01:00
|
|
|
if ($request->getSchemeAndHttpHost() && config('ninja.db.multi_db_enabled') && ! MultiDB::findAndSetDbByDomain($request->getSchemeAndHttpHost())) {
|
|
|
|
if (request()->json) {
|
2020-02-05 05:06:03 +01:00
|
|
|
return response()->json($error, 403);
|
2019-12-30 22:59:12 +01:00
|
|
|
} else {
|
2019-09-23 07:59:01 +02:00
|
|
|
abort(404);
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-07-12 07:03:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|