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

70 lines
1.5 KiB
PHP
Raw Normal View History

2018-10-24 05:50:15 +02:00
<?php
namespace App\Jobs\User;
use App\Events\User\UserCreated;
use App\Models\User;
use App\Models\CompanyUser;
use App\Utils\Traits\MakesHash;
2018-10-24 05:50:15 +02:00
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Http\Request;
class CreateUser
{
use MakesHash;
2018-10-24 05:50:15 +02:00
use Dispatchable;
protected $request;
protected $account;
protected $company;
2018-10-24 05:50:15 +02:00
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Request $request, $account, $company)
2018-10-24 05:50:15 +02:00
{
$this->request = $request;
$this->account = $account;
$this->company = $company;
2018-10-24 05:50:15 +02:00
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$user = new User();
$user->account_id = $this->account->id;
$user->password = bcrypt($this->request->input('password'));
2018-10-24 05:50:15 +02:00
$user->accepted_terms_version = config('ninja.terms_version');
$user->confirmation_code = $this->createDbHash(config('database.default'));
2018-10-24 05:50:15 +02:00
$user->db = config('database.default');
$user->fill($this->request->all());
$user->save();
CompanyUser::create([
'user_id' => $user->id,
'account_id' => $this->account->id,
'company_id' => $this->company->id,
'is_admin' => true,
'is_owner' => true,
'permissions' => '',
]);
event(new UserCreated($user));
2018-10-24 05:50:15 +02:00
return $user;
}
}