mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Streamline Hosted Migrations
This commit is contained in:
parent
a4c1829257
commit
a38dcbdd87
52
app/Http/Controllers/HostedMigrationController.php
Normal file
52
app/Http/Controllers/HostedMigrationController.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?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://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Jobs\Account\CreateAccount;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\CompanyToken;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class HostedMigrationController extends Controller
|
||||
{
|
||||
|
||||
public function getAccount(Request $request)
|
||||
{
|
||||
if($request->header('X-API-HOSTED-SECRET') != config('ninja.ninja_hosted_secret'))
|
||||
return;
|
||||
|
||||
if($user = MultiDB::hasUser(['email' => $request->input('email')]))
|
||||
{
|
||||
|
||||
if($user->account->owner() && $user->account->companies()->count() >= 1)
|
||||
{
|
||||
return response()->json(['token' => $user->account->companies->first()->tokens->first()->token] ,200);
|
||||
}
|
||||
|
||||
|
||||
return response()->json(['error' => 'This user is not able to perform a migration. Please contact us at contact@invoiceninja.com to discuss.'], 401)
|
||||
|
||||
}
|
||||
|
||||
$account = CreateAccount::dispatchNow($request->all(), $request->getClientIp());
|
||||
|
||||
$company = $account->companies->first();
|
||||
|
||||
$company_token = CompanyToken::where('user_id', auth()->user()->id)
|
||||
->where('company_id', $company->id)
|
||||
->first();
|
||||
|
||||
return response()->json(['token' => $company_token->token], 200);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -46,7 +46,8 @@ class CreateAccountRequest extends Request
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{nlog($this->all());
|
||||
{
|
||||
|
||||
$input = $this->all();
|
||||
|
||||
$input['user_agent'] = request()->server('HTTP_USER_AGENT');
|
||||
|
@ -319,6 +319,12 @@ class Import implements ShouldQueue
|
||||
$account = $this->company->account;
|
||||
$account->fill($data);
|
||||
$account->save();
|
||||
|
||||
//Prevent hosted users being pushed into a trial
|
||||
if(Ninja::isHosted() && $account->plan != ''){
|
||||
$account->trial_plan = '';
|
||||
$account->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -206,4 +206,6 @@ Route::post('api/v1/postmark_webhook', 'PostMarkController@webhook');
|
||||
Route::get('token_hash_router', 'OneTimeTokenController@router');
|
||||
Route::get('webcron', 'WebCronController@index');
|
||||
|
||||
Route::post('api/v1/get_migration_account', 'HostedMigration@getAccount');
|
||||
|
||||
Route::fallback('BaseController@notFound');
|
||||
|
Loading…
x
Reference in New Issue
Block a user