2018-04-07 12:35:15 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Auth;
|
|
|
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
use Pterodactyl\Http\Requests\Auth\LoginCheckpointRequest;
|
|
|
|
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
|
|
|
|
|
|
|
class LoginCheckpointController extends AbstractLoginController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle a login where the user is required to provide a TOTP authentication
|
2018-04-07 16:17:51 -05:00
|
|
|
* token. Once a user has reached this stage it is assumed that they have already
|
|
|
|
* provided a valid username and password.
|
2018-04-07 12:35:15 -05:00
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Auth\LoginCheckpointRequest $request
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
*/
|
2018-04-08 15:18:13 -05:00
|
|
|
public function __invoke(LoginCheckpointRequest $request): JsonResponse
|
2018-04-07 12:35:15 -05:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
$cache = $this->cache->pull($request->input('confirmation_token'), []);
|
|
|
|
$user = $this->repository->find(array_get($cache, 'user_id', 0));
|
|
|
|
} catch (RecordNotFoundException $exception) {
|
|
|
|
return $this->sendFailedLoginResponse($request);
|
|
|
|
}
|
|
|
|
|
2018-04-07 16:17:51 -05:00
|
|
|
if (array_get($cache, 'request_ip') !== $request->ip()) {
|
2018-04-07 12:35:15 -05:00
|
|
|
return $this->sendFailedLoginResponse($request, $user);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $this->google2FA->verifyKey(
|
|
|
|
$this->encrypter->decrypt($user->totp_secret),
|
|
|
|
$request->input('authentication_code'),
|
|
|
|
config('pterodactyl.auth.2fa.window')
|
|
|
|
)) {
|
|
|
|
return $this->sendFailedLoginResponse($request, $user);
|
|
|
|
}
|
|
|
|
|
2018-04-07 16:17:51 -05:00
|
|
|
$this->auth->guard()->login($user, true);
|
2018-04-07 12:35:15 -05:00
|
|
|
|
|
|
|
return $this->sendLoginResponse($request);
|
|
|
|
}
|
|
|
|
}
|