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);
|
|
|
|
}
|
|
|
|
}
|