Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

请问 Laravel 5.3 中,自带的 Auth 是如何存 remember_token 的?

我稍微改重写了下login方法,最后登陆成功不是 redirect 而是返回了一串 JSON 数据,然后发现,记住登录的时候,只有页面刷新或者有跳转的时候才会生效。也就是 cookie 里还没存 remember_token。
然后看了下找了一圈没找到哪里出发存这个 cookie 的操作的。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

我猜您是为了实现ajax登录的效果,这个是没问题的,因为我就这么实现的。

使用ajax来post表单数据,等到返回json时,Cookie已经写入了,然后新的页面的跳转。

测试地址: https://www.load-page.com/tee... 账号密码 admin 123456

代码也没什么特殊的

$remember = $request->has('remember');
$data = [
    'username' => ''
    'password' => ''
];
if ($this->guard()->attempt(['username' => $data['username'], 'password' => $data['password']], $remember))
{
    $this->clearLoginAttempts($request);
    echo json_encode($this->guard()->user());
}

然后我也看到了 cookie中

clipboard.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...