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

60 lines
1.5 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.
*
2019-09-05 21:32:57 -07:00
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
* @param \Pterodactyl\Repositories\Eloquent\UserRepository $repository
2017-08-04 19:11:41 -05:00
*/
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
*
* @param \Pterodactyl\Models\User $user
2019-09-05 21:32:57 -07:00
* @param array $data
* @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
{
2018-02-07 21:13:40 -06: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
}
}