I do not recognize the metoo authenticate Laravel 5.4

1

Using the latest version I get this little problem, in the documentation says that you have to add this method to the controller to authenticate (This in the Login Controller)

public function authenticate()
{
    if (Auth::attempt(['email' => $email, 'password' => $password])) {
        // Authentication passed...
        return redirect()->intended('dashboard');
    }
}

Another thing I use to authenticate is the username instead of the email and change the values to:

public function authenticate(){
    if (Auth::attempt(['username' => $username, 'password' => $password])) {
        // Authentication passed...
        return redirect()->route('blog.index');
    }
}

And when you log in you send me the index directly, try to make a dd of $ email and simply log in and go to the index, as if you were not authenticate

I have in my LoginController

public function authenticate(){
    if (Auth::attempt(['username' => $username, 'password' => $password, 'activo' => 1],$remember)) {
        return redirect()->login('index');
    }else{
        return redirect()->route('debeconfirmar');
    }
}

If the user enters their data well, but also confirm their account will send it to the index is your account is active, but if the user entered your account with the correct data but does not confirm the email immediately send it to a page who will inform you of the process to confirm your account.

The problem is that if the user enters the correct data and is not 'active' he / she does the login in the same way and goes to the index page

    
asked by Luis Morales 03.04.2017 в 00:08
source

1 answer

1

You are misreading the documentation, the name of the method authenticate() is just an example, you can call the method as you want, what the documentation says you should keep in mind is preferably use the Facade Auth and the method attempt() , by default Laravel calls the method login() of the AuthenticatesUsers trait:

if (Auth::attempt(['email' => $email, 'password' => $password])) {
   // Authentication passed...
   return redirect()->intended('dashboard');
}

The Laravel code of the attempt() method:

/**
 * Attempt to authenticate a user using the given credentials.
 *
 * @param  array  $credentials
 * @param  bool   $remember
 * @return bool
 */
public function attempt(array $credentials = [], $remember = false)
{
    $this->fireAttemptEvent($credentials, $remember);

    $this->lastAttempted = $user = $this->provider->retrieveByCredentials($credentials);

    // If an implementation of UserInterface was returned, we'll ask the provider
    // to validate the user against the given credentials, and if they are in
    // fact valid we'll log the users into the application and return true.
    if ($this->hasValidCredentials($user, $credentials)) {
        $this->login($user, $remember);

        return true;
    }

    // If the authentication attempt fails we will fire an event so that the user
    // may be notified of any suspicious attempts to access their account from
    // an unrecognized user. A developer may listen to this event as needed.
    $this->fireFailedEvent($user, $credentials);

    return false;
}

More information in the Laravel code: link

    
answered by 03.04.2017 в 00:34