2017-08-05 00:11:41 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-08-05 00:11:41 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-08-05 00:11:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Users;
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Hashing\Hasher;
|
|
|
|
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
|
|
|
|
2017-08-27 20:10:51 +00:00
|
|
|
class UserUpdateService
|
2017-08-05 00:11:41 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Hashing\Hasher
|
|
|
|
*/
|
|
|
|
protected $hasher;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UpdateService constructor.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
|
|
|
|
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
Hasher $hasher,
|
|
|
|
UserRepositoryInterface $repository
|
|
|
|
) {
|
|
|
|
$this->hasher = $hasher;
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the user model instance.
|
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param int $id
|
|
|
|
* @param array $data
|
2017-08-05 00:11:41 +00:00
|
|
|
* @return mixed
|
|
|
|
*
|
|
|
|
* @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
|
|
|
*/
|
|
|
|
public function handle($id, array $data)
|
|
|
|
{
|
|
|
|
if (isset($data['password'])) {
|
|
|
|
$data['password'] = $this->hasher->make($data['password']);
|
|
|
|
}
|
|
|
|
|
2017-08-05 22:23:02 +00:00
|
|
|
return $this->repository->update($id, $data);
|
2017-08-05 00:11:41 +00:00
|
|
|
}
|
|
|
|
}
|