0

在我的应用程序中,我需要首先通过用户名和密码(都是数据库字段)通过两种方式检查用户身份验证,cake php 已经通过

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

现在我需要的是,如果在第一种情况下用户无法进行身份验证,然后检查用户名和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 回答