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

これを試して:

[1] 末尾のスラッシュ (/) を削除します。

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

[2] それでも成功しない場合は、router ステートメント (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 に答える
0

私が見つけた答えは、正しいかどうかに関係なく、変更方法について誰かが提案している場合はコメントしてください。

私はスカイウォーカーの提案を受けて、IDが最初になるようにパラメータを切り替えました。

public function reset($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 に答える