登录后重定向到引荐来源不起作用 [英] Redirect to referrer not working after Login

查看:95
本文介绍了登录后重定向到引荐来源不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

登录用户后,我想将他们重定向回他们的来源,但在CakePHP 3.5中无法正常工作。以下是帮助我解决此问题的必要信息。

After logging a user in, I want to redirect them back to where they came from but It's not working properly in CakePHP 3.5. Here are the required info's to help me figure out this problem.

登录(会话超时)时的网址,

URL while login(session time out),

http://dev.scys.com/db/admin?redirect=%2Fadmin%2Fstatuses

这是我的Auth配置,

This is my Auth config,

$this->loadComponent('Auth', [
            'loginAction' => ['controller' => 'Admins', 'action' => 'login'],
            'loginRedirect' => ['controller' => 'Admins', 'action' => 'index'],
            'logoutRedirect' => ['controller' => 'Admins', 'action' => 'login'],
            'unauthorizedRedirect' => $this->referer(),
            'authenticate' => [
                'Form' => [
                    'finder' => 'auth',
                    'userModel' => 'Admins',
                    'fields' => ['username' => 'username', 'password' => 'password']
                ]
            ]

        ]);

在登录方法/操作中

$user = $this->Auth->identify();
            if ($user) {
                $this->Auth->setUser($user);
                return $this->redirect($this->Auth->redirectUrl());
            }




更多积分

More Points

我也尝试过$ this-> redirect($ this-> request-> getQuery('redirect'));

I have also tried $this->redirect($this->request->getQuery('redirect'));

我缺少任何东西还是必须添加才能解决此问题:(

Am I missing anything or something else I have to add to work this out :(

推荐答案

找出我的错误
实际上,我使用的是操作网址,例如

I figured out my mistake, Actually, I was using for action URL like,

$this->Form->create(NULL, ['url'=> ['controller' => 'Admins', 'action' => 'login'],'style'=>'display: block;');

因此,URL变为管理员/登录,并且重定向查询字符串被删除,这就是问题所在发生,因为 $ this-> redirect($ this-> Auth-> redirectUrl()); 找不到任何重定向查询字符串(按照情况1),因此它使用 $ this-> Auth-> config('loginRedirect'); (根据情况2)。

Because of this, the URL became "admins/login" and the redirect query string get removed that's why the problem occurred, because "$this->redirect($this->Auth->redirectUrl());" didn't find any redirect query string(as per the case 1), so it uses $this->Auth->config('loginRedirect');(as per case 2).

然后我通过删除URL键来解决它表单创建选项参数中的值。

Then I solve it by removing the URL key and value from the form create option parameter.

这篇关于登录后重定向到引荐来源不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆