2012-07-31 6 views
0

저는 Zend를 사용하여 소셜 웹 사이트를 만들고 있습니다. 이 사이트를 통해 사용자는 친구가되어 서로의 프로필과 블로그에 액세스 할 수 있습니다. 나는 또한 사용자가 자신의 개인 정보를 제어 할 수 있기를 원하며 "친구 전용"및 "공개"매개 변수를 사용할 수 있습니다. 나는 Zend_Acl을 살펴 봤지만 사용자와 관계가없는 단일 사용자의 접근성 만 처리 할 수있는 것 같다. 이 작업을 수행하는 가장 좋은 방법에 대한 아이디어가 있습니까?Zend를 사용한 개인 정보 제어

답변

0

Zend_Acl을 사용하는 경우 사용자의 목적에 따라 assertions을 확인해야합니다.

응용 프로그램의 사용자 간 복잡한 관계로 인해 쿼리 할 대부분의 액세스 규칙은 매우 동적 인 것처럼 보이므로 액세스 가능성을 결정하기 위해 더 복잡한 논리를 사용할 수있는 어설 션에 크게 의존하게됩니다.

Zend_Acl을 사용하여 원하는 것을 달성 할 수 있어야합니다.

이 같은 ACL 규칙을 설정할 수 있습니다 :

ACL을 주장 자체
$acl->allow('user', 'profile', 'view', new My_Acl_Assertion_UsersAreFriends()); 

: 장소에서이 주장에 이제

<?php 

class My_Acl_Assertion_UsersAreFriends implements Zend_Acl_Assert_Interface 
{ 
    public function assert(Zend_Acl $acl, 
          Zend_Acl_Role_Interface $role = null, 
          Zend_Acl_Resource_Interface $resource = null, 
          $privilege = null) 
    { 
     return $this->_usersAreFriends(); 
    } 

    protected function _usersAreFriends() 
    { 
     // get UserID of current logged in user 
     // assumes Zend_Auth has stored a User object of the logged in user 
     $user = Zend_Auth::getInstance()->getStorage(); 
     $userId = $user->getId(); 

     // get the ID of the user profile they are trying to view 
     // assume you can pull it from the URL 
     // or your controller or a plugin can set this value another way 
     $userToView = $this->getRequest()->getParam('id', null); 

     // call your function that checks the database for the friendship 
     $usersAreFriends = usersAreFriends($userId, $userToView); 

     return $usersAreFriends; 
    } 
} 

는, 액세스는이 개 사용자 ID 경우 거부됩니다 친구가 아니야.

가 좋아 체크 : 도움이

if ($acl->isAllowed('user', 'profile', 'view')) { 
    // This will use the UsersAreFriends assertion 

    // they can view profile 
} else { 
    // sorry, friend this person to view their profile 
} 

희망을.

관련 문제