2018-06-06 06:00:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Client;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
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-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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AccountController constructor.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Services\Users\UserUpdateService $updateService
|
|
|
|
*/
|
|
|
|
public function __construct(UserUpdateService $updateService)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->updateService = $updateService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the authenticated user's email address if their password matches.
|
|
|
|
*
|
|
|
|
* @param UpdateEmailRequest $request
|
|
|
|
* @return array
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
|
|
|
public function updateEmail(UpdateEmailRequest $request): array
|
|
|
|
{
|
|
|
|
$updated = $this->updateService->handle($request->user(), [
|
|
|
|
'email' => $request->input('email'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $this->fractal->item($updated->get('model'))
|
|
|
|
->transformWith($this->getTransformer(AccountTransformer::class))
|
|
|
|
->toArray();
|
|
|
|
}
|
2018-06-06 06:00:01 +00:00
|
|
|
}
|