1

I'm using Zend_Auth with a project using doctrine.I believe every bootstrapping is done correctly and i can log in.

my adapter looks like this:

class Abra_Auth_Adapter_Doctrine implements Zend_Auth_Adapter_Interface {

protected $_resultArray;
private $username;
private $password;

public function  __construct($username, $password) {

    $this->username = $username;
    $this->password = $password;

}

//based on feedbacks as response authenticate has changed to this
public function  authenticate() {
    $q = Doctrine_Query::create()
    ->from("Abra_Model_User u")
    ->leftJoin("u.Role r")
    ->where("u.username=? AND u.password=?", array($this->username,$this->password));
    $result = $q->execute();
    if (count($result) == 1) {
        return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $result->get("Mylibrary_Model_User"), array());//autoloaderNamespaces[] = "Mylibrary_" in application.ini
    } else {
        return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null, array("Authentication Unsuccessful"));
    }
}

my Abra_Controller_Pluging_Acl looks like this

class Abra_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract {

public function preDispatch(Zend_Controller_Request_Abstract $request) {
    parent::preDispatch($request);
    $controller = $request->getControllerName();
    $action = $request->getActionName();
    $module = $request->getModuleName();

    $auth = Zend_Auth::getInstance();
    if($auth->hasIdentity()){
        $identity = $auth->getIdentity();
        $roles = $identity["Role"];
        $role = $roles["name"];
        $role = (empty ($role) || is_null($role))? "regular" : $role ;
    } else {
        $role = "guest";
    }

 }

now having Doctrine_Event Fatal error: spl_autoload() [function.spl-autoload]: Class Doctrine_Event could not be loaded. i've seen this post here and i'm wondering how that can affect my using of Zend_Session, and it's true that i have apc.dll enabled in my php.thanks a lot for reading this

4

1 回答 1

2

如何获取角色:在您的适配器中,成功登录后,不是只返回用户名字段,而是返回整个用户对象怎么样?然后,当您致电时,整个事情都将可用Zend_Auth::getIdentity()

问题 1:如果您将控制器视为资源并且每个模块的 ACL 规则会有所不同,那么资源名称也应该反映模块。这将解决具有相同控制器名称的模块的问题。

问题2:我不确定我的理解是否正确。Zend_Auth 及其存储将负责将用户身份保存在其自己的会话命名空间中。但是,我遇到了当数据库中的用户记录发生更改时该怎么做的问题 - 例如,用户在登录会话期间修改了他的个人资料中的全名 - 而您在站点模板中显示该全名, 从Zend_Auth::getIdentity(). 作为用户,我希望更改会反映在可见界面中,但更改只发生在数据库中,而不是会话中。

我过去所做的是创建一个额外的身份验证适配器来获取新的用户记录并始终返回成功。当用户更新他的个人资料时,我Zend_Auth::authenticate()使用这个简单的适配器调用。会话存储得到更新,一切都很好。

[这种方法几乎可以肯定是一种 hack,所以我有兴趣听到其他方法。我确定我可以直接在会话存储中设置一个值,但是当我上次尝试时,我无法让它完全正常工作。所以求助于额外的适配器解决方法。]

于 2011-01-12T02:42:14.070 回答