English 中文(简体)
我如何把Zentd_Ath、Zentd_Acl和部分观点结合起来,用于认证和资源控制。
原标题:How do I combine Zend_Ath, Zend_Acl and partialview for the authentication and resource control

According to Randomness will get you everywhere. Ryan’s Blog the action stack component of Zend Framework is un-needed and that a partial view can be combined with Zend_Acl and Zend_Auth for the purpose of authenticating and controlling resources.

我未能找到任何适当的例子来探讨它是如何做到的。 很高兴有人会向我表明如何执行。 增 编

最佳回答

各位:

http://devzone.zend.com/article/3322” 为了扩大其他答复,我举了一个简短的例子,说明你如何利用冻结的框架来管理认证:

首先,如果允许客户查阅某些数据,你需要打上“<>前>发送<>>的原始数据。 这一gin子可能看起来像这样:

class Plugin_AccessCheck extends Zend_Controller_Plugin_Abstract {

    private $_acl = null;

    public function __construct(Zend_Acl $acl) {
        $this->_acl = $acl;
    }

    public function preDispatch(Zend_Controller_Request_Abstract $request) {
        //get request information
        $module = $request->getModuleName ();
        $resource = $request->getControllerName ();
        $action = $request->getActionName ();

        try {
            if(!$this->_acl->isAllowed(Zend_Registry::get( role ), 
                                $module .  :  . $resource, $action)){
                $request->setControllerName ( authentication )
                        ->setActionName ( login );
            }
        }catch(Zend_Acl_Exception $e) {
            $request->setControllerName( index )->setActionName ( uups );
        }
    }
}

因此,每个用户类型都有你在图书馆中界定的某些许可。 根据每项要求,如果允许用户获得资源,请进行检查。 如果您不改用正文页,则预分机将用户带上资源。

http://framework.zend.com/manual/en/zend.acl.introduction.html” 您界定了允许或拒绝接触的作用、资源和许可,例如:

class Model_LibraryAcl extends Zend_Acl {
    public function __construct() {

        $this->addRole(new Zend_Acl_Role( guests ));
        $this->addRole(new Zend_Acl_Role( users ),  guests );
        $this->addRole(new Zend_Acl_Role( admins ),  users );                

        $this->add(new Zend_Acl_Resource( default ))
             ->add(new Zend_Acl_Resource( default:authentication ),  default )
             ->add(new Zend_Acl_Resource( default:index ),  default )
             ->add(new Zend_Acl_Resource( default:error ),  default );

        $this->allow( guests ,  default:authentication , array( login ));
        $this->allow( guests ,  default:error ,  error );

        $this->allow( users ,  default:authentication ,  logout );          
    }
}

之后,你不得不在你的boot锁档案中安装cl子和 au子:

    private $_acl = null;

    protected function _initAutoload() {

       //...your code           
       if (Zend_Auth::getInstance()->hasIdentity()){
        Zend_Registry::set ( role ,
                     Zend_Auth::getInstance()->getStorage()
                                              ->read()
                                              ->role);
        }else{
            Zend_Registry::set( role ,  guests );
        }

        $this->_acl = new Model_LibraryAcl ();
        $fc = Zend_Controller_Front::getInstance ();
        $fc->registerPlugin ( new Plugin_AccessCheck ( $this->_acl ) );

        return $modelLoader;
    }

Finally in your authentication controller you have to use a custom auth adapter and setup actions for login and logout:

public function logoutAction() {
    Zend_Auth::getInstance ()->clearIdentity ();
    $this->_redirect (  index/index  );
}

private function getAuthAdapter() {
    $authAdapter = new Zend_Auth_Adapter_DbTable ( 
                        Zend_Db_Table::getDefaultAdapter ());
    $authAdapter->setTableName( users )
                ->setIdentityColumn( email )
                ->setCredentialColumn ( password )
                ->setCredentialTreatment ( SHA1(CONCAT(?,salt)) );

    return $authAdapter;
}

在你的行动中,你需要将日志数据传递给进行认证的适应者。

$authAdapter = $this->getAuthAdapter ();
$authAdapter->setIdentity ( $username )->setCredential ( $password );
$auth = Zend_Auth::getInstance ();
$result = $auth->authenticate ( $authAdapter );

if ($result->isValid ()) {
    $identity = $authAdapter->getResultRowObject ();
    if ($identity->approved ==  true ) {
        $authStorage = $auth->getStorage ();
        $authStorage->write ( $identity );
        $this->_redirect (  index/index  );
    } else {
       $this->_redirect (  authentication/login  );
  }

And that s all. I recommend you this HOW TO on youtube on zend auth and zend acl.

问题回答

你可能认为以下关于行动帮助者的文章有用,我建议,如果你们有新之处的话,将网站浏览起来,因为还有执行Zend_Auth的文章:





相关问题
Zend 邮件问题,涉及外国char子+ com子

泽斯德邮局在名称被定为具有外国性质(如“保”)和 com(”)的物品时,就放弃了一种例外(因为邮局(邮局)退回假)。 重新提出以下守则。

PHP Framework: Ebay Like Site

I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal. What would be the best PHP framework to use to build this quickly, ...

Link to a specific step in onepage checkout

Is it possible to redirect the browser to nth step in the onepage checkout? If so, how would one go about doing it? I m working on a payment module and have a sort of "cancel" action that i would ...

Tagging with Zend Framework

I m trying to create the same solutions as below, but using a simple MySQL query (instead of the static version used below where the words/tags are implemented in the code). The name of the MySQL ...

dynamicaly adding textboxes to zend_form

I hope that this is a quick question to answer. I am developing a form using Zend_Form, I have a number of Zend_Dojo_Form_Element_Textboxs to add to this form dynamically. These are added from rows ...

热门标签