2017-08-05 00:11:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Users;
|
|
|
|
|
2017-12-03 20:00:47 +00:00
|
|
|
use Pterodactyl\Models\User;
|
2017-08-05 00:11:41 +00:00
|
|
|
use Illuminate\Contracts\Hashing\Hasher;
|
2017-12-03 20:00:47 +00:00
|
|
|
use Pterodactyl\Traits\Services\HasUserLevels;
|
2019-12-08 19:02:59 +00:00
|
|
|
use Pterodactyl\Repositories\Eloquent\UserRepository;
|
2017-08-05 00:11:41 +00:00
|
|
|
|
2017-08-27 20:10:51 +00:00
|
|
|
class UserUpdateService
|
2017-08-05 00:11:41 +00:00
|
|
|
{
|
2017-12-03 20:00:47 +00:00
|
|
|
use HasUserLevels;
|
|
|
|
|
2017-08-05 00:11:41 +00:00
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Hashing\Hasher
|
|
|
|
*/
|
2017-12-03 20:00:47 +00:00
|
|
|
private $hasher;
|
2017-08-05 00:11:41 +00:00
|
|
|
|
|
|
|
/**
|
2019-12-08 19:02:59 +00:00
|
|
|
* @var \Pterodactyl\Repositories\Eloquent\UserRepository
|
2017-08-05 00:11:41 +00:00
|
|
|
*/
|
2017-12-03 20:00:47 +00:00
|
|
|
private $repository;
|
|
|
|
|
2017-08-05 00:11:41 +00:00
|
|
|
/**
|
|
|
|
* UpdateService constructor.
|
|
|
|
*
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
|
2019-12-08 19:02:59 +00:00
|
|
|
* @param \Pterodactyl\Repositories\Eloquent\UserRepository $repository
|
2017-08-05 00:11:41 +00:00
|
|
|
*/
|
2019-12-08 19:02:59 +00:00
|
|
|
public function __construct(Hasher $hasher, UserRepository $repository)
|
|
|
|
{
|
2017-08-05 00:11:41 +00:00
|
|
|
$this->hasher = $hasher;
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-08 19:02:59 +00:00
|
|
|
* Update the user model instance.
|
2017-08-05 00:11:41 +00:00
|
|
|
*
|
2017-12-03 20:00:47 +00:00
|
|
|
* @param \Pterodactyl\Models\User $user
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param array $data
|
2019-12-08 19:02:59 +00:00
|
|
|
* @return \Pterodactyl\Models\User
|
2017-08-05 00:11:41 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-08-31 02:11:14 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-08-05 00:11:41 +00:00
|
|
|
*/
|
2019-12-08 19:02:59 +00:00
|
|
|
public function handle(User $user, array $data)
|
2017-08-05 00:11:41 +00:00
|
|
|
{
|
2018-02-08 03:13:40 +00:00
|
|
|
if (! empty(array_get($data, 'password'))) {
|
2017-08-05 00:11:41 +00:00
|
|
|
$data['password'] = $this->hasher->make($data['password']);
|
2018-02-08 03:13:40 +00:00
|
|
|
} else {
|
|
|
|
unset($data['password']);
|
2017-08-05 00:11:41 +00:00
|
|
|
}
|
|
|
|
|
2019-12-08 19:02:59 +00:00
|
|
|
/** @var \Pterodactyl\Models\User $response */
|
|
|
|
$response = $this->repository->update($user->id, $data);
|
2017-12-03 20:00:47 +00:00
|
|
|
|
2019-12-08 19:02:59 +00:00
|
|
|
return $response;
|
2017-08-05 00:11:41 +00:00
|
|
|
}
|
|
|
|
}
|