0

私のアプリケーションでは、最初にユーザー名とパスワード(どちらもデータベースフィールド)でユーザー認証を双方向でチェックする必要があります。cakephpはすでにこれを提供しています。

  $this->Auth->fields = array(
        'username' => 'username', 
        'password' => 'password'
        );

今、私の必要なのは、最初のケースでユーザーが認証できない場合、usernameとforgot_password(両方ともデータベースフィールド)のユーザーデータをチェックして、Authコンポーネントフィールドをどのように使用できるかを確認することです。私が試してみました :

else
{
$this->Auth->fields = array(
        'username' => 'username', 
        'password' => 'forgot_password'
        );
$this->Auth->login();       
}

しかし、これはうまくいきませんでした..他の方法はありますか?他の場合と同様に、両方のタイプのクロスチェック条件が必要です。

4

1 に答える 1

1

を使用する必要があります$this->Auth->constructAuthenticate();

<?php
function login()
{       
    if ($this->request->is('post'))
    {
        if (!$this->Auth->login())
        {
            $this->Auth->authenticate = array('Form' => array('fields' => array('username' => 'username',
                                                'password' => 'forgot_password')));
            $this->Auth->constructAuthenticate();
            if ($this->Auth->login())
            {
                //Your message here
                //redirect to further pages
            }
            else
            {
                //redirect to login page
            }
        }
    }
}
于 2012-08-24T12:51:27.260 に答える