Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Http/Controllers/Auth/LoginController.php
10284 views
1
<?php
2
3
namespace Pterodactyl\Http\Controllers\Auth;
4
5
use Carbon\CarbonImmutable;
6
use Illuminate\Support\Str;
7
use Illuminate\Http\Request;
8
use Pterodactyl\Models\User;
9
use Illuminate\Http\JsonResponse;
10
use Pterodactyl\Facades\Activity;
11
use Illuminate\Contracts\View\View;
12
use Illuminate\Database\Eloquent\ModelNotFoundException;
13
14
class LoginController extends AbstractLoginController
15
{
16
/**
17
* Handle all incoming requests for the authentication routes and render the
18
* base authentication view component. React will take over at this point and
19
* turn the login area into an SPA.
20
*/
21
public function index(): View
22
{
23
return view('templates/auth.core');
24
}
25
26
/**
27
* Handle a login request to the application.
28
*
29
* @throws \Pterodactyl\Exceptions\DisplayException
30
* @throws \Illuminate\Validation\ValidationException
31
*/
32
public function login(Request $request): JsonResponse
33
{
34
if ($this->hasTooManyLoginAttempts($request)) {
35
$this->fireLockoutEvent($request);
36
$this->sendLockoutResponse($request);
37
}
38
39
try {
40
$username = $request->input('user');
41
42
/** @var User $user */
43
$user = User::query()->where($this->getField($username), $username)->firstOrFail();
44
} catch (ModelNotFoundException) {
45
$this->sendFailedLoginResponse($request);
46
}
47
48
// Ensure that the account is using a valid username and password before trying to
49
// continue. Previously this was handled in the 2FA checkpoint, however that has
50
// a flaw in which you can discover if an account exists simply by seeing if you
51
// can proceed to the next step in the login process.
52
if (!password_verify($request->input('password'), $user->password)) {
53
$this->sendFailedLoginResponse($request, $user);
54
}
55
56
if (!$user->use_totp) {
57
return $this->sendLoginResponse($user, $request);
58
}
59
60
Activity::event('auth:checkpoint')->withRequestMetadata()->subject($user)->log();
61
62
$request->session()->put('auth_confirmation_token', [
63
'user_id' => $user->id,
64
'token_value' => $token = Str::random(64),
65
'expires_at' => CarbonImmutable::now()->addMinutes(5),
66
]);
67
68
return new JsonResponse([
69
'data' => [
70
'complete' => false,
71
'confirmation_token' => $token,
72
],
73
]);
74
}
75
}
76
77