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

47 lines
1.1 KiB
PHP
Raw Normal View History

<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2019-05-11 05:32:07 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
2019-05-11 05:32:07 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Middleware;
use App\Libraries\MultiDB;
2019-03-27 23:30:32 +01:00
use App\Models\CompanyToken;
use Closure;
class SetDb
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
2019-09-24 00:37:38 +02:00
$error = [
'message' => 'Invalid Token',
'errors' => new \stdClass,
2019-09-24 00:37:38 +02:00
];
if ($request->header('X-API-TOKEN') && config('ninja.db.multi_db_enabled')) {
if (! MultiDB::findAndSetDb($request->header('X-API-TOKEN'))) {
2019-09-24 23:18:41 +02:00
return response()->json($error, 403);
}
} elseif (! config('ninja.db.multi_db_enabled')) {
return $next($request);
} else {
return response()->json($error, 403);
}
return $next($request);
}
}