CakePHP的2.0身份验证登录不工作 [英] CakePHP 2.0 Auth Login not working

查看:110
本文介绍了CakePHP的2.0身份验证登录不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直争取与此一段时间。我有一个CakePHP的2.0应用程序需要验证,由于事实,即它必须在另一种语言,我踩着从用户名和密码公约AUTOMAGIC用户的路程,并提出我自己的数据库表:

I have been fighting with this for awhile. I have a CakePHP 2.0 application that needs Authentication, due to the fact that it must be in another language, I stepped away from the automagic 'User' with 'Username' and 'Password' convention and made my own database table:

utilizatori('id', 'nume', 'parola')

在我的 AppController的我有以下的定义了,如果我正确理解应该覆盖默认的CakePHP协会,使其使用我的新结构:

In my AppController I have the following defined which if I understood correctly should override the default CakePHP associations and make it use my new structure:

class AppController extends Controller {
    var $components = array('Session',
    'Auth' => array('Form' => array(
        'userModel' => 'Utilizator',
        'fields' => array('username' => 'nume', 'password' => 'parola'),
        'loginAction' => array('controller' => 'utilizatori', 'action' => 'login'),
        'loginRedirect' => array('controller' => 'categorii', 'action' => 'admin_index'))));

    function beforeFilter() { }
}

在我的 UtilizatoriController 我有以下登录功能:

In my UtilizatoriController I have the following login function:

function login() 
{
    $this->layout = 'admin'; 
    debug($this->data);
    debug(Security::hash($this->data['Utilizator']['parola']));
    debug($this->Auth->login());
    /*more here but don't think it's important*/

数据调试出现与预期值,让我们presume:

The data debug comes up with the expected values, let's presume:

**data['Utilizator']['nume']** = 'Cosmin'
**data['Utilizator']['parola']** = 'Cosmin'

密码哈希调试产生这也是我手动插入到数据库中,但登录功能返回预期的哈希的

The password hash debug yield the expected hash which I also manually inserted in the database and yet the login function returns false.

我不知道下一步该怎么做任何意见,将AP preciated。
此外,有没有进入什么被发送到一个方法的 $这个 - > Auth->登录()

I'm not sure what to do next and any feedback would be appreciated. Also, is there a way to access what gets sent to $this->Auth->login()?

感谢您

推荐答案

事实证明,后面$这个 - > Auth-)失败的原因>登录(是我的 AuthComponent 里面声明的AppController 。经过一番更多的研究和小得惊人,但乐于助人发表于<一个href=\"http://stackoverflow.com/questions/8996162/how-can-i-use-different-model-for-auth-component-in-cakephp-2-0-4\">How我可以在CakePHP中2.0.4?我回顾我的code使用不同的模型验证组件,现在它似乎是工作。

As it turns out, the reason behind $this->Auth->login() failing was my declaration of the AuthComponent inside AppController. After some more research and a surprisingly small but helpful post at How can I use different model for Auth component in CakePHP 2.0.4? I reviewed my code and now it seems to be working.

我将在这里发布审查的情况下,没有人会碰到这一点。

I will post the review here in case anyone will bump into this.

public $components = array(
    'Session',
    'Auth' => array(
        'authenticate' => array(
            'Form' => array(
                'userModel' => 'Utilizator',
                'fields' => array(
                    'username' => 'nume',
                    'password' => 'parola'
                )
            )
        ),
        'loginAction' => array('controller' => 'utilizatori', 'action' => 'login'), //Not related to the problem
        'loginRedirect' => array('controller' => 'utilizatori', 'action' => 'index'), //Not related to the problem
        'logoutRedirect' => array('controller' => 'utilizatori', 'action' => 'index') //Not related to the problem
    )
);

这篇关于CakePHP的2.0身份验证登录不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆