2019-11-16 04:12:29 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @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-11-16 04:12:29 +01:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use App\Libraries\MultiDB;
|
|
|
|
use Closure;
|
|
|
|
|
|
|
|
class SetInviteDb
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
$error = [
|
2019-11-16 04:12:29 +01:00
|
|
|
'message' => 'Invalid URL',
|
|
|
|
'errors' => []
|
|
|
|
];
|
2019-12-30 22:59:12 +01:00
|
|
|
/*
|
2019-11-16 04:12:29 +01: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::findAndSetDbByInvitation($request->route('entity'), $request->route('invitation_key'))) {
|
|
|
|
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-11-16 04:12:29 +01:00
|
|
|
abort(404);
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-11-16 04:12:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|