创建自己的Zend_Auth_Adapter [英] Creating own Zend_Auth_Adapter

查看:105
本文介绍了创建自己的Zend_Auth_Adapter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有创造我自己的Zend_Auth_Adapter困难。我使用学说2也。到目前为止,我有... code以下

i am having difficulties creating my own Zend_Auth_Adapter. i am using Doctrine 2 with it also. so far i have ... code below

我得到的误差

方法hasIdentity不存在,并没有被困在__call()

Method "hasIdentity" does not exist and was not trapped in __call()

什么是错?

use \Doctrine\ORM;
class Application_Auth_Adapter implements Zend_Auth_Adapter_Interface {
    private $username;
    private $password;

    function __construct($username, $password) {
        $this->username = $username;
        $this->password = $password;
    }

    function authenticate() {
        $em = Zend_Registry::get('em');
        $query = $em->createQuery('select u from Application\Entities\User u WHERE u.name = :username')
                    ->setParameter('username', $this->username);
        try {
            $user = $query->getSingleResult();
            $salt = $user->salt;
            $hashedPassword = hash_hmac('sha256', $this->password, $salt);
            if ($hashedPassword == $user->password) {
                // login success
                return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $user);
            } else {
                // wrong password
                return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, null);
            }
        } catch (NonUniqueResultException $e) {
            // non unique result
            return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null);
        } catch (NoResultException $e) {
            // no result found
            return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, null);
        } catch (Exception $e) {
            // exception occured
            return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null);
        }
    }
} 

更新

我注意到的问题来自 Zend_Auth的

if ($this->hasIdentity()) {
    $this->clearIdentity();
}

但略低于功能,认证(),其

public function hasIdentity()

我注意到德堆栈跟踪一些奇怪的事情。

i noticed something strange with teh stack trace

#0 [internal function]: Zend_Controller_Action->__call('hasIdentity', Array)
#1 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Auth.php(123): AuthController->hasIdentity()
#2 D:\Projects\Websites\php\ZendFramework\LearningZF\application\controllers\AuthController.php(23): Zend_Auth->authenticate(Object(Application_Auth_Adapter))
#3 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Controller\Action.php(513): AuthController->loginAction()
#4 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('loginAction')
#5 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#6 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#7 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#8 D:\Projects\Websites\php\ZendFramework\LearningZF\public\index.php(26): Zend_Application->run()
#9 {main}

AuthController-> hasIdentity()其试图调用 hasIdentity() AuthController

推荐答案

我找到了原因!看到我更新...堆栈跟踪。我打电话的方法,就好像它是静态的。惯于产生错误?反正...我SHLD做

i found out why! see my update ... the stack trace. i am calling a method as if it were static. wont that produce an error? anyways ... i shld be doing

$结果= Zend_Auth的::的getInstance() - >进行身份验证($适配器);

$result = Zend_Auth::getInstance()->authenticate($adapter);

这篇关于创建自己的Zend_Auth_Adapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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