示例#1
0
 /**
  * Checks a username.
  * @param array $users array data of access
  * @return bool
  * @throws FilterException
  */
 protected function matchUsers(array $users)
 {
     if (!$this->user instanceof \rock\user\User) {
         throw new FilterException(FilterException::UNKNOWN_CLASS, ['class' => '\\rock\\user\\User']);
     }
     // All users
     if (in_array('*', $users)) {
         return true;
         // guest
     } elseif (in_array('?', $users) && $this->user->isGuest()) {
         return true;
         // Authenticated
     } elseif (in_array('@', $users) && !$this->user->isGuest()) {
         return true;
         // username
     } elseif (in_array($this->user->get('username'), $users)) {
         return true;
     }
     $this->sendHeaders();
     return false;
 }
示例#2
0
 /**
  * Match by users
  *
  * @param array $users array data of access
  * @return bool|null
  * @throws AccessException
  */
 protected function matchUsers(array $users)
 {
     if (!$this->user instanceof \rock\user\User) {
         throw new AccessException(AccessException::UNKNOWN_CLASS, ['class' => '\\rock\\user\\User']);
     }
     // All users
     if (in_array('*', $users)) {
         return true;
         // guest
     } elseif (in_array('?', $users) && $this->user->isGuest()) {
         return true;
         // Authenticated
     } elseif (in_array('@', $users) && !$this->user->isGuest()) {
         return true;
         // username
     } elseif (in_array($this->user->get('username'), $users)) {
         return true;
     }
     if ($this->sendHeaders && $this->response instanceof \rock\response\Response) {
         $this->response->status403();
     }
     return false;
 }