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
|
|
|
|
2020-04-09 12:48:04 +02:00
|
|
|
$company_token = new CompanyToken;
|
|
|
|
$company_token->user_id = $this->user->id;
|
|
|
|
$company_token->company_id = $this->company->id;
|
|
|
|
$company_token->account_id = $this->user->account->id;
|
|
|
|
$company_token->name = $this->custom_token_name ?: $this->user->first_name. ' '. $this->user->last_name;
|
|
|
|
$company_token->token = Str::random(64);
|
2020-07-21 07:03:04 +02:00
|
|
|
$company_token->is_system = true;
|
|
|
|
|
2020-04-09 12:48:04 +02:00
|
|
|
$company_token->save();
|
|
|
|
|
2019-03-26 22:17:28 +01:00
|
|
|
|
2020-04-09 12:48:04 +02:00
|
|
|
return $company_token;
|
2019-03-26 05:46:08 +01:00
|
|
|
}
|
|
|
|
}
|