2019-03-26 05:46:08 +01:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-03-26 05:46:08 +01:00
|
|
|
|
|
|
|
namespace App\Jobs\Company;
|
|
|
|
|
|
|
|
use App\Models\Company;
|
2019-03-26 22:17:28 +01:00
|
|
|
use App\Models\CompanyToken;
|
2019-03-26 05:46:08 +01:00
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2019-09-26 15:00:51 +02:00
|
|
|
use Illuminate\Support\Str;
|
2019-03-26 05:46:08 +01:00
|
|
|
|
|
|
|
class CreateCompanyToken implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
protected $company;
|
|
|
|
|
|
|
|
protected $user;
|
|
|
|
|
2019-11-26 09:14:01 +01:00
|
|
|
protected $custom_token_name;
|
2019-03-26 05:46:08 +01:00
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-11-26 09:14:01 +01:00
|
|
|
public function __construct(Company $company, User $user, string $custom_token_name)
|
2019-03-26 05:46:08 +01:00
|
|
|
{
|
|
|
|
$this->company = $company;
|
|
|
|
|
|
|
|
$this->user = $user;
|
2019-11-21 09:38:57 +01:00
|
|
|
|
2019-11-26 09:14:01 +01:00
|
|
|
$this->custom_token_name = $custom_token_name;
|
2019-03-26 05:46:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-03-26 22:17:28 +01:00
|
|
|
public function handle() : ?CompanyToken
|
2019-03-26 05:46:08 +01:00
|
|
|
{
|
2019-11-26 09:14:01 +01:00
|
|
|
$this->custom_token_name = $this->custom_token_name ?: $this->user->first_name. ' '. $this->user->last_name;
|
2019-03-26 22:17:28 +01:00
|
|
|
|
|
|
|
$ct = CompanyToken::create([
|
2019-03-26 05:46:08 +01:00
|
|
|
'user_id' => $this->user->id,
|
2020-03-30 08:40:21 +02:00
|
|
|
'account_id' => $this->user->account->id,
|
2019-09-26 15:00:51 +02:00
|
|
|
'token' => Str::random(64),
|
2019-11-26 09:14:01 +01:00
|
|
|
'name' => $this->custom_token_name ?: $this->user->first_name. ' '. $this->user->last_name,
|
2019-03-26 22:17:28 +01:00
|
|
|
'company_id' => $this->company->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $ct;
|
2019-03-26 05:46:08 +01:00
|
|
|
}
|
|
|
|
}
|