0

我目前正在重置密码,正在通过电子邮件将以下链接发送给用户

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

然后用户转到表单,控制器执行以下操作

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);
        }
    }

问题是当我提交它时会出现这样的错误

错误:在此服务器上找不到请求的地址“/realestateagencyadministration/users/reset/48”。

我该如何处理?

4

2 回答 2

0

我发现的答案是否正确,如果有人对如何更改它有任何建议,请发表评论。

我接受了天行者的建议并切换了参数,以便 id 是第一位的。

公共函数重置($id = null,$resetkey = null){

并更改了我的保存代码

    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);
        }
    } 

我知道它不干净,如果有人知道更好的方法,将不胜感激。

于 2014-04-05T16:10:36.027 回答
0

尝试这个:

[1] 删除尾部斜杠 (/):

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

[2] 如果仍然没有成功,添加路由语句(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
于 2014-04-05T19:20:10.883 回答