Files
panel/app/Services/Users/UserUpdateService.php
Dane Everitt 0e74f3aade Improve SFTP session revocation to cover password changes and account deletion (#5568)
This expands upon previous work done to better disconnect users from
SFTP when different events occur within Pterodactyl. This new logic also
accounts for password changes and their account being deleted entirely
from the system.

These events now trigger background jobs that will reach out to every
node they are associated with to ensure they're disconnected if
currently connected.
2026-02-14 10:51:26 -08:00

43 lines
939 B
PHP

<?php
namespace Pterodactyl\Services\Users;
use Pterodactyl\Models\User;
use Illuminate\Contracts\Hashing\Hasher;
use Pterodactyl\Events\User\PasswordChanged;
use Pterodactyl\Traits\Services\HasUserLevels;
class UserUpdateService
{
use HasUserLevels;
/**
* UserUpdateService constructor.
*/
public function __construct(private Hasher $hasher)
{
}
/**
* Update the user model instance and return the updated model.
*
* @throws \Throwable
*/
public function handle(User $user, array $data): User
{
if (!empty(array_get($data, 'password'))) {
$data['password'] = $this->hasher->make($data['password']);
} else {
unset($data['password']);
}
$user->forceFill($data)->saveOrFail();
if (isset($data['password'])) {
PasswordChanged::dispatch($user);
}
return $user->refresh();
}
}