Question

I am currently doing a reset password of which is sending the following link to a user in an email

 http://localhost/realestateagencyadministration/users/reset/859be257b603ce278c42dca470be642a/48/

Then the user goes to the form and the controller does the following

public function reset($resetkey = null, $id = null) {

        if (!$this->User->exists($id)) {
            throw new NotFoundException(__('Invalid user'));
        }

        $result =$this->User->find('first', array('conditions' => array('User.id' => $id, 'User.resetKey' => "'" . $resetkey . "'")));

        if ($result) {
            $message = __('<b>Please check your reset link</b>');
            $this->Session->setFlash($message);
        }

        if ($this->request->is('post')) {
            if ($this->User->save()) {
                $message = __('Your password has been reset');
                $this->Session->setFlash($message);
            } else {
                $message = __('Something has gone wrong. Please try later or <b>sign up again</b>');
                $this->Session->setFlash($message);
            }
        } 
        else {
            $this->request->data = $this->User->findByIdAndResetkey( $id,  $resetkey );
            $log = $this->User->getDataSource()->getLog(false, false);
            debug($log);
        }
    }

The problem is when I submit it gives an error like so

Error: The requested address '/realestateagencyadministration/users/reset/48' was not found on this server.

How should I handle this?

Was it helpful?

Solution

The answer that I have found be it correct or not and if anyone has suggestions on how it should be altered do comment.

I took skywalker's suggestion and switched around the params so that id is first.

public function reset($id = null,$resetkey = null) {

and changed my save code

    if ($this->request->is(array('post', 'put'))) {                    
        $data = $this->User->findById($id);
        $data['User']['password'] = $this->request->data['User']['password'];
        $data['User']['resetkey'] = '';
        if ($this->User->save($data)) {
            $message = __('Your password has been changed, try logging in with your new password.');
            $this->Session->setFlash($message);
        } else {
            $message = __('Something has gone wrong. Please try again later.');
            $this->Session->setFlash($message);
        }
    } 

I know it isn't clean and if anyone knows a better way it would be gratefully appreciated.

OTHER TIPS

Try this:

[1] Remove trailing slash (/):

http://localhost/realestateagencyadministration
    /users/reset/859be257b603ce278c42dca470be642a/48

[2] If still no success, add router statement (app/Config/routes.php), :

Router::connect('/users/reset/:resetkey/:id',
    array('controller' => 'users', 'action' => 'reset'),
    array('pass' => array('resetkey', 'id'))); // <-- must be in action argument order
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top