Exemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $email = $this->argument('email');
     $role = $this->option('role');
     if (!match_email_domain($email)) {
         return $this->comment(PHP_EOL . $email . ' is invalid. Admin or Staff require a DoSomething.org email.' . PHP_EOL);
     }
     $northstarUser = User::hasNorthstarAccount('email', $email);
     if (is_null($northstarUser)) {
         return $this->comment(PHP_EOL . 'No user found on Northstar with email: ' . $email . '. Create an account at https://dosomething.org.' . PHP_EOL);
     }
     $gladiatorUser = User::find($northstarUser->id);
     if (is_null($gladiatorUser)) {
         $user = new User();
         $user->id = $northstarUser->id;
         $user->role = $role;
         $user->save();
         return $this->comment(PHP_EOL . $email . ' added as a new "' . $role . '" user with id: ' . $northstarUser->id . PHP_EOL);
     }
     return $this->comment(PHP_EOL . $email . ' already exists as a user in Gladiator with a role of "' . $gladiatorUser->role . '"!' . PHP_EOL);
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 /**
  * 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]);
     }
 }
Exemplo n.º 4
0
 public function saveSplit($contest, $split, $request)
 {
     $startDate = Carbon::now()->startOfDay();
     $endDate = new Carbon($request->competition_end_date);
     foreach ($split as $competitionGroup) {
         // For each split, create a competition.
         $competition = new Competition();
         $competition->contest_id = $contest->getKey();
         $competition->competition_start_date = $startDate;
         $competition->competition_end_date = $endDate->endOfDay();
         $competition->leaderboard_msg_day = $request->leaderboard_msg_day;
         $competition->rules_url = $request->rules_url;
         $contest->competitions()->save($competition);
         // For each user in this group
         foreach ($competitionGroup as $userId) {
             $user = User::find($userId);
             // Remove them from the waiting room pivot table
             $user->waitingRooms()->detach();
             // Add them to the competitions pivot table
             $user->competitions()->attach($competition->id);
         }
     }
 }
 /**
  * Update the specified user's data
  *
  * @param  \Gladiator\Http\Requests\UserRequest $request
  * @param  string $id  Northstar ID
  * @return \Gladiator\Models\User
  */
 public function update($request, $id)
 {
     $user = User::findOrFail($id);
     $user->role = $request->role;
     $user->save();
     return $user;
 }
Exemplo n.º 6
0
 /**
  * Parse through cached role ids, and update for specified user.
  *
  * @param  string $id  Northstar ID
  * @param  string $role
  * @return void
  */
 protected function resolveUpdatedRoles($id, $role)
 {
     foreach (User::getRoles() as $name => $value) {
         $key = $name . ':ids';
         $ids = $this->retrieve($key);
         if ($ids) {
             if (in_array($id, $ids)) {
                 unset($ids[array_search($id, $ids)]);
                 $this->forget($key);
                 $this->store($key, $ids);
             } else {
                 if ($name === $role) {
                     $this->forget($key);
                     $ids[] = $id;
                     $this->store($key, $ids);
                 }
             }
         }
     }
 }
 /**
  * Detach a user from a competition.
  *
  * @param  \Gladiator\Models\Competition  $competition
  * @param  \Gladiator\Models\User  $user
  * @return \Illuminate\Http\Response
  */
 public function removeUser(Competition $competition, User $user)
 {
     $user->competitions()->detach($competition->id);
     return redirect()->back()->with('status', 'User was removed from competition ' . $competition->id);
 }
Exemplo n.º 8
0
 /**
  * Display the specified resource.
  *
  * @param  string  $id  Northstar ID
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $activities = [];
     $user = $this->repository->find($id);
     $competitions = User::findOrFail($id)->competitions;
     foreach ($competitions as $competition) {
         $parameters = $this->manager->getCampaignParameters($competition);
         $parameters['users'] = $user->id;
         $activities[] = $this->manager->appendReportback($competition, $parameters);
     }
     return view('users.show', compact('user', 'activities'));
 }
Exemplo n.º 9
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     // @TODO: temp for now, likely want to use repository and transform.
     return User::all();
 }