diff --git a/app/Http/Controllers/ClientPortal/InvitationController.php b/app/Http/Controllers/ClientPortal/InvitationController.php new file mode 100644 index 000000000000..e49c063357d5 --- /dev/null +++ b/app/Http/Controllers/ClientPortal/InvitationController.php @@ -0,0 +1,46 @@ +first(); + + if($invitation){ + $invitation->markViewed(); + Auth::guard('contact')->loginUsingId($invitation->client_contact_id, true); + return redirect()->route('client.invoice.show', ['invoice' => $this->encodePrimaryKey($invitation->invoice_id)]); + } + else + abort(404); + + } +} diff --git a/app/Http/Middleware/SetDomainNameDb.php b/app/Http/Middleware/SetDomainNameDb.php index 852a543f2d9f..e5605e312981 100644 --- a/app/Http/Middleware/SetDomainNameDb.php +++ b/app/Http/Middleware/SetDomainNameDb.php @@ -34,9 +34,10 @@ class SetDomainNameDb **/ if( $request->getHttpHost() && config('ninja.db.multi_db_enabled') && ! MultiDB::findAndSetDbByDomain($request->getHttpHost())) { - - return response()->json(json_encode($error, JSON_PRETTY_PRINT) ,403); - + if(request()->json) + return response()->json(json_encode($error, JSON_PRETTY_PRINT) ,403); + else + abort(404); } return $next($request); diff --git a/app/Http/Middleware/UrlSetDb.php b/app/Http/Middleware/UrlSetDb.php index bb0ee5e13861..0e8bb10903c5 100644 --- a/app/Http/Middleware/UrlSetDb.php +++ b/app/Http/Middleware/UrlSetDb.php @@ -34,7 +34,7 @@ class UrlSetDb if (config('ninja.db.multi_db_enabled')) { - $hashids = new Hashids('', 15); //decoded output is _always_ an array. + $hashids = new Hashids('', 10); //decoded output is _always_ an array. //parse URL hash and set DB $segments = explode("-", $request->route('confirmation_code')); diff --git a/app/Models/InvoiceInvitation.php b/app/Models/InvoiceInvitation.php index 814c19e71449..a648329a581c 100644 --- a/app/Models/InvoiceInvitation.php +++ b/app/Models/InvoiceInvitation.php @@ -14,6 +14,7 @@ namespace App\Models; use App\Models\Invoice; use App\Utils\Traits\MakesDates; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Carbon; class InvoiceInvitation extends BaseModel { @@ -79,4 +80,10 @@ class InvoiceInvitation extends BaseModel { } + + public function markViewed() + { + $this->viewed_date = Carbon::now(); + $this->save(); + } } diff --git a/database/seeds/RandomDataSeeder.php b/database/seeds/RandomDataSeeder.php index f6732d5f0b7f..2c3166dd1583 100644 --- a/database/seeds/RandomDataSeeder.php +++ b/database/seeds/RandomDataSeeder.php @@ -39,7 +39,7 @@ class RandomDataSeeder extends Seeder $account = factory(\App\Models\Account::class)->create(); $company = factory(\App\Models\Company::class)->create([ 'account_id' => $account->id, - 'domain' => 'ninja.test', + 'domain' => 'ninja.test:8000', ]); $account->default_company_id = $company->id; diff --git a/routes/client.php b/routes/client.php index 275565d985b7..e9b973c5876d 100644 --- a/routes/client.php +++ b/routes/client.php @@ -40,4 +40,11 @@ Route::group(['middleware' => ['auth:contact'], 'prefix' => 'client', 'as' => 'c }); +Route::group(['middleware' => ['domain_db'], 'prefix' => 'client', 'as' => 'client.'], function () { + + /*Invitation catches*/ + Route::get('invoice/{invitation_id}','ClientPortal\InvitationController@invoiceRouter'); + +}); + Route::fallback('BaseController@notFoundClient'); \ No newline at end of file