Example #1
0
 /**
  * Resolve user account within Northstar/Gladiator system.
  *
  * @param  array  $credentials
  * @return \Gladiator\Models\User|object
  * @throws \Gladiator\Services\Northstar\Exceptions\NorthstarUserNotFoundException
  */
 public function findUserAccount($credentials)
 {
     $northstarUser = $this->northstar->getUser($credentials['term'], $credentials['id']);
     if (!$northstarUser) {
         throw new NorthstarUserNotFoundException();
     }
     // @TODO: Can't use Repository method below because it throws exception
     // and here we just need "null" if user not found in Database. Find a
     // better fix if necessary!
     $user = User::find($northstarUser->id);
     if (!$user) {
         return $northstarUser;
     }
     return $user;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // Add Admin Users
     $admins = ['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'];
     foreach ($admins as $admin) {
         Artisan::call('add:user', ['email' => $admin, '--role' => 'admin']);
     }
     // Add Contestant Users
     $waitingRooms = WaitingRoom::all();
     $totalRooms = count($waitingRooms);
     $seedContestants = $this->northstar->getAllUsers(['limit' => 100]);
     foreach ($seedContestants as $contestant) {
         $index = mt_rand(0, $totalRooms - 1);
         // Using first or create if someone is already an admin.
         $user = User::firstOrCreate(['id' => $contestant->id]);
         $user->waitingRooms()->save($waitingRooms[$index]);
     }
 }
 /**
  * Get large number of users in batches from Northstar.
  *
  * @param  array  $ids
  * @param  int $size
  * @return \Illuminate\Support\Collection
  */
 protected function getBatchedCollection($ids, $size = 50)
 {
     // @TODO: Should this be a function in Northstar Client?
     $count = intval(ceil(count($ids) / 50));
     $index = 0;
     $data = [];
     for ($i = 0; $i < $count; $i++) {
         $batch = array_slice($ids, $index, $size);
         $parameters['limit'] = '50';
         $parameters['filter[_id]'] = implode(',', $batch);
         $accounts = $this->northstar->getAllUsers($parameters);
         $data = array_merge($data, $accounts);
         $index += $size;
     }
     return collect($data);
 }
Example #4
0
 /**
  * Search for users in Northstar.
  *
  * @param  string $query
  * @param  int $page
  * @return collection|null
  */
 public function search($query, $page = null)
 {
     // Attempt to fetch all users.
     $users = $this->northstar->getAllUsers(['search' => ['_id' => $query, 'drupal_id' => $query, 'email' => $query, 'mobile' => $query], 'page' => is_null($page) ? 1 : $page]);
     return $users ? collect($users) : null;
 }