不能使用电子邮件作为登录cakephp

时间:2014-08-05 00:13:37

标签: cakephp cakephp-2.3

我在appcontroller登录时无法验证用户身份。我以非管理员角色登录,但我仍然可以通过。 。事实上,我没有得到任何错误,没有出现调试值,所以isAuthorized($ user)不工作。使用相同的代码没有电子邮件,并在另一个网站使用用户名,它工作正常。我查看了文档中的代码,实际上看不出问题。 users表中的字段包含角色,电子邮件和密码。由于相同的代码在其他地方没有用于用户名的电子邮件,因此我无法做什么,因为我检查了如何在$ components中添加电子邮件作为用户名。

我有一个名为teacher的角色的用户,它总是在不应该登录时启用,并且我启用了简单的密码。我检查了数据库中的电子邮件和角色值,所有内容都符合预期。

http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html

 public $components = array(
     "Email",
    'Session',
    'Auth' => array(
        'loginRedirect' => array('controller' => 'users', 'action' => 'dashboard'),
        'logoutRedirect' => array('controller' => 'users','action' => 'login'  ),
          'authenticate' => array( 'Form' => array('fields' => array('username' => 'email', 'password' => 'password'),
         'authorize' => array('Controller') // Added this line    
    )))
);


        public function isAuthorized($user) {
            // Admin can access every action
            debug($user['role']); //// NO output
            debug("asdddddddddddddddddddddddddd");//// NO output

            if (isset($user['role']) && $user['role'] === 'admin') {
                return true;
            }

            // Default deny
            return false;
        } 

0 个答案:

没有答案