Files

42 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2026-10-05 18:10:18 -04:00
<?php
declare(strict_types=1);
namespace Pterodactyl\Actions\Users;
use Illuminate\Support\Facades\Auth;
2026-10-11 03:16:44 -04:00
use Illuminate\Support\Str;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Contracts\Users\UpdatesUserPasswords;
use Pterodactyl\Contracts\Users\UpdatesUsers;
2026-10-11 14:23:31 -04:00
use Pterodactyl\Facades\Activity;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Models\User;
final readonly class UpdateUserPassword implements UpdatesUserPasswords
{
public function __construct(private UpdatesUsers $users) {}
public function update(User $user, string $password): User
{
$user = $this->users->update($user, ['password' => $password]);
2026-10-11 03:16:44 -04:00
$user->setRememberToken(Str::random(60));
$user->save();
2026-10-05 18:10:18 -04:00
2026-10-11 14:23:31 -04:00
Activity::event('user:account.password-changed')->subject($user)->log();
2026-10-11 03:16:44 -04:00
// Users changing their own password keep this session. A reset link has no session
// to keep, and is never signed in here: an account with two-factor authentication
// still has to pass its checkpoint.
2026-10-05 18:10:18 -04:00
$guard = Auth::guard(Auth::getDefaultDriver());
2026-10-11 03:16:44 -04:00
$current = $guard->user();
if ($current instanceof User && $current->is($user)) {
$guard->setUser($user);
2026-10-05 18:10:18 -04:00
2026-10-11 03:16:44 -04:00
if (method_exists($guard, 'logoutOtherDevices')) {
$guard->logoutOtherDevices($password);
}
2026-10-05 18:10:18 -04:00
}
return $user;
}
}