mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-21 10:00:56 -04:00
41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Closure;
|
|
use App\Models\LookupContact;
|
|
use App\Models\LookupInvitation;
|
|
use App\Models\LookupAccountToken;
|
|
use App\Models\LookupUser;
|
|
|
|
class DatabaseLookup
|
|
{
|
|
public function handle(Request $request, Closure $next, $guard = 'user')
|
|
{
|
|
if (! env('MULTI_DB_ENABLED')) {
|
|
return $next($request);
|
|
}
|
|
|
|
if ($guard == 'user') {
|
|
if ($email = $request->email) {
|
|
LookupUser::setServerByField('email', $email);
|
|
}
|
|
} elseif ($guard == 'api') {
|
|
if ($token = $request->header('X-Ninja-Token')) {
|
|
LookupAccountToken::setServerByField('token', $token);
|
|
}
|
|
} elseif ($guard == 'contact') {
|
|
if ($key = request()->invitation_key) {
|
|
LookupInvitation::setServerByField('invitation_key', $key);
|
|
} elseif ($key = request()->contact_key) {
|
|
LookupContact::setServerByField('contact_key', $key);
|
|
}
|
|
} elseif ($guard == 'postmark') {
|
|
LookupInvitation::setServerByField('message_id', request()->MessageID);
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|