Files
pterodactyl-panel/app/Services/Users/UserUpdateService.php
T

55 lines
1.3 KiB
PHP
Raw Normal View History

2017-08-04 19:11:41 -05:00
<?php
namespace Pterodactyl\Services\Users;
use Pterodactyl\Models\User;
2017-08-04 19:11:41 -05:00
use Illuminate\Contracts\Hashing\Hasher;
use Pterodactyl\Traits\Services\HasUserLevels;
use Pterodactyl\Repositories\Eloquent\UserRepository;
2017-08-04 19:11:41 -05:00
class UserUpdateService
2017-08-04 19:11:41 -05:00
{
use HasUserLevels;
2017-08-04 19:11:41 -05:00
/**
* @var \Illuminate\Contracts\Hashing\Hasher
*/
private $hasher;
2017-08-04 19:11:41 -05:00
/**
* @var \Pterodactyl\Repositories\Eloquent\UserRepository
2017-08-04 19:11:41 -05:00
*/
private $repository;
2017-08-04 19:11:41 -05:00
/**
* UpdateService constructor.
*/
public function __construct(Hasher $hasher, UserRepository $repository)
{
2017-08-04 19:11:41 -05:00
$this->hasher = $hasher;
$this->repository = $repository;
}
/**
* Update the user model instance.
2017-08-04 19:11:41 -05:00
*
* @return \Pterodactyl\Models\User
2017-08-04 19:11:41 -05:00
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
2017-08-04 19:11:41 -05:00
*/
public function handle(User $user, array $data)
2017-08-04 19:11:41 -05:00
{
2021-01-23 12:33:34 -08:00
if (!empty(array_get($data, 'password'))) {
2017-08-04 19:11:41 -05:00
$data['password'] = $this->hasher->make($data['password']);
2018-02-07 21:13:40 -06:00
} else {
unset($data['password']);
2017-08-04 19:11:41 -05:00
}
/** @var \Pterodactyl\Models\User $response */
$response = $this->repository->update($user->id, $data);
return $response;
2017-08-04 19:11:41 -05:00
}
}