%PDF- %PDF-
Direktori : /www/loslex/demo/app/Http/Controllers/Auth/ |
Current File : //www/loslex/demo/app/Http/Controllers/Auth/AuthenticatedSessionController.php |
<?php namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use App\Http\Requests\Auth\LoginRequest; use App\Providers\RouteServiceProvider; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\View\View; use Illuminate\Support\Facades\Log; class AuthenticatedSessionController extends Controller { /** * Display the login view. */ public function create(): View { return view('auth.login'); } /** * Handle an incoming authentication request. */ public function store(LoginRequest $request): RedirectResponse { $request->authenticate(); $request->session()->regenerate(); // check if user is banned if (!$request->user()->is_active) { Log::warning("Banned user {$request->user()->username} attempted to log in."); Auth::guard('web')->logout(); $request->session()->invalidate(); $request->session()->regenerateToken(); return redirect()->intended(route('banned')); } // update last login info in DB $request->user()->update(['last_login' => date('Y-m-d H:i:s')]); Log::info("User {$request->user()->username} logged in.", ['user' => $request->user()->id]); $url = url()->previous(); $route = app('router')->getRoutes($url)->match(app('request')->create($url))->getName(); if ($route == 'login') return redirect()->intended(config('app.homepage')); else return back(); } /** * Destroy an authenticated session. */ public function destroy(Request $request): RedirectResponse { Auth::guard('web')->logout(); $request->session()->invalidate(); $request->session()->regenerateToken(); return redirect('/'); } public function banned(): View { return view('auth.banned'); } }