alert = $alert; $this->creationService = $creationService; $this->deletionService = $deletionService; $this->repository = $repository; $this->translator = $translator; $this->updateService = $updateService; } /** * Display user index page. * * @param \Illuminate\Http\Request $request * @return \Illuminate\View\View */ public function index(Request $request) { $users = $this->repository->search($request->input('query'))->getAllUsersWithCounts(); return view('admin.users.index', ['users' => $users]); } /** * Display new user page. * * @return \Illuminate\View\View */ public function create() { return view('admin.users.new'); } /** * Display user view page. * * @param \Pterodactyl\Models\User $user * @return \Illuminate\View\View */ public function view(User $user) { return view('admin.users.view', ['user' => $user]); } /** * Delete a user from the system. * * @param \Illuminate\Http\Request $request * @param \Pterodactyl\Models\User $user * @return \Illuminate\Http\RedirectResponse * * @throws \Exception * @throws \Pterodactyl\Exceptions\DisplayException */ public function delete(Request $request, User $user) { if ($request->user()->id === $user->id) { throw new DisplayException($this->translator->trans('admin/user.exceptions.user_has_servers')); } $this->deletionService->handle($user); return redirect()->route('admin.users'); } /** * Create a user. * * @param \Pterodactyl\Http\Requests\Admin\UserFormRequest $request * @return \Illuminate\Http\RedirectResponse * * @throws \Exception * @throws \Throwable */ public function store(UserFormRequest $request) { $user = $this->creationService->handle($request->normalize()); $this->alert->success($this->translator->trans('admin/user.notices.account_created'))->flash(); return redirect()->route('admin.users.view', $user->id); } /** * Update a user on the system. * * @param \Pterodactyl\Http\Requests\Admin\UserFormRequest $request * @param \Pterodactyl\Models\User $user * @return \Illuminate\Http\RedirectResponse * * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException */ public function update(UserFormRequest $request, User $user) { $this->updateService->setUserLevel(User::USER_LEVEL_ADMIN); $data = $this->updateService->handle($user, $request->normalize()); if (! empty($data->get('exceptions'))) { foreach ($data->get('exceptions') as $node => $exception) { /** @var \GuzzleHttp\Exception\RequestException $exception */ /** @var \GuzzleHttp\Psr7\Response|null $response */ $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; $message = trans('admin/server.exceptions.daemon_exception', [ 'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(), ]); $this->alert->danger(trans('exceptions.users.node_revocation_failed', [ 'node' => $node, 'error' => $message, 'link' => route('admin.nodes.view', $node), ]))->flash(); } } $this->alert->success($this->translator->trans('admin/user.notices.account_updated'))->flash(); return redirect()->route('admin.users.view', $user->id); } /** * Get a JSON response of users on the system. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Database\Eloquent\Collection */ public function json(Request $request) { return $this->repository->filterUsersByQuery($request->input('q')); } }