1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Http/Middleware/DatabaseLookup.php

39 lines
1.1 KiB
PHP
Raw Normal View History

2017-04-30 22:08:07 +02:00
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Closure;
2017-05-01 08:50:10 +02:00
use App\Models\LookupContact;
use App\Models\LookupInvitation;
2017-05-01 09:03:42 +02:00
use App\Models\LookupAccountToken;
2017-04-30 22:08:07 +02:00
class DatabaseLookup
{
2017-05-01 08:50:10 +02:00
public function handle(Request $request, Closure $next, $guard = 'user')
2017-04-30 22:08:07 +02:00
{
2017-05-01 08:50:10 +02:00
if (! env('MULTI_DB_ENABLED')) {
return $next($request);
}
// user's value is set when logging in
if ($guard == 'user') {
if (! session('SESSION_USER_DB_SERVER')) {
return redirect('/logout');
}
2017-05-01 09:03:42 +02:00
} elseif ($guard == 'api') {
if ($token = $request->header('X-Ninja-Token')) {
LookupAccountToken::setServerByField('token', $token);
}
2017-05-01 08:50:10 +02:00
} else {
if (request()->invitation_key) {
LookupInvitation::setServerByField('invitation_key', request()->invitation_key);
} elseif (request()->contact_key) {
LookupContact::setServerByField('contact_key', request()->contact_key);
}
2017-04-30 22:08:07 +02:00
}
return $next($request);
}
}