我无法得到"记住我"在Laravel上工作

时间:2014-09-02 09:52:25

标签: php laravel remember-me

在我的应用程序中,我使用“记住我”功能进行了登录。当我用“记住我”连接到应用程序时,它会在cookie中创建一个记忆标记。但是,当我测试并关闭导航器时,有没有记住我,它的行为方式相同。

我已阅读Auth::viaRemember(),但我不知道如何使用它。

这是我的登录信息:

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');


}

视图控制器:

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");
        }

}

我的用户模型:

<?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;
    }

}

0 个答案:

没有答案