Multi-db support

This commit is contained in:
Hillel Coren 2017-05-01 10:03:42 +03:00
parent 9c70ca63f3
commit 479340c07a
6 changed files with 15 additions and 7 deletions

View File

@ -9,7 +9,7 @@ use App\Models\LookupCompany;
use App\Models\LookupAccount; use App\Models\LookupAccount;
use App\Models\LookupUser; use App\Models\LookupUser;
use App\Models\LookupContact; use App\Models\LookupContact;
use App\Models\LookupToken; use App\Models\LookupAccountToken;
use App\Models\LookupInvitation; use App\Models\LookupInvitation;
class InitLookup extends Command class InitLookup extends Command
@ -123,7 +123,7 @@ class InitLookup extends Command
]); ]);
} }
foreach ($account['tokens'] as $token) { foreach ($account['tokens'] as $token) {
LookupToken::create([ LookupAccountToken::create([
'lookup_account_id' => $lookupAccount->id, 'lookup_account_id' => $lookupAccount->id,
'token' => $token['token'], 'token' => $token['token'],
]); ]);

View File

@ -6,6 +6,7 @@ use Illuminate\Http\Request;
use Closure; use Closure;
use App\Models\LookupContact; use App\Models\LookupContact;
use App\Models\LookupInvitation; use App\Models\LookupInvitation;
use App\Models\LookupAccountToken;
class DatabaseLookup class DatabaseLookup
{ {
@ -20,7 +21,10 @@ class DatabaseLookup
if (! session('SESSION_USER_DB_SERVER')) { if (! session('SESSION_USER_DB_SERVER')) {
return redirect('/logout'); return redirect('/logout');
} }
// contacts can login with just the URL } elseif ($guard == 'api') {
if ($token = $request->header('X-Ninja-Token')) {
LookupAccountToken::setServerByField('token', $token);
}
} else { } else {
if (request()->invitation_key) { if (request()->invitation_key) {
LookupInvitation::setServerByField('invitation_key', request()->invitation_key); LookupInvitation::setServerByField('invitation_key', request()->invitation_key);

View File

@ -300,7 +300,7 @@ Route::group(['middleware' => ['lookup:user', 'auth:user']], function () {
}); });
// Route groups for API // Route groups for API
Route::group(['middleware' => 'api', 'prefix' => 'api/v1'], function () { Route::group(['middleware' => ['lookup:api', 'api'], 'prefix' => 'api/v1'], function () {
Route::get('ping', 'AccountApiController@ping'); Route::get('ping', 'AccountApiController@ping');
Route::post('login', 'AccountApiController@login'); Route::post('login', 'AccountApiController@login');
Route::post('oauth_login', 'AccountApiController@oauthLogin'); Route::post('oauth_login', 'AccountApiController@oauthLogin');

View File

@ -3,7 +3,7 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\LookupToken; use App\Models\LookupAccountToken;
/** /**
* Class AccountToken. * Class AccountToken.
@ -43,7 +43,7 @@ class AccountToken extends EntityModel
AccountToken::creating(function ($token) AccountToken::creating(function ($token)
{ {
LookupToken::createNew($token->account->account_key, [ LookupAccountToken::createNew($token->account->account_key, [
'token' => $token->token, 'token' => $token->token,
]); ]);
}); });

View File

@ -7,7 +7,7 @@ use Eloquent;
/** /**
* Class ExpenseCategory. * Class ExpenseCategory.
*/ */
class LookupToken extends LookupModel class LookupAccountToken extends LookupModel
{ {
/** /**
* @var array * @var array

View File

@ -45,6 +45,8 @@ class AddMultipleDatabaseSupport extends Migration
Schema::table('lookup_tokens', function ($table) { Schema::table('lookup_tokens', function ($table) {
$table->string('token')->change()->unique(); $table->string('token')->change()->unique();
}); });
Schema::rename('lookup_tokens', 'lookup_account_tokens');
} }
/** /**
@ -57,5 +59,7 @@ class AddMultipleDatabaseSupport extends Migration
Schema::table('lookup_companies', function ($table) { Schema::table('lookup_companies', function ($table) {
$table->dropColumn('company_id'); $table->dropColumn('company_id');
}); });
Schema::rename('lookup_account_tokens', 'lookup_tokens');
} }
} }