88use Auth ;
99
1010use Pterodactyl \Http \Controllers \Controller ;
11+ use PragmaRX \Google2FA \Google2FA ;
1112use Illuminate \Http \Request ;
1213use Illuminate \Foundation \Auth \ThrottlesLogins ;
1314use Illuminate \Foundation \Auth \AuthenticatesAndRegistersUsers ;
@@ -27,6 +28,73 @@ class AuthController extends Controller
2728
2829 use AuthenticatesAndRegistersUsers, ThrottlesLogins;
2930
31+ /**
32+ * Handle a login request to the application.
33+ *
34+ * @param \Illuminate\Http\Request $request
35+ * @return \Illuminate\Http\Response
36+ */
37+ public function postLogin (Request $ request )
38+ {
39+ $ this ->validate ($ request , [
40+ $ this ->loginUsername () => 'required ' , 'password ' => 'required ' ,
41+ ]);
42+
43+ $ throttles = $ this ->isUsingThrottlesLoginsTrait ();
44+
45+ if ($ throttles && $ this ->hasTooManyLoginAttempts ($ request )) {
46+ return $ this ->sendLockoutResponse ($ request );
47+ }
48+
49+ $ credentials = $ this ->getCredentials ($ request );
50+
51+ if (Auth::attempt ($ credentials , $ request ->has ('remember ' ))) {
52+ if (User::select ('id ' )->where ('email ' , $ request ->input ('email ' ))->where ('use_totp ' , 1 )->exists ()) {
53+ $ validator = Validator::make ($ request ->all (), [
54+ 'totp_token ' => 'required|numeric '
55+ ]);
56+
57+ if ($ validator ->fails ()) {
58+ Auth::logout ();
59+ return redirect ('auth/login ' )->withErrors ($ validator )->withInput ();
60+ }
61+
62+ $ google2fa = new Google2FA ();
63+
64+ if ($ google2fa ->verifyKey (User::where ('email ' , $ request ->input ('email ' ))->first ()->totp_secret , $ request ->input ('totp_token ' ))) {
65+ return $ this ->handleUserWasAuthenticated ($ request , $ throttles );
66+ } else {
67+ Auth::logout ();
68+ $ validator ->errors ()->add ('field ' , trans ('validation.welcome ' ));
69+ return redirect ('auth/login ' )->withErrors ($ validator )->withInput ();
70+ }
71+ } else {
72+ return $ this ->handleUserWasAuthenticated ($ request , $ throttles );
73+ }
74+ }
75+
76+ if ($ throttles ) {
77+ $ this ->incrementLoginAttempts ($ request );
78+ }
79+
80+ return redirect ($ this ->loginPath ())
81+ ->withInput ($ request ->only ($ this ->loginUsername (), 'remember ' ))
82+ ->withErrors ([
83+ $ this ->loginUsername () => $ this ->getFailedLoginMessage (),
84+ ]);
85+ }
86+
87+ /**
88+ * Check if the provided user has TOTP enabled.
89+ *
90+ * @param \Illuminate\Http\Request $request
91+ * @return \Illuminate\Http\Response
92+ */
93+ public function checkTotp (Request $ request )
94+ {
95+ return response ()->json (User::select ('id ' )->where ('email ' , $ request ->input ('email ' ))->where ('use_totp ' , 1 )->first ());
96+ }
97+
3098 /**
3199 * Post-Authentication redirect location.
32100 *
0 commit comments