middleware('guest')->except('logout'); $this->middleware('auth')->only('logout'); } /** * Show the application login form. */ public function show(): View { return view('auth.login', [ 'socialProviders' => config('auth.social.providers'), ]); } public function login(LoginRequest $request, SessionRepository $sessions): Response|RedirectResponse { // In case that request throttling is enabled, we have to check if user can perform this request. // We'll key this by the username and the IP address of the client making these requests into this application. $throttles = (bool) setting('throttle_enabled'); //Redirect URL that can be passed as hidden field. $to = $request->has('to') ? '?to=' . $request->get('to') : ''; if ($throttles && $this->hasTooManyLoginAttempts($request)) { return $this->sendLockoutResponse($request); } $credentials = $request->getCredentials(); if (! Auth::validate($credentials)) { // If the login attempt was unsuccessful we will increment the number of attempts // to log in and redirect the user back to the login form. Of course, when this // user surpasses their maximum number of attempts they will get locked out. if ($throttles) { $this->incrementLoginAttempts($request); } return redirect()->to('login' . $to) ->withErrors(trans('auth.failed')); } $user = Auth::getProvider()->retrieveByCredentials($credentials); if ($user->isBanned()) { return redirect()->to('login' . $to) ->withErrors(trans('auth.banned')); } $maxSessions = setting('max_active_sessions'); if ($maxSessions && $sessions->getActiveSessionsCount($user->id) >= $maxSessions) { return redirect()->to('login' . $to) ->withErrors(trans('auth.max_sessions_reached')); } Auth::login($user, setting('remember_me') && $request->get('remember')); return $this->authenticated($request, $throttles, $user); } /** * Send the response after the user was authenticated. */ protected function authenticated( Request $request, bool $throttles, BaseAuthenticatable $user, ): Response|RedirectResponse { if ($throttles) { $this->clearLoginAttempts($request); } $redirectPage = $request->get('to'); if (setting('2fa.enabled') && $user->twoFactorEnabled()) { return $this->logoutAndRedirectToTokenPage($request, $user, $redirectPage); } event(new LoggedIn); if ($redirectPage) { return redirect()->to($redirectPage); } // Reindirizza in base al ruolo if ($user->hasRole('Admin')) { return redirect()->to('userarea/import_xls.php'); } elseif ($user->hasRole('User')) { return redirect()->to('userarea/import_xls.php'); } // Se il ruolo non รจ specificato, reindirizza alla home predefinita return redirect()->intended('/'); } protected function logoutAndRedirectToTokenPage(Request $request, $user, ?string $redirectPage): RedirectResponse { Auth::logout(); $request->session()->put('auth.2fa.id', $user->id); if ($redirectPage) { $request->session()->put('auth.redirect_to', $redirectPage); } return redirect()->route('auth.token'); } /** * Log the user out of the application. */ public function logout(): RedirectResponse { event(new LoggedOut); Auth::logout(); return redirect('login'); } }