Issue
I just recreated the CMS tutorial to the letter. When not logged in and trying to edit an article I'm redirected to the login page. Success here. After logging in I get redirected to an error page. Why? The redirect back to articles has gone wrong. See below
Link it is redirecting to: http://localhost/test_cms/test_cms/articles/edit/first-post
Link it is supposed to redirect to http://localhost/test_cms/articles/edit/first-post
I worked every file according to the CMS tutorial and can't seem to figure out what is going wrong here.
Login code below:
public function login()
{
$this->Authorization->skipAuthorization();
$this->request->allowMethod(['get', 'post']);
$result = $this->Authentication->getResult();
// regardless of POST or GET, redirect if user is logged in
if ($result->isValid()) {
// redirect to /articles after login success
$redirect = $this->request->getQuery('redirect', [
'controller' => 'Articles',
'action' => 'index',
]);
return $this->redirect($redirect);
}
// display error if user submitted and authentication failed
if ($this->request->is('post') && !$result->isValid()) {
$this->Flash->error(__('Invalid username or password'));
}
}
Error screenshot: https://ibb.co/PjX8435
Solution
I had this issue as well and found a work around. In my UsersController login method, before return $this->redirect($redirect);
, I added this code to strip the extra app name:
if (!is_array($redirect)) {
if (strncmp($redirect, '/myapp', 6) === 0) {
$redirect = substr($redirect, 6);
}
}
Again, this is a workaround.
Answered By - dividedbyzero
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.