1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 22:22:32 +01:00

Minor fixes for vendor key login

This commit is contained in:
David Bomba 2022-10-25 12:42:05 +11:00
parent 9a8468906a
commit 7459a211cd
2 changed files with 19 additions and 1 deletions

View File

@ -65,7 +65,7 @@ class VendorContactKeyLogin
return redirect($this->setRedirectPath());
}
} elseif ($request->segment(3) && config('ninja.db.multi_db_enabled')) {
if (MultiDB::findAndSetDbByContactKey($request->segment(3))) {
if (MultiDB::findAndSetDbByVendorContactKey($request->segment(3))) {
if ($vendor_contact = VendorContact::where('contact_key', $request->segment(3))->first()) {
if (empty($vendor_contact->email)) {
$vendor_contact->email = Str::random(6).'@example.com';

View File

@ -18,6 +18,7 @@ use App\Models\Company;
use App\Models\CompanyToken;
use App\Models\Document;
use App\Models\User;
use App\Models\VendorContact;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
@ -364,6 +365,23 @@ class MultiDB
return false;
}
public static function findAndSetDbByVendorContactKey($contact_key) :bool
{
$current_db = config('database.default');
foreach (self::$dbs as $db) {
if (VendorContact::on($db)->where('contact_key', $contact_key)->exists()) {
self::setDb($db);
return true;
}
}
self::setDB($current_db);
return false;
}
public static function findAndSetDbByClientHash($client_hash) :bool
{
$current_db = config('database.default');