Authentication 别忘了不要工作-拉雷维尔

Authentication 别忘了不要工作-拉雷维尔,authentication,login,laravel,Authentication,Login,Laravel,Auth::trument工作正常,但当您传递第二个参数“true”时,显然不关心或无法使用ViaMemory恢复 记住,如果失败,请检查此项 控制器用户 `$`userdata = array( 'email' => trim(Input::get('username')), 'password' => trim(Input::get('password')) ); if(Auth::attempt(`$`userdata, true)){ re

Auth::trument工作正常,但当您传递第二个参数“true”时,显然不关心或无法使用ViaMemory恢复

记住,如果失败,请检查此项

控制器用户

`$`userdata = array(
    'email'     => trim(Input::get('username')),
    'password'  => trim(Input::get('password'))
);

if(Auth::attempt(`$`userdata, true)){
    return Redirect::to('/dashboard');
}
查看“仪表板”,始终显示777

@if (Auth::viaRemember())
    {{666}}
@else
    {{777}}
@endif

您的项目似乎在Laravel4.0上,但在Laravel4.1中添加了
vialemember()
!这是意料之中的。

config\session.php
文件中,将
'expire\u on\u close'=false
更改为
true
,一旦关闭并重新启动浏览器,一切都会正常。

我遇到了同样的障碍,因此,查看代码可以看出,
vialemory
并不是用来检查用户是否以所有用户登录方式之一登录系统的功能

“viaRemember”用于检查用户是否专门通过“viaRemember”cookie登录系统

据我所知,用户身份验证有两种方式:

  • 通过记住
    cookie创建

    cookie值通过用户表中的memory
    字段与
    进行比较

  • 会话cookie

    cookie值在服务器中用于从服务器获取会话 会话存储。在存储区的会话对象上附加了数据。其中一个 数据项是连接到会话的用户id。第一次 会话已创建,系统将用户id附加到数据 这是本季的第一季

  • 照明\Auth\Guard
    类中:

    public function user()
    {
        if ($this->loggedOut) return;
    
        // If we have already retrieved the user for the current request we can just
        // return it back immediately. We do not want to pull the user data every
        // request into the method because that would tremendously slow an app.
        if ( ! is_null($this->user))
        {
            return $this->user;
        }
    
        $id = $this->session->get($this->getName());
    
        // First we will try to load the user using the identifier in the session if
        // one exists. Otherwise we will check for a "remember me" cookie in this
        // request, and if one exists, attempt to retrieve the user using that.
        $user = null;
    
        if ( ! is_null($id))
        {
            $user = $this->provider->retrieveByID($id);
        }
    
        // If the user is null, but we decrypt a "recaller" cookie we can attempt to
        // pull the user data on that cookie which serves as a remember cookie on
        // the application. Once we have a user we can return it to the caller.
        $recaller = $this->getRecaller();
    
        if (is_null($user) && ! is_null($recaller))
        {
            $user = $this->getUserByRecaller($recaller);
        }
    
        return $this->user = $user;
    }
    
    仅当会话cookie身份验证不起作用时,才会调用
    getUserByRecaller
    函数

    vialemory
    标志仅在
    getUserByRecaller
    函数中设置。
    vialember
    方法只是一种简单的getter方法

        public function viaRemember()
    {
        return $this->viaRemember;
    }
    
    因此,最后,我们可以使用
    Auth::check()
    进行所有检查,包括
    vialemory
    检查。它调用Guard类中的
    user()
    函数


    似乎
    ViaMemory
    也只是一个指标。您需要执行一种类型的
    Auth::check()
    将启动身份验证过程,因此将调用user()函数

    伙计们,我用的是4.1.22。但它不起作用。请给我一些建议。