Path: blob/1.0-develop/app/Http/Controllers/Api/Client/AccountController.php
10279 views
<?php12namespace Pterodactyl\Http\Controllers\Api\Client;34use Illuminate\Http\Request;5use Illuminate\Http\Response;6use Illuminate\Auth\AuthManager;7use Illuminate\Http\JsonResponse;8use Pterodactyl\Facades\Activity;9use Pterodactyl\Services\Users\UserUpdateService;10use Pterodactyl\Transformers\Api\Client\AccountTransformer;11use Pterodactyl\Http\Requests\Api\Client\Account\UpdateEmailRequest;12use Pterodactyl\Http\Requests\Api\Client\Account\UpdatePasswordRequest;1314class AccountController extends ClientApiController15{16/**17* AccountController constructor.18*/19public function __construct(private AuthManager $manager, private UserUpdateService $updateService)20{21parent::__construct();22}2324public function index(Request $request): array25{26return $this->fractal->item($request->user())27->transformWith($this->getTransformer(AccountTransformer::class))28->toArray();29}3031/**32* Update the authenticated user's email address.33*/34public function updateEmail(UpdateEmailRequest $request): JsonResponse35{36$original = $request->user()->email;37$this->updateService->handle($request->user(), $request->validated());3839if ($original !== $request->input('email')) {40Activity::event('user:account.email-changed')41->property(['old' => $original, 'new' => $request->input('email')])42->log();43}4445return new JsonResponse([], Response::HTTP_NO_CONTENT);46}4748/**49* Update the authenticated user's password. All existing sessions will be logged50* out immediately.51*52* @throws \Throwable53*/54public function updatePassword(UpdatePasswordRequest $request): JsonResponse55{56$user = $this->updateService->handle($request->user(), $request->validated());5758$guard = $this->manager->guard();59// If you do not update the user in the session you'll end up working with a60// cached copy of the user that does not include the updated password. Do this61// to correctly store the new user details in the guard and allow the logout62// other devices functionality to work.63$guard->setUser($user);6465// This method doesn't exist in the stateless Sanctum world.66if (method_exists($guard, 'logoutOtherDevices')) { // @phpstan-ignore function.alreadyNarrowedType67$guard->logoutOtherDevices($request->input('password'));68}6970Activity::event('user:account.password-changed')->log();7172return new JsonResponse([], Response::HTTP_NO_CONTENT);73}74}757677