Esempio n. 1
0
 /**
  * Checks if a user is in a group or groups
  * @param  string|array $groups group name or an array of possible group names
  * @return boolean
  */
 public function inGroup($group)
 {
     if (!is_array($group)) {
         $group = array($group);
     }
     $gg = Set::extract($this->groups()->get(), '*.attributes.name');
     return count(array_intersect($gg, $group)) > 0;
 }
Esempio n. 2
0
 public static function search($query, $field = 'givenname')
 {
     $ds = LDAP::connect();
     $cfg = LDAP::config();
     $result = array();
     if ($ds) {
         $resource = ldap_bind($ds);
         $search = ldap_search($ds, $cfg['base'], "({$field}={$query})");
         $entries = ldap_get_entries($ds, $search);
         $prop_map = array('uid' => 'crsid', 'sn' => 'surname', 'cn' => 'name', 'ou' => 'college', 'instid' => 'collegecode', 'displayname' => 'display');
         foreach ($entries as $i => $r) {
             if (!is_integer($i)) {
                 continue;
             }
             array_push($result, array_map(function ($a) {
                 return $a[0];
             }, Set::reassignKeys(Set::select($r, array_keys($prop_map)), $prop_map)));
         }
     } else {
         throw new Exception('Unable to connect to LDAP server: ' + ldap_error($ds));
     }
     return $result;
 }