1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Http/Controllers/HostedMigrationController.php

74 lines
2.3 KiB
PHP
Raw Normal View History

2021-07-17 07:58:37 +02:00
<?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;
2021-11-08 03:05:54 +01:00
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\Company;
2021-07-17 07:58:37 +02:00
use App\Models\CompanyToken;
use Illuminate\Http\Request;
2021-11-08 03:05:54 +01:00
use Illuminate\Support\Facades\Artisan;
2021-07-17 07:58:37 +02:00
class HostedMigrationController extends Controller
{
public function getAccount(Request $request)
{
2021-07-17 07:58:37 +02:00
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);
2021-07-17 07:58:37 +02:00
}
$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);
}
2021-11-08 00:17:49 +01:00
public function confirmForwarding(Request $request)
{
if($request->header('X-API-HOSTED-SECRET') != config('ninja.ninja_hosted_secret'))
return;
2021-11-08 03:05:54 +01:00
$input = $request->all();
2021-11-21 03:49:52 +01:00
2021-11-08 03:05:54 +01:00
MultiDB::findAndSetDbByCompanyKey($input['account_key']);
$company = Company::with('account')->where('company_key', $input['account_key'])->first();
2021-11-21 02:57:27 +01:00
$forward_url = $company->domain();
2021-11-08 00:17:49 +01:00
2021-11-21 02:57:27 +01:00
$billing_transferred = \Modules\Admin\Jobs\Account\TransferAccountPlan::dispatchNow($input);
2021-11-08 03:05:54 +01:00
2021-11-21 02:57:27 +01:00
return response()->json(['forward_url' => $forward_url, 'billing_transferred' => $billing_transferred], 200);
2021-11-08 00:17:49 +01:00
}
2021-07-17 07:58:37 +02:00
}