1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 00:41:34 +02:00
invoiceninja/app/Jobs/User/CreateUser.php

68 lines
1.5 KiB
PHP
Raw Normal View History

2018-10-24 05:50:15 +02:00
<?php
namespace App\Jobs\User;
2019-02-17 12:07:58 +01:00
use App\DataMapper\DefaultSettings;
use App\Events\User\UserCreated;
use App\Models\CompanyUser;
2019-02-17 12:07:58 +01:00
use App\Models\User;
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(array $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
2018-10-24 05:50:15 +02:00
{
$user = new User();
$user->account_id = $this->account->id;
$user->password = bcrypt($this->request['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'));
$user->fill($this->request);
2018-10-24 05:50:15 +02:00
$user->save();
2018-11-02 12:57:59 +01:00
$user->companies()->attach($this->company->id, [
'account_id' => $this->account->id,
'is_owner' => 1,
'is_admin' => 1,
'is_locked' => 0,
'permissions' => json_encode([]),
2019-02-17 12:07:58 +01:00
'settings' => json_encode(DefaultSettings::userSettings()),
2018-11-02 12:57:59 +01:00
]);
event(new UserCreated($user));
2018-10-24 05:50:15 +02:00
return $user;
}
}