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;
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* UpdateService constructor.
|
|
|
|
*/
|
2021-08-16 00:37:12 +00:00
|
|
|
public function __construct(Hasher $hasher)
|
2019-12-08 19:02:59 +00:00
|
|
|
{
|
2017-08-05 00:11:41 +00:00
|
|
|
$this->hasher = $hasher;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-08-16 00:37:12 +00:00
|
|
|
* Update the user model instance and return the updated model.
|
2017-08-05 00:11:41 +00:00
|
|
|
*
|
2021-08-16 00:37:12 +00:00
|
|
|
* @throws \Throwable
|
2017-08-05 00:11:41 +00:00
|
|
|
*/
|
2021-08-16 00:37:12 +00:00
|
|
|
public function handle(User $user, array $data): User
|
2017-08-05 00:11:41 +00:00
|
|
|
{
|
2021-01-23 20:33:34 +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
|
|
|
}
|
|
|
|
|
2021-08-16 00:37:12 +00:00
|
|
|
$user->forceFill($data)->saveOrFail();
|
2017-12-03 20:00:47 +00:00
|
|
|
|
2021-08-16 00:37:12 +00:00
|
|
|
return $user->refresh();
|
2017-08-05 00:11:41 +00:00
|
|
|
}
|
|
|
|
}
|