I'm trying to override the authenticated method in the Login Controller but somehow it isn't working. I just tried to simply dd(); but still it doesn't work.
Below is my function code:
public function authenticated(Request $request, $user)
{
dd("hi");
}
What I actually wish to do is as below, but just for simplicity sake, I have dd(); in the function.
public function authenticated(Request $request, $user)
{
if (!$user->verified) {
auth()->logout();
return back()->with('warning', 'You need to confirm your account. We have sent you an activation code, please check your email.');
}
return redirect()->intended($this->redirectPath());
}
Whole controller:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use App\Mail\WelcomeMail;
use Illuminate\Support\Facades\Mail;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function login(Request $request)
{
if (Auth::attempt(['email' => $request->email, 'password' => $request->password, 'isActive' => '1']))
{
return view('homepage');
}
else
{
return $this->sendFailedLoginResponse($request, 'auth.failed_status');
}
}
protected function authenticated(Request $request, $user)
{
dd("HI");
// auth()->logout();
return back()->with('warning', 'You need to confirm your account. We have sent you an activation code, please check your email.');
// if(!$user->verified)
// {
// auth()->logout();
// // Auth::logout();
// // \Auth::guard('web')->logout();
// // added logout here
// return back()->with('warning', 'You need to confirm your account. We have sent you an activation code, please check your email.');
// }
// return redirect()->intended($this->redirectPath());
}
}
Kindly ignore the extra commented code in the authenticated function in the controller.