mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 05:14:36 -04:00
One Time Token Requests
This commit is contained in:
parent
18fa537791
commit
aa290172ae
@ -11,14 +11,16 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\OneTimeToken\OneTimeRouterRequest;
|
||||
use App\Http\Requests\OneTimeToken\OneTimeTokenRequest;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class OneTimeTokenController extends BaseController
|
||||
{
|
||||
use DispatchesJobs;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@ -74,4 +76,27 @@ class OneTimeTokenController extends BaseController
|
||||
return response()->json(['hash' => $hash], 200);
|
||||
|
||||
}
|
||||
|
||||
public function router(OneTimeRouterRequest $request)
|
||||
{
|
||||
$data = Cache::get($request->input('hash'));
|
||||
|
||||
MultiDB::findAndSetDbByCompanyKey($data['company_key']);
|
||||
|
||||
$user = User::findOrFail($data['user_id']);
|
||||
|
||||
Auth::login($user, true);
|
||||
|
||||
Cache::forget($request->input('hash'));
|
||||
|
||||
$this->sendTo($data['context']);
|
||||
|
||||
}
|
||||
|
||||
/* We need to merge all contexts here and redirect to the correct location */
|
||||
private function sendTo($context)
|
||||
{
|
||||
|
||||
return redirect();
|
||||
}
|
||||
}
|
||||
|
45
app/Http/Requests/OneTimeToken/OneTimeRouterRequest.php
Normal file
45
app/Http/Requests/OneTimeToken/OneTimeRouterRequest.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\OneTimeToken;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class OneTimeRouterRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'hash' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
// $input = $this->all();
|
||||
// $this->replace($input);
|
||||
}
|
||||
}
|
@ -180,5 +180,6 @@ Route::match(['get', 'post'], 'payment_webhook/{company_key}/{company_gateway_id
|
||||
->name('payment_webhook');
|
||||
|
||||
Route::post('api/v1/postmark_webhook', 'PostMarkController@webhook');
|
||||
Route::get('token_hash_router', 'OneTimeTokenController@router');
|
||||
|
||||
Route::fallback('BaseController@notFound');
|
||||
|
Loading…
x
Reference in New Issue
Block a user