nitin7805
nitin7805

Reputation: 203

Laravel remember me functionality with Sentry

I want to create login script using remember me. I am new to laravel, according to my search I found to create remember_token with 255 varchar and set to NULL in my users table and in my User model I create three functions that are.

#User.php

public function getRememberToken()
{
    return $this->remember_token;
}

public function setRememberToken($value)
{
    $this->remember_token = $value;
}

public function getRememberTokenName()
{
    return 'remember_token';
}

becouse I am using Laravel Sentry for authentication thats why in my controller

#AuthController.php

public function postLogin()
{
    $input = Input::all();
    $remember = (Input::has('remember')) ? true : false;
    Sentry::authenticate([
            'email' => $input['email'],
            'password' => $input['password'],
        ], $remember);
    Flash::addSuccess('You have been logged in successfully.');
    return Redirect::intended(URL::route('profile_connect'))->withInput();
}
   catch(Exception $e){
       Flash::addError('That username or password is incorrect.');
       return Redirect::route('auth_login');
}

Now if I do login and select remember me checkbox then login done successfully but my remember_token field in users table still empty(null). Can somebody tell me from where I am wrong and where I need to change. Thanks in advance.

Upvotes: 1

Views: 373

Answers (1)

Dan
Dan

Reputation: 18754

Rather than storing a value in the remember_token field, Sentry's authenticate method sets a cookie if the remember flag is true.

Technically, the login() method is called by authenticate() and sets the cookie.

Here's the relevant code:

public function login(UserInterface $user, $remember = false)
{
    ... (snip)

    if ($remember)
    {
        $this->cookie->forever($toPersist);
    }

}

Upvotes: 1

Related Questions