viaRemember无法正常工作-Laravel [英] viaRemember not work - laravel
问题描述
Auth ::尝试完美!,但是当您传递第二个参数"true"时,显然并不在乎,或者无法通过viaRemember恢复
Auth :: attempt works perfect, but when you pass the second parameter "true" apparently does not care or does not recover with viaRemember
viaRemember无法正常工作,请检查此
viaRemember fails to work, check this
控制器用户
`$`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
推荐答案
我遇到了相同的障碍,因此查看代码可以看到viaRemember
并非旨在用作检查用户是否使用的函数已通过用户登录的所有方式之一登录到系统.
I have hit the same obstacle, so looking into the code one can see that viaRemember
is not meant to be used as a function to check if the user was logged into the system in one of all the ways a user can be logged in.
'viaRemember'旨在检查用户是否通过"viaRemember" cookie专门登录到系统.
'viaRemember' is meant to check if a user was logged into the system specifically via the `viaRemember' cookie.
从我收集的信息中,可以通过两种方式记住用户的身份验证:
From what I gather, authentication of user is remembered in two ways:
-
一个
via remember
cookie.
将cookie值与users表中的via remember
字段进行比较.
The cookie value is compared to the via remember
field in the users table.
会话cookie.
服务器中使用cookie值从以下网址获取会话: 会话存储.在商店中的会话对象上,附加了数据.中的一个 数据项是连接到会话的用户ID.第一次 创建会话,系统将用户标识附加到数据 的季节.
The cookie value is used in the server to get the session from the session store. On the session object from the store there is data attached. One of the data items is the user id connected to the session. The first time the session was created, the system attached the user id to the data of the season.
在Illuminate\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
函数.
The getUserByRecaller
function is called only if the session cookie authentication did not work.
viaRemember
标志仅在getUserByRecaller
功能中设置. viaRemember
方法只是一个简单的getter方法.
The viaRemember
flag is only set in the getUserByRecaller
function. The viaRemember
method is only a simple getter method.
public function viaRemember()
{
return $this->viaRemember;
}
最后,我们可以使用Auth::check()
进行所有检查,包括viaRemember
检查.它会在Guard类中调用user()
函数.
So in the end, we can use Auth::check()
that does make all the checks including the viaRemember
check. It calls the user()
function in the Guard class.
似乎viaRemember
只是一个指标.您需要执行Auth::check()
类型,这将启动身份验证过程,因此将调用user()函数.
It seems also the viaRemember
is only an indicator. You need to do a type of Auth::check()
the will get the process of authentication started and so the user() function will be called.
这篇关于viaRemember无法正常工作-Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!