1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Invitation routing

This commit is contained in:
David Bomba 2019-09-23 15:59:01 +10:00
parent d5ec342764
commit 1e1be26980
6 changed files with 66 additions and 5 deletions

View File

@ -0,0 +1,46 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Controllers\ClientPortal;
use App\Http\Controllers\Controller;
use App\Models\InvoiceInvitation;
use App\Utils\Traits\MakesDates;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
/**
* Class InvitationController
* @package App\Http\Controllers\ClientPortal\InvitationController
*/
class InvitationController extends Controller
{
use MakesHash;
use MakesDates;
public function invoiceRouter(string $invitation_key)
{
$invitation = InvoiceInvitation::whereInvitationKey($invitation_key)->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);
}
}

View File

@ -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);

View File

@ -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'));

View File

@ -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();
}
}

View File

@ -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;

View File

@ -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');