mok*_*okk 6 php redirect login laravel
当我想从我的网站共享页面网址时mysite.com/page1#foo=bar,或者想要在我退出时访问此页面时,我会被重定向到login表单,因为page1路由在auth middleware.
我的问题是,在我成功登录后,我被重定向到mysite.com/page1,我丢失了哈希值.
(哈希值也不保留/login)
哈维尔提供什么简单的方法来保持哈希?由于散列没有发送到服务器,我有点怀疑,但也许有些东西我错过了某个地方!
否则我需要覆盖登录,也许用JS读取哈希并以某种方式在登录后重定向重新注入它,但是如果有一个简单的方法,我很想避免这样做:)
感谢 Mruf 的指导,我终于弄清了这件事的真相。不确定这是最好的实现,但它似乎有效。
基本上,我按照 Mruf 建议的形式插入哈希值,然后扩展该handleUserWasAuthenticated函数AuthController
登录.blade.php
<script type="text/javascript" >
$( document ).ready(function() {
$('.urlHash').val(window.location.hash);
});
</script>
<form id="login-form" role="form" method="POST" action="{{ url('/login') }}">
<input type="hidden" class="form-control urlHash" name="urlHash" value="">
....
</form>
Run Code Online (Sandbox Code Playgroud)
AuthController.php
protected function handleUserWasAuthenticated(Request $request, $throttles)
{
if ($throttles) {
$this->clearLoginAttempts($request);
}
if (method_exists($this, 'authenticated')) {
return $this->authenticated($request, Auth::guard($this->getGuard())->user());
}
// old code: return redirect()->intended($this->redirectPath());
$newRequest = redirect()->intended($this->redirectPath());
$newRequest->setTargetUrl($newRequest->getTargetUrl() . $request->urlHash);
return $newRequest;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1290 次 |
| 最近记录: |