1
votes

I am using the auth feature provided by Laravel 5 and trying to login with valid credentials but it is throwing me invalid user error continuously.

Here is my postLogin.

   public function postLogin(Request $request)
   {
    $this->validate($request, [
        'email' => 'required|email', 'password' => 'required',
    ]);

    $credentials = $request->only('email', 'password');
    if ($this->auth->attempt($credentials, $request->has('remember')))
    {
        if($this->auth->attempt(['active' => 1]))
        {
           return redirect()->intended($this->redirectPath());
        }
        else
        {
            return redirect('aut.reset');
        }

    }

    return redirect()->back()
                ->withInput($request->only('email', 'remember'))
                ->withErrors([
                    'email' => $this->getFailedLoginMesssage(),
                ]);
}

My Model contains username, email, password, active, client_code fields.

1

1 Answers

0
votes

You are attempting two times, use this code instead:

$creds = ['email' => $request->get('email'),
          'password' => $request->get('email'),
          'active' => 1]; //your custom parameters
          
if ($this->auth->attempt($credentials, $request->has('remember')))
{
    return redirect()->intended($this->redirectPath());

}

Next time read manual its in there...

Authenticating A User With Conditions

You also may add extra conditions to the authentication query:

if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1]))
{
    // The user is active, not suspended, and exists.
}