public static function doSearch($term) { $data = ['users' => [], 'pages' => [], 'events' => [], 'committees' => []]; $term = str_replace('%', '', $term); if (strlen($term) == 0) { return $data; } $term = explode(' ', $term); if (count($term) == 0) { return $data; } foreach ($term as $string) { $string = strtolower($string); if ($string == 'proto') { continue; } foreach (User::all() as $user) { if ((strlen($string) >= 3 && strpos(strtolower($user->name), $string) > -1 || strtolower($user->calling_name) == $string || $user->utwente_username && strlen($string) >= 5 && strpos(strtolower($user->utwente_username), $string) > -1 || intval($string) > 0 && $user->id == $string) && $user->member && Auth::check() && Auth::user()->member) { if (array_key_exists($user->id, $data['users'])) { $data['users'][$user->id]++; } else { $data['users'][$user->id] = 1; } } } foreach (Page::all() as $page) { if ((strlen($string) >= 3 && strpos(strtolower($page->title), $string) > -1 || strlen($string) >= 3 && strpos(strtolower($page->content), $string) > -1) && (!$page->is_member_only || Auth::check() && Auth::user()->member)) { if (array_key_exists($page->id, $data['pages'])) { $data['pages'][$page->id] += substr_count(strtolower($page->title), $string) + substr_count(strtolower($page->content), $string); } else { $data['pages'][$page->id] = substr_count(strtolower($page->title), $string) + substr_count(strtolower($page->content), $string); } } } foreach (Event::all() as $event) { if ((strlen($string) >= 3 && strpos(strtolower($event->title), $string) > -1 || strlen($string) >= 3 && strpos(strtolower($event->description), $string) > -1) && (!$event->secret || Auth::check() && Auth::user()->can('board'))) { if (array_key_exists($event->id, $data['events'])) { $data['events'][$event->id] += substr_count(strtolower($event->title), $string) + substr_count(strtolower($event->content), $string); } else { $data['events'][$event->id] = substr_count(strtolower($event->title), $string) + substr_count(strtolower($event->description), $string); $data['events'][$event->id] -= SearchController::searchTimePenalty($event); } } } foreach (Committee::all() as $committee) { if ((strlen($string) >= 3 && strpos(strtolower($committee->name), $string) > -1 || strlen($string) >= 3 && strpos(strtolower($committee->description), $string) > -1) && ($committee->public || Auth::check() && Auth::user()->can('board'))) { if (array_key_exists($committee->id, $data['committees'])) { $data['committees'][$committee->id] += substr_count(strtolower($committee->name), $string) + substr_count(strtolower($committee->description), $string); } else { $data['committees'][$committee->id] = substr_count(strtolower($committee->name), $string) + substr_count(strtolower($committee->description), $string); } } } } arsort($data['users']); arsort($data['pages']); arsort($data['events']); arsort($data['committees']); return $data; }
private function syncUsers($provider) { $activeIds = []; $this->info("Make sure all users exist in LDAP."); foreach (User::all() as $user) { $activeIds[] = $user->id; $ldapuser = $provider->search()->where('objectClass', 'user')->where('description', $user->id)->first(); $username = $user->member ? $user->member->proto_username : "******" . $user->id; if ($ldapuser == null) { $this->info('Creating LDAP user for ' . $user->name . '.'); $ldapuser = $provider->make()->user(); $ldapuser->cn = $username; $ldapuser->description = $user->id; $ldapuser->save(); } $ldapuser->move('cn=' . $username, 'OU=Members,OU=Proto,DC=ad,DC=saproto,DC=nl'); $ldapuser->displayName = trim($user->name); $ldapuser->givenName = trim($user->calling_name); $ldapuser->mail = $user->email; $ldapuser->wWWHomePage = $user->website; if ($user->address) { $ldapuser->l = $user->address->city; $ldapuser->postalCode = $user->address->zipcode; $ldapuser->streetAddress = $user->address->street . " " . $user->address->number; $ldapuser->preferredLanguage = $user->address->country; } else { $ldapuser->l = null; $ldapuser->postalCode = null; $ldapuser->streetAddress = null; $ldapuser->preferredLanguage = null; } $ldapuser->telephoneNumber = $user->phone; $ldapuser->setAttribute('sAMAccountName', $username); $ldapuser->setUserPrincipalName($username . config('adldap.proto')['account_suffix']); if (!$user->member) { $ldapuser->setUserAccountControl(AccountControl::ACCOUNTDISABLE); } $ldapuser->save(); } $this->info("Removing obsolete users from LDAP."); $users = $provider->search()->users()->get(); foreach ($users as $user) { if (!$user->description[0] || !in_array($user->description[0], $activeIds)) { $this->info("Deleting LDAP user " . $user->description[0] . "."); $user->delete(); } } }
public function members(Request $request) { if (!Auth::check() || !Auth::user()->member) { abort(403); } $users = User::all(); $data = array(); foreach ($users as $user) { if (!$user->member) { continue; } if ($request->has('term') && strpos(strtolower($user->name), strtolower($request->term)) === false) { continue; } $member = new \stdClass(); $member->name = $user->name; $member->id = $user->id; $data[] = $member; } return $data; }
private function constructForwarderList() { $data = []; // Constructing user forwarders. $users = User::all(); foreach ($users as $user) { if ($user->member && $user->isActiveMember()) { $data[$user->member->proto_username] = [$user->email]; } } // Constructing committee forwarders. $committees = Committee::all(); foreach ($committees as $committee) { $destinations = []; $users = CommitteeMembership::withTrashed()->where('committee_id', $committee->id)->where('created_at', '<', date('Y-m-d H:i:s'))->where(function ($q) { $q->whereNull('deleted_at')->orWhere('deleted_at', '>', date('Y-m-d H:i:s')); })->get(); foreach ($users as $user) { $destinations[] = $user->user->email; } if (count($destinations) > 0) { $data[$committee->slug] = $destinations; $data['committees'][] = $committee->slug . '@' . config('proto.emaildomain'); } } // Constructing manual aliases. $aliases = Alias::all(); foreach ($aliases as $alias) { if ($alias->destination) { $data[$alias->alias][] = $alias->destination; } else { $data[$alias->alias][] = $alias->user->email; } } return $data; }