cakephp - Undefined index: token Error -
i using github repository code here: https://github.com/hunzinker/cakephp-auth-forgot-password
i have used following function in userscontroller.php
. error undefined index: token on line has comment before it. should change?
/** * allow user reset password if $token valid. * @return */ function reset_password_token($reset_password_token = null) { if (empty($this->data)) { $this->data = $this->user->findbyresetpasswordtoken($reset_password_token); if (!empty($this->data['user']['reset_password_token']) && !empty($this->data['user']['token_created_at']) && $this->__validtoken($this->data['user']['token_created_at']) ) { $this->data['user']['id'] = null; $_session['token'] = $reset_password_token; } else { $this->session->setflash( 'the password reset request has either expired or invalid.' ); $this->redirect('/users/login'); } } else { //error on next line here undefined index: token if ($this->data['user']['reset_password_token'] != $_session['token']) { $this->session->setflash( 'the password reset request has either expired or invalid.' ); $this->redirect('/users/login'); } $user = $this->user->findbyresetpasswordtoken( $this->data['user']['reset_password_token'] ); $this->user->id = $user['user']['id']; if ($this->user->save($this->data, array('validate' => 'only'))) { $this->data['user']['reset_password_token'] = $this->data['user']['token_created_at'] = null; if ($this->user->save($this->data) && $this->__sendpasswordchangedemail($user['user']['id']) ) { unset($_session['token']); $this->session->setflash( 'your password changed successfully. please login continue.' ); $this->redirect('/users/login'); } } } }
you need sure $_session contains index, should update in order sure exists:
by this:
if (!isset($_session['token']) || $this->data['user']['reset_password_token'] != $_session['token']) { $this->session->setflash( 'the password reset request has either expired or invalid.' ); $this->redirect('/users/login'); }
Comments
Post a Comment