From 1075cc0de4a39cc3023a79ecb92287237bf72c20 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 6 Nov 2024 18:43:35 +1100 Subject: [PATCH] Fix auth controllers for laravel 11 --- .../Auth/ConfirmPasswordController.php | 5 +- .../Auth/ForgotPasswordController.php | 3 +- app/Http/Controllers/Auth/LoginController.php | 58 +++++++++---------- .../Controllers/Auth/RegisterController.php | 3 +- .../Auth/ResetPasswordController.php | 16 +---- .../Auth/VerificationController.php | 6 +- app/Http/Controllers/Controller.php | 10 ++-- .../views/auth/passwords/email.blade.php | 2 +- .../views/auth/passwords/reset.blade.php | 2 +- 9 files changed, 46 insertions(+), 59 deletions(-) diff --git a/app/Http/Controllers/Auth/ConfirmPasswordController.php b/app/Http/Controllers/Auth/ConfirmPasswordController.php index 138c1f0..413ec48 100644 --- a/app/Http/Controllers/Auth/ConfirmPasswordController.php +++ b/app/Http/Controllers/Auth/ConfirmPasswordController.php @@ -2,10 +2,9 @@ namespace App\Http\Controllers\Auth; -use App\Http\Controllers\Controller; -use App\Providers\RouteServiceProvider; use Illuminate\Foundation\Auth\ConfirmsPasswords; +use App\Http\Controllers\Controller; class ConfirmPasswordController extends Controller { /* @@ -26,7 +25,7 @@ class ConfirmPasswordController extends Controller * * @var string */ - protected $redirectTo = RouteServiceProvider::HOME; + protected $redirectTo = '/'; /** * Create a new controller instance. diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php index 984b684..663f5b0 100644 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -2,11 +2,12 @@ namespace App\Http\Controllers\Auth; -use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\SendsPasswordResetEmails; use Illuminate\Http\Request; use Illuminate\Support\Facades\Password; +use App\Http\Controllers\Controller; + class ForgotPasswordController extends Controller { /* diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 499f0ce..5d2683e 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -8,7 +8,6 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use App\Http\Controllers\Controller; -use App\Providers\RouteServiceProvider; class LoginController extends Controller { @@ -30,7 +29,7 @@ class LoginController extends Controller * * @var string */ - protected $redirectTo = RouteServiceProvider::HOME; + protected $redirectTo = '/'; /** * Create a new controller instance. @@ -39,40 +38,41 @@ class LoginController extends Controller */ public function __construct() { - $this->middleware('guest') - ->except('logout'); + $this->middleware('guest')->except('logout'); + $this->middleware('auth')->only('logout'); } - public function login(Request $request) - { - $this->validateLogin($request); + public function login(Request $request) + { + $this->validateLogin($request); - if (Auth::attempt(array_merge($this->credentials($request),['active'=>TRUE]),TRUE)) { - $request->session()->regenerate(); + if (Auth::attempt(array_merge($this->credentials($request),['active'=>TRUE]),TRUE)) { + $request->session()->regenerate(); - return $this->sendLoginResponse($request); - } + return $this->sendLoginResponse($request); + } - return $this->sendFailedLoginResponse($request); - } + return $this->sendFailedLoginResponse($request); + } - protected function authenticated(Request $request, $user) - { - $user->last_on = Carbon::now(); - $user->save(); - } + // Record our last logged in time + protected function authenticated(Request $request, $user) + { + $user->last_on = Carbon::now(); + $user->save(); + } - /** - * Show our themed login page - */ - public function showLoginForm() - { - $login_note = ''; + /** + * Show our themed login page + */ + public function showLoginForm() + { + $login_note = ''; - if (file_exists('login_note.txt')) - $login_note = file_get_contents('login_note.txt'); + if (file_exists('login_note.txt')) + $login_note = file_get_contents('login_note.txt'); - return view('auth.login') - ->with('login_note',$login_note); - } + return view('auth.login') + ->with('login_note',$login_note); + } } diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 6b194fc..0531ea0 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -7,7 +7,6 @@ use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; use App\Http\Controllers\Controller; -use App\Providers\RouteServiceProvider; use App\Models\User; class RegisterController extends Controller @@ -30,7 +29,7 @@ class RegisterController extends Controller * * @var string */ - protected $redirectTo = RouteServiceProvider::HOME; + protected $redirectTo = '/'; /** * Create a new controller instance. diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index 7ff36e2..e9cae75 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -2,10 +2,10 @@ namespace App\Http\Controllers\Auth; -use App\Http\Controllers\Controller; -use App\Providers\RouteServiceProvider; use Illuminate\Foundation\Auth\ResetsPasswords; +use App\Http\Controllers\Controller; + class ResetPasswordController extends Controller { /* @@ -26,15 +26,5 @@ class ResetPasswordController extends Controller * * @var string */ - protected $redirectTo = RouteServiceProvider::HOME; - - /** - * Create a new controller instance. - * - * @return void - */ - public function __construct() - { - $this->middleware('guest'); - } + protected $redirectTo = '/'; } diff --git a/app/Http/Controllers/Auth/VerificationController.php b/app/Http/Controllers/Auth/VerificationController.php index 5e749af..d2c6426 100644 --- a/app/Http/Controllers/Auth/VerificationController.php +++ b/app/Http/Controllers/Auth/VerificationController.php @@ -2,10 +2,10 @@ namespace App\Http\Controllers\Auth; -use App\Http\Controllers\Controller; -use App\Providers\RouteServiceProvider; use Illuminate\Foundation\Auth\VerifiesEmails; +use App\Http\Controllers\Controller; + class VerificationController extends Controller { /* @@ -26,7 +26,7 @@ class VerificationController extends Controller * * @var string */ - protected $redirectTo = RouteServiceProvider::HOME; + protected $redirectTo = '/'; /** * Create a new controller instance. diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 03e02a2..4eca382 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -2,12 +2,10 @@ namespace App\Http\Controllers; -use Illuminate\Foundation\Bus\DispatchesJobs; -use Illuminate\Routing\Controller as BaseController; -use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; +use Illuminate\Foundation\Validation\ValidatesRequests; -class Controller extends BaseController +abstract class Controller extends \Illuminate\Routing\Controller { - use AuthorizesRequests, DispatchesJobs, ValidatesRequests; -} + use AuthorizesRequests,ValidatesRequests; +} \ No newline at end of file diff --git a/resources/views/auth/passwords/email.blade.php b/resources/views/auth/passwords/email.blade.php index 1af14bf..3fffb86 100644 --- a/resources/views/auth/passwords/email.blade.php +++ b/resources/views/auth/passwords/email.blade.php @@ -5,7 +5,7 @@ @endsection @section('content') - @includeWhen(session()->has('success'),'widgets.success-row',['msg'=>session()->get('success')]) + @includeWhen(session()->has('status'),'widgets.success-row',['msg'=>session()->pull('status')])
@csrf diff --git a/resources/views/auth/passwords/reset.blade.php b/resources/views/auth/passwords/reset.blade.php index 4159208..61bac58 100644 --- a/resources/views/auth/passwords/reset.blade.php +++ b/resources/views/auth/passwords/reset.blade.php @@ -5,7 +5,7 @@ @endsection @section('content') - @includeWhen(session()->has('status') || true,'widgets.success-row',['msg'=>session()->get('status')]) + @includeWhen(session()->has('status'),'widgets.success-row',['msg'=>session()->pull('status')]) @csrf