1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 06:32:40 +01:00
invoiceninja/app/Jobs/Account/CreateAccount.php

80 lines
1.6 KiB
PHP
Raw Normal View History

2018-10-24 05:50:15 +02:00
<?php
namespace App\Jobs\Account;
use App\Events\Account\AccountCreated;
use App\Jobs\Company\CreateCompany;
2019-03-26 05:46:08 +01:00
use App\Jobs\Company\CreateCompanyToken;
use App\Jobs\User\CreateUser;
use App\Models\Account;
use App\Models\User;
use App\Utils\Traits\UserSessionAttributes;
2018-10-24 05:50:15 +02:00
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
2019-03-28 10:05:13 +01:00
use Illuminate\Support\Facades\Log;
2018-10-24 05:50:15 +02:00
class CreateAccount
{
use Dispatchable;
protected $request;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(array $request)
2018-10-24 05:50:15 +02:00
{
$this->request = $request;
}
/**
* Execute the job.
*
* @return void
*/
2019-04-18 13:57:22 +02:00
public function handle() : ?Account
2018-10-24 05:50:15 +02:00
{
/*
* Create account
*/
$account = Account::create($this->request);
/*
* Create company
*/
2018-10-24 05:50:15 +02:00
$company = CreateCompany::dispatchNow($this->request, $account);
/*
* Set default company
*/
$account->default_company_id = $company->id;
$account->save();
/*
* Create user
*/
2019-04-18 13:57:22 +02:00
$user = CreateUser::dispatchNow($this->request, $account, $company, true); //make user company_owner
2018-10-24 05:50:15 +02:00
2019-03-26 05:46:08 +01:00
/*
* Create token
*/
2019-03-26 22:17:28 +01:00
$company_token = CreateCompanyToken::dispatchNow($company, $user);
2019-03-26 05:46:08 +01:00
/*
* Login user
*/
2019-04-18 13:57:22 +02:00
//Auth::loginUsingId($user->id, true);
2018-10-24 05:50:15 +02:00
/*
* Fire related events
*/
event(new AccountCreated($user));
2018-10-24 05:50:15 +02:00
2019-04-18 13:57:22 +02:00
return $account;
2018-10-24 05:50:15 +02:00
}
}