2018-10-24 05:50:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs\User;
|
|
|
|
|
2018-10-29 04:16:17 +01:00
|
|
|
use App\Events\User\UserCreated;
|
2018-10-24 12:24:09 +02:00
|
|
|
use App\Models\User;
|
2018-11-02 11:54:46 +01:00
|
|
|
use App\Models\CompanyUser;
|
2018-10-26 06:53:29 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2018-10-24 05:50:15 +02:00
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class CreateUser
|
|
|
|
{
|
2018-10-26 06:53:29 +02:00
|
|
|
use MakesHash;
|
2018-10-24 05:50:15 +02:00
|
|
|
use Dispatchable;
|
|
|
|
|
|
|
|
protected $request;
|
|
|
|
|
|
|
|
protected $account;
|
2018-10-24 12:24:09 +02:00
|
|
|
|
|
|
|
protected $company;
|
|
|
|
|
2018-10-24 05:50:15 +02:00
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
|
2018-10-24 12:24:09 +02:00
|
|
|
public function __construct(Request $request, $account, $company)
|
2018-10-24 05:50:15 +02:00
|
|
|
{
|
|
|
|
$this->request = $request;
|
|
|
|
$this->account = $account;
|
2018-10-24 12:24:09 +02:00
|
|
|
$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;
|
2018-10-24 12:24:09 +02:00
|
|
|
$user->password = bcrypt($this->request->input('password'));
|
2018-10-24 05:50:15 +02:00
|
|
|
$user->accepted_terms_version = config('ninja.terms_version');
|
2018-10-26 06:53:29 +02:00
|
|
|
$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();
|
|
|
|
|
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
CompanyUser::create([
|
2018-10-24 12:24:09 +02:00
|
|
|
'user_id' => $user->id,
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'is_admin' => true,
|
|
|
|
'is_owner' => true,
|
|
|
|
'permissions' => '',
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
2018-10-29 04:16:17 +01:00
|
|
|
|
|
|
|
event(new UserCreated($user));
|
|
|
|
|
2018-10-24 05:50:15 +02:00
|
|
|
return $user;
|
|
|
|
}
|
|
|
|
}
|