mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 06:04:30 -04:00
Multi-db support
This commit is contained in:
parent
97c2a35868
commit
2e0cd34bf8
@ -142,7 +142,7 @@ class AuthController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function postLoginWrapper(Request $request)
|
public function postLoginWrapper(Request $request)
|
||||||
{
|
{
|
||||||
LookupUser::loadEmail($request->input('email'));
|
LookupUser::setServerByEmail($request->input('email'));
|
||||||
|
|
||||||
$userId = Auth::check() ? Auth::user()->id : null;
|
$userId = Auth::check() ? Auth::user()->id : null;
|
||||||
$user = User::where('email', '=', $request->input('email'))->first();
|
$user = User::where('email', '=', $request->input('email'))->first();
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Eloquent;
|
use Eloquent;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ExpenseCategory.
|
* Class ExpenseCategory.
|
||||||
@ -18,7 +19,7 @@ class LookupUser extends LookupModel
|
|||||||
'user_id',
|
'user_id',
|
||||||
];
|
];
|
||||||
|
|
||||||
public static function loadEmail($email)
|
public static function setServerByEmail($email)
|
||||||
{
|
{
|
||||||
if (! env('MULTI_DB_ENABLED')) {
|
if (! env('MULTI_DB_ENABLED')) {
|
||||||
return;
|
return;
|
||||||
@ -28,10 +29,15 @@ class LookupUser extends LookupModel
|
|||||||
config(['database.default' => DB_NINJA_LOOKUP]);
|
config(['database.default' => DB_NINJA_LOOKUP]);
|
||||||
|
|
||||||
if ($lookupUser = static::whereEmail($email)->first()) {
|
if ($lookupUser = static::whereEmail($email)->first()) {
|
||||||
session(['SESSION_DB_SERVER' => $lookupUser->getDbServer()]);
|
$server = $lookupUser->getDbServer();
|
||||||
}
|
session(['SESSION_DB_SERVER' => $server]);
|
||||||
|
config(['database.default' => $server]);
|
||||||
|
|
||||||
|
if (! User::whereEmail($email)->first()) {
|
||||||
|
abort('Lookedup user not found: ' . $email);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
config(['database.default' => $current]);
|
config(['database.default' => $current]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user