2021-03-03 23:39:24 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2021-03-03 23:39:24 +01:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2021-03-03 23:39:24 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Services\User;
|
|
|
|
|
|
|
|
use App\Jobs\Mail\NinjaMailer;
|
|
|
|
use App\Jobs\Mail\NinjaMailerJob;
|
|
|
|
use App\Jobs\Mail\NinjaMailerObject;
|
|
|
|
use App\Mail\Admin\VerifyUserObject;
|
2023-10-02 08:20:26 +02:00
|
|
|
use App\Models\Company;
|
2021-03-03 23:39:24 +01:00
|
|
|
use App\Models\User;
|
|
|
|
use App\Utils\Ninja;
|
|
|
|
|
|
|
|
class UserService
|
|
|
|
{
|
2023-10-02 07:31:14 +02:00
|
|
|
public function __construct(public User $user)
|
2021-03-03 23:39:24 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-01-14 05:05:00 +01:00
|
|
|
public function invite(Company $company, bool $is_react = true)
|
2021-03-03 23:39:24 +01:00
|
|
|
{
|
2023-10-02 07:31:14 +02:00
|
|
|
|
2021-03-03 23:39:24 +01:00
|
|
|
try {
|
2024-01-14 05:05:00 +01:00
|
|
|
$nmo = new NinjaMailerObject();
|
2023-10-02 07:31:14 +02:00
|
|
|
$nmo->mailable = new NinjaMailer((new VerifyUserObject($this->user, $company, $is_react))->build());
|
2021-03-03 23:39:24 +01:00
|
|
|
$nmo->company = $company;
|
|
|
|
$nmo->to_user = $this->user;
|
|
|
|
$nmo->settings = $company->settings;
|
|
|
|
|
2021-08-02 23:01:28 +02:00
|
|
|
NinjaMailerJob::dispatch($nmo, true);
|
2021-03-03 23:39:24 +01:00
|
|
|
|
|
|
|
Ninja::registerNinjaUser($this->user);
|
|
|
|
} catch (\Exception $e) {
|
2022-06-21 11:57:17 +02:00
|
|
|
nlog("I couldn't send the verification email ".$e->getMessage());
|
2021-03-03 23:39:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->user;
|
|
|
|
}
|
|
|
|
}
|