Esempio n. 1
0
 /**
  * Same as getByEmail, but also allows for restriction by account id.
  *
  * @param string $email
  * @param AccountInterface $account
  * @return User
  */
 public function getByEmailAndAccount($email, $account)
 {
     $user = $this->getQuery()->whereHas('accounts', function ($query) use($account) {
         $query->where('accounts.id', '=', $account->getId());
     })->whereEmail($email)->first();
     return $user;
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  */
 public function equals(AccountInterface $account)
 {
     if (!$account instanceof User) {
         return false;
     }
     if ($this->password !== $account->getPassword()) {
         return false;
     }
     if ($this->getSalt() !== $account->getSalt()) {
         return false;
     }
     if ($this->username !== $account->getUsername()) {
         return false;
     }
     if ($this->accountNonExpired !== $account->isAccountNonExpired()) {
         return false;
     }
     if ($this->accountNonLocked !== $account->isAccountNonLocked()) {
         return false;
     }
     if ($this->credentialsNonExpired !== $account->isCredentialsNonExpired()) {
         return false;
     }
     if ($this->enabled !== $account->isEnabled()) {
         return false;
     }
     return true;
 }
 /**
  * {@inheritdoc}
  */
 public function getFieldAccess($operation, $items, AccountInterface $account, $field_definition)
 {
     $default_type = FieldPermissionsService::fieldGetPermissionType($field_definition);
     if (in_array("administrator", $account->getRoles()) || $default_type == FIELD_PERMISSIONS_PUBLIC) {
         return TRUE;
     }
     if ($default_type == FIELD_PERMISSIONS_PRIVATE) {
         if ($operation === "view") {
             if ($items->getEntity()->getOwnerId() == $account->id()) {
                 return $account->hasPermission($operation . "_own_" . $field_name);
             } else {
                 return FALSE;
             }
         } elseif ($operation === "edit") {
             if ($items->getEntity()->isNew()) {
                 return $account->hasPermission("create_" . $field_name);
             } elseif ($items->getEntity()->getOwnerId() == $account->id()) {
                 return $account->hasPermission($operation . "_own_" . $field_name);
             } else {
                 return FALSE;
             }
         }
     }
     if ($default_type == FIELD_PERMISSIONS_CUSTOM) {
         if ($operation === "view") {
             if ($account->hasPermission($operation . "_" . $field_name)) {
                 return $account->hasPermission($operation . "_" . $field_name);
             } elseif ($items->getEntity()->getOwnerId() == $account->id()) {
                 return $account->hasPermission($operation . "_own_" . $field_name);
             }
         } elseif ($operation === "edit") {
             if ($items->getEntity()->isNew()) {
                 return $account->hasPermission("create_" . $field_name);
             }
             if ($account->hasPermission($operation . "_" . $field_name)) {
                 return $account->hasPermission($operation . "_" . $field_name);
             } elseif ($items->getEntity()->getOwnerId() == $account->id()) {
                 return $account->hasPermission($operation . "_own_" . $field_name);
             }
         }
     }
 }
 /**
  * Checks access for a list of the user's purchased file downloads.
  *
  * @param \Drupal\Core\Session\AccountInterface $account
  *   Run access checks for this account.
  */
 public function accessUserDownloads(AccountInterface $account)
 {
     $user = \Drupal::currentUser();
     return $user->id() && ($user->hasPermission('view all downloads') || $user->id() == $account->id());
 }