0

In my application I have made a login with “remember me” functionality. When I connect to the application with “remember me” it creates a remember token in the cookies. However, when I test and close the navigator with and without the remember me it behaves the same way.

I have read about Auth::viaRemember(), but I don’t know how to use it.

Here is my login:

public function postLogin()
{
    $rules = array(
    'email' => 'required|email',
    'password' => 'required',
    );

$validation = Validator::make(Input::all(), $rules);
    if ($validation->fails())
        {
            return Redirect::to('login')->withErrors
            ($validation)->withInput();
        }


$credentials = Input::only('email', 'password');
$remember = (Input::has('remember')) ? true : false  ;

$email = Input::get('email');
$username = DB::table('users')
                    ->where('email','LIKE',$email)
                    ->pluck('email');   

if( is_null($username)){
    Session::flash('message', 'Votre login est invalide'); 
    return Redirect::to('login');
}   

 else if (Auth::attempt($credentials, $remember)) {

 return Redirect::intended('/');
 }

else{Session::flash('message', 'Votre mot de passe est incorrect, veuillez réessayer'); }

 return Redirect::to('login');


}

the view controller:

public function index()
{
        if (Auth::check())
        {   
            $theme = Theme::all();
            $questions = questionList::paginate(10);
            $the = "";
            return View::make('home.home')
            ->with('user',Auth::user())
            ->with('theme', $theme)
            ->with('the' ,  $the)
            ->with('questions',$questions);

        }
        else
        {
            return Redirect::to('login')->with('message',"Vous devez vous connecter d'abord");
        }

}

my user model:

<?php

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('password');

    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->password;
    }

    /**
     * Get the token value for the "remember me" session.
     *
     * @return string
     */
    public function getRememberToken()
    {
        return $this->remember_token;
    }

    /**
     * Set the token value for the "remember me" session.
     *
     * @param  string  $value
     * @return void
     */
    public function setRememberToken($value)
    {
        $this->remember_token = $value;
    }

    /**
     * Get the column name for the "remember me" token.
     *
     * @return string
     */
    public function getRememberTokenName()
    {
        return 'remember_token';
    }

    /**
     * Get the e-mail address where password reminders are sent.
     *
     * @return string
     */
    public function getReminderEmail()
    {
        return $this->email;
    }

}
TRiG
  • 10,148
  • 7
  • 57
  • 107
Ahmed Karmous
  • 373
  • 2
  • 10
  • 25

0 Answers0