mirror of
https://github.com/pterodactyl/panel.git
synced 2026-06-13 18:07:29 -05:00
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.
43 lines
939 B
PHP
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();
|
|
}
|
|
}
|