Fix user creation to use UUIDs correctly

Also updates the notification send method to be cleaner and more maintainable
This commit is contained in:
Dane Everitt 2018-01-01 12:13:08 -06:00
parent 410a0cca9a
commit 4457634127
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 97 additions and 171 deletions

View file

@ -1,77 +1,52 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Users;
use Ramsey\Uuid\Uuid;
use Illuminate\Foundation\Application;
use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Notifications\ChannelManager;
use Pterodactyl\Notifications\AccountCreated;
use Pterodactyl\Services\Helpers\TemporaryPasswordService;
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
class UserCreationService
{
/**
* @var \Illuminate\Foundation\Application
*/
protected $app;
/**
* @var \Illuminate\Database\ConnectionInterface
*/
protected $connection;
private $connection;
/**
* @var \Illuminate\Contracts\Hashing\Hasher
*/
protected $hasher;
/**
* @var \Illuminate\Notifications\ChannelManager
*/
protected $notification;
private $hasher;
/**
* @var \Pterodactyl\Services\Helpers\TemporaryPasswordService
*/
protected $passwordService;
private $passwordService;
/**
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
*/
protected $repository;
private $repository;
/**
* CreationService constructor.
*
* @param \Illuminate\Foundation\Application $application
* @param \Illuminate\Notifications\ChannelManager $notification
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
* @param \Pterodactyl\Services\Helpers\TemporaryPasswordService $passwordService
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
*/
public function __construct(
Application $application,
ChannelManager $notification,
ConnectionInterface $connection,
Hasher $hasher,
TemporaryPasswordService $passwordService,
UserRepositoryInterface $repository
) {
$this->app = $application;
$this->connection = $connection;
$this->hasher = $hasher;
$this->notification = $notification;
$this->passwordService = $passwordService;
$this->repository = $repository;
}
@ -97,20 +72,13 @@ class UserCreationService
$token = $this->passwordService->handle($data['email']);
}
/** @var \Pterodactyl\Models\User $user */
$user = $this->repository->create(array_merge($data, [
'uuid' => Uuid::uuid4()->toString(),
]));
]), true, true);
$this->connection->commit();
// @todo fire event, handle notification there
$this->notification->send($user, $this->app->makeWith(AccountCreated::class, [
'user' => [
'name' => $user->name_first,
'username' => $user->username,
'token' => $token ?? null,
],
]));
$user->notify(new AccountCreated($user, $token ?? null));
return $user;
}