Path: blob/1.0-develop/app/Http/Controllers/Auth/LoginController.php
10284 views
<?php12namespace Pterodactyl\Http\Controllers\Auth;34use Carbon\CarbonImmutable;5use Illuminate\Support\Str;6use Illuminate\Http\Request;7use Pterodactyl\Models\User;8use Illuminate\Http\JsonResponse;9use Pterodactyl\Facades\Activity;10use Illuminate\Contracts\View\View;11use Illuminate\Database\Eloquent\ModelNotFoundException;1213class LoginController extends AbstractLoginController14{15/**16* Handle all incoming requests for the authentication routes and render the17* base authentication view component. React will take over at this point and18* turn the login area into an SPA.19*/20public function index(): View21{22return view('templates/auth.core');23}2425/**26* Handle a login request to the application.27*28* @throws \Pterodactyl\Exceptions\DisplayException29* @throws \Illuminate\Validation\ValidationException30*/31public function login(Request $request): JsonResponse32{33if ($this->hasTooManyLoginAttempts($request)) {34$this->fireLockoutEvent($request);35$this->sendLockoutResponse($request);36}3738try {39$username = $request->input('user');4041/** @var User $user */42$user = User::query()->where($this->getField($username), $username)->firstOrFail();43} catch (ModelNotFoundException) {44$this->sendFailedLoginResponse($request);45}4647// Ensure that the account is using a valid username and password before trying to48// continue. Previously this was handled in the 2FA checkpoint, however that has49// a flaw in which you can discover if an account exists simply by seeing if you50// can proceed to the next step in the login process.51if (!password_verify($request->input('password'), $user->password)) {52$this->sendFailedLoginResponse($request, $user);53}5455if (!$user->use_totp) {56return $this->sendLoginResponse($user, $request);57}5859Activity::event('auth:checkpoint')->withRequestMetadata()->subject($user)->log();6061$request->session()->put('auth_confirmation_token', [62'user_id' => $user->id,63'token_value' => $token = Str::random(64),64'expires_at' => CarbonImmutable::now()->addMinutes(5),65]);6667return new JsonResponse([68'data' => [69'complete' => false,70'confirmation_token' => $token,71],72]);73}74}757677