user creating flow updated
This commit is contained in:
		@@ -1,20 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Events\Auth;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Event;
 | 
			
		||||
 | 
			
		||||
class InvitationCreated extends Event
 | 
			
		||||
{
 | 
			
		||||
    public $invitation;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a new event instance.
 | 
			
		||||
     *
 | 
			
		||||
     * @param $invitation
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct($invitation)
 | 
			
		||||
    {
 | 
			
		||||
        $this->invitation = $invitation;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -3,9 +3,11 @@
 | 
			
		||||
namespace App\Jobs\Auth;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Job;
 | 
			
		||||
use App\Events\Auth\InvitationCreated;
 | 
			
		||||
use App\Models\Auth\UserInvitation;
 | 
			
		||||
use App\Notifications\Auth\Invitation as Notification;
 | 
			
		||||
use Exception;
 | 
			
		||||
use Illuminate\Support\Str;
 | 
			
		||||
use Symfony\Component\Mailer\Exception\TransportException;
 | 
			
		||||
 | 
			
		||||
class CreateInvitation extends Job
 | 
			
		||||
{
 | 
			
		||||
@@ -13,31 +15,29 @@ class CreateInvitation extends Job
 | 
			
		||||
 | 
			
		||||
    protected $user;
 | 
			
		||||
 | 
			
		||||
    protected $company;
 | 
			
		||||
 | 
			
		||||
    public function __construct($user, $company)
 | 
			
		||||
    public function __construct($user)
 | 
			
		||||
    {
 | 
			
		||||
        $this->user = $user;
 | 
			
		||||
        $this->company = $company;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function handle(): UserInvitation
 | 
			
		||||
    {
 | 
			
		||||
        \DB::transaction(function () {
 | 
			
		||||
            if ($this->user->hasPendingInvitation($this->company->id)) {
 | 
			
		||||
                $pending_invitation = $this->user->getPendingInvitation($this->company->id);
 | 
			
		||||
 | 
			
		||||
                $this->dispatch(new DeleteInvitation($pending_invitation));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $this->invitation = UserInvitation::create([
 | 
			
		||||
                'user_id' => $this->user->id,
 | 
			
		||||
                'company_id' => $this->company->id,
 | 
			
		||||
                'token' => (string) Str::uuid(),
 | 
			
		||||
            ]);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        event(new InvitationCreated($this->invitation));
 | 
			
		||||
            $notification = new Notification($this->invitation);
 | 
			
		||||
 | 
			
		||||
            try {
 | 
			
		||||
                $this->dispatch(new NotifyUser($this->user, $notification));
 | 
			
		||||
            } catch (TransportException $e) {
 | 
			
		||||
                $message = trans('errors.title.500');
 | 
			
		||||
 | 
			
		||||
                throw new Exception($message);
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        return $this->invitation;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -69,12 +69,10 @@ class CreateUser extends Job implements HasOwner, HasSource, ShouldCreate
 | 
			
		||||
                    'user' => $this->model->id,
 | 
			
		||||
                    'company' => $company->id,
 | 
			
		||||
                ]);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
                if (app()->runningInConsole() || request()->isInstall()) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                $this->dispatch(new CreateInvitation($this->model, $company));
 | 
			
		||||
            if (! app()->runningInConsole() && ! request()->isInstall()) {
 | 
			
		||||
                $this->dispatch(new CreateInvitation($this->model));
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,22 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Listeners\Auth;
 | 
			
		||||
 | 
			
		||||
use App\Events\Auth\InvitationCreated as Event;
 | 
			
		||||
use App\Notifications\Auth\Invitation as Notification;
 | 
			
		||||
 | 
			
		||||
class SendUserInvitation
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Handle the event.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $event
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    public function handle(Event $event)
 | 
			
		||||
    {
 | 
			
		||||
        $invitation = $event->invitation;
 | 
			
		||||
 | 
			
		||||
        $invitation->user->notify(new Notification($invitation));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user