2018-06-06 06:00:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Client;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
2018-06-17 23:53:24 +00:00
|
|
|
use Illuminate\Http\Response;
|
2019-12-28 20:07:42 +00:00
|
|
|
use Illuminate\Auth\AuthManager;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
2018-06-12 05:56:57 +00:00
|
|
|
use Pterodactyl\Services\Users\UserUpdateService;
|
2018-06-06 06:00:01 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Client\AccountTransformer;
|
2018-06-12 05:56:57 +00:00
|
|
|
use Pterodactyl\Http\Requests\Api\Client\Account\UpdateEmailRequest;
|
2018-06-17 23:53:24 +00:00
|
|
|
use Pterodactyl\Http\Requests\Api\Client\Account\UpdatePasswordRequest;
|
2018-06-06 06:00:01 +00:00
|
|
|
|
|
|
|
class AccountController extends ClientApiController
|
|
|
|
{
|
2018-06-12 05:56:57 +00:00
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Users\UserUpdateService
|
|
|
|
*/
|
|
|
|
private $updateService;
|
|
|
|
|
2019-12-28 20:07:42 +00:00
|
|
|
/**
|
|
|
|
* @var \Illuminate\Auth\SessionGuard
|
|
|
|
*/
|
|
|
|
private $sessionGuard;
|
|
|
|
|
2018-06-12 05:56:57 +00:00
|
|
|
/**
|
|
|
|
* AccountController constructor.
|
|
|
|
*
|
2019-12-28 20:07:42 +00:00
|
|
|
* @param \Illuminate\Auth\AuthManager $sessionGuard
|
2018-06-12 05:56:57 +00:00
|
|
|
* @param \Pterodactyl\Services\Users\UserUpdateService $updateService
|
|
|
|
*/
|
2019-12-28 20:07:42 +00:00
|
|
|
public function __construct(AuthManager $sessionGuard, UserUpdateService $updateService)
|
2018-06-12 05:56:57 +00:00
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->updateService = $updateService;
|
2019-12-28 20:07:42 +00:00
|
|
|
$this->sessionGuard = $sessionGuard;
|
2018-06-12 05:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Request $request
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-06-06 06:00:01 +00:00
|
|
|
public function index(Request $request): array
|
|
|
|
{
|
|
|
|
return $this->fractal->item($request->user())
|
|
|
|
->transformWith($this->getTransformer(AccountTransformer::class))
|
|
|
|
->toArray();
|
|
|
|
}
|
2018-06-12 05:56:57 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-17 23:53:24 +00:00
|
|
|
* Update the authenticated user's email address.
|
2018-06-12 05:56:57 +00:00
|
|
|
*
|
2018-06-16 21:30:20 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Client\Account\UpdateEmailRequest $request
|
2018-06-17 23:53:24 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
2018-06-12 05:56:57 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
2018-06-17 23:53:24 +00:00
|
|
|
public function updateEmail(UpdateEmailRequest $request): Response
|
2018-06-12 05:56:57 +00:00
|
|
|
{
|
2018-06-17 23:53:24 +00:00
|
|
|
$this->updateService->handle($request->user(), $request->validated());
|
2018-06-12 05:56:57 +00:00
|
|
|
|
2018-06-17 23:53:24 +00:00
|
|
|
return response('', Response::HTTP_CREATED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-28 20:07:42 +00:00
|
|
|
* Update the authenticated user's password. All existing sessions will be logged
|
|
|
|
* out immediately.
|
2018-06-17 23:53:24 +00:00
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Client\Account\UpdatePasswordRequest $request
|
2019-12-28 20:07:42 +00:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2018-06-17 23:53:24 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
2019-12-28 20:07:42 +00:00
|
|
|
public function updatePassword(UpdatePasswordRequest $request): \Illuminate\Http\JsonResponse
|
2018-06-17 23:53:24 +00:00
|
|
|
{
|
|
|
|
$this->updateService->handle($request->user(), $request->validated());
|
|
|
|
|
2019-12-28 20:07:42 +00:00
|
|
|
$this->sessionGuard->logoutOtherDevices($request->input('current_password'));
|
|
|
|
|
|
|
|
return JsonResponse::create([], Response::HTTP_NO_CONTENT);
|
2018-06-12 05:56:57 +00:00
|
|
|
}
|
2018-06-06 06:00:01 +00:00
|
|
|
}
|