public function run()
 {
     User::create(array('role_id' => UserRole::Administrator, 'username' => 'elonmusk', 'email' => '*****@*****.**', 'password' => 'password', 'key' => str_random(32), 'launch_controller_flag' => true));
     User::create(array('role_id' => UserRole::CharterSubscriber, 'username' => 'gwynne.shotwell', 'email' => '*****@*****.**', 'password' => 'password', 'key' => str_random(32)));
     User::create(array('role_id' => UserRole::Subscriber, 'username' => 'TomMueller', 'email' => '*****@*****.**', 'password' => 'password', 'subscription_ends_at' => Carbon::now()->addYear(), 'key' => str_random(32)));
     User::create(array('role_id' => UserRole::Member, 'username' => 'stevejurvetson', 'email' => '*****@*****.**', 'password' => 'password', 'key' => str_random(32)));
     User::create(array('role_id' => UserRole::Unauthenticated, 'username' => 'barrymatsomuri', 'email' => '*****@*****.**', 'password' => 'password', 'key' => str_random(32)));
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $user = new User();
     $user->username = $this->argument('username');
     $user->email = $this->argument('username') . '@spacexstats.com';
     $user->password = $this->argument('password');
     // Hashed as a mutator on the User model
     $user->key = str_random(32);
     $user->role_id = UserRole::fromString($this->argument('role'));
     if ($this->option('launchctl')) {
         $user->launch_controller_flag = true;
     }
     DB::transaction(function () use($user) {
         $user->save();
         // Associate a profile
         $profile = new Profile();
         $profile->user()->associate($user)->save();
     });
 }
 /**
  * Increment the user's Mission Control subscription by the given number of seconds if they are a
  * Mission Control subscriber.
  *
  * This method has safeguards to prevent users with higher roles (charter subscribers, admins) from
  * being awarded extra time on a nonexistent subscription.
  *
  * @param User $user    The user to award
  * @param Award $award The award for which we can calculate the subscription length
  */
 public function incrementSubscription(User $user, Award $award)
 {
     if ($user->role_id == UserRole::Subscriber) {
         // Calculate the seconds to extend by
         $seconds = (new DeltaVCalculator())->toSeconds($award->value);
         // Fetch the current subscription/trial end
         $endDate = is_null($user->getTrialEndDate()) ? $user->getSubscriptionEndDate() : $user->getTrialEndDate();
         // Calculate the new end date
         $newEndDate = $endDate->addSeconds($seconds);
         // Extend trial to that date
         $user->subscription($this->currentPlan)->noProrate()->trialFor($newEndDate)->swap();
         // Update the database
         $user->trial_ends_at = $user->subsription()->getTrialEndDate();
         $user->save();
     }
 }
 public function notify()
 {
     // What notification type is this
     if ($this->timeRemaining->hours == 24) {
         $notificationType = NotificationType::TMinus24HoursSMS;
     } elseif ($this->timeRemaining->hours == 3) {
         $notificationType = NotificationType::TMinus3HoursSMS;
     } else {
         $notificationType = NotificationType::TMinus1HourSMS;
     }
     // grab all users with this particular notification
     $usersToNotify = User::whereHas('notification', function ($q) use($notificationType) {
         $q->where('notification_type_id', $notificationType);
     })->with('notifications.notification_type')->get();
     $messageToSend = sprintf($this->message, $this->nextMission->name, $this->nextMission->vehicle->vehicle, $this->timeRemaining, $this->nextMission->launchDateTime, $this->nextMission->launchSite->fullLocation, $this->nextMission->slug);
     // Send!
     $sms = new SMSSender();
     $sms->send($usersToNotify, $messageToSend);
 }
 /**
  * GET (HTTP). Home.
  *
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
  */
 public function home()
 {
     if (Auth::isSubscriber()) {
         // Fetch data
         $objects['latest'] = Object::authedVisibility()->inMissionControl()->orderBy('created_at', 'desc')->take(10)->get();
         $objects['hot'] = Object::authedVisibility()->inMissionControl()->selectRaw('objects.*, LOG10(greatest(1, count(comments.object_id)) + greatest(1, count(favorites.object_id))) / TIMESTAMPDIFF(HOUR, objects.actioned_at, NOW()) as score')->leftJoin('comments', 'comments.object_id', '=', 'objects.object_id')->leftJoin('favorites', 'favorites.object_id', '=', 'objects.object_id')->groupBy('objects.object_id')->orderBy(DB::raw('score'))->take(10)->get();
         $objects['discussions'] = Object::authedVisibility()->inMissionControl()->where('type', MissionControlType::Text)->join('comments', 'comments.object_id', '=', 'objects.object_id')->orderBy('comments.created_at')->select('objects.*')->take(10)->get();
         $objects['mission'] = Object::authedVisibility()->inMissionControl()->whereHas('Mission', function ($q) {
             $q->future()->take(1);
         })->take(10)->get();
         $objects['random'] = Object::authedVisibility()->inMissionControl()->orderByRaw("RAND()")->take(10)->get();
         // Leaderboards
         $leaderboards['week'] = User::join('awards', 'awards.user_id', '=', 'users.user_id')->selectRaw('users.user_id, users.username, sum(awards.value) as totalDeltaV')->where('awards.created_at', '>=', Carbon::now()->subWeek())->groupBy('users.user_id')->take(10)->get();
         $leaderboards['month'] = User::join('awards', 'awards.user_id', '=', 'users.user_id')->selectRaw('users.user_id, users.username, sum(awards.value) as totalDeltaV')->where('awards.created_at', '>=', Carbon::now()->subMonth())->groupBy('users.user_id')->take(10)->get();
         $leaderboards['year'] = User::join('awards', 'awards.user_id', '=', 'users.user_id')->selectRaw('users.user_id, users.username, sum(awards.value) as totalDeltaV')->where('awards.created_at', '>=', Carbon::now()->subYear())->groupBy('users.user_id')->take(10)->get();
         $leaderboards['alltime'] = User::join('awards', 'awards.user_id', '=', 'users.user_id')->selectRaw('users.user_id, users.username, sum(awards.value) as totalDeltaV')->groupBy('users.user_id')->take(10)->get();
         // Comments
         $comments = Comment::with(['object' => function ($query) {
             $query->select('object_id', 'title');
         }])->with(['user' => function ($query) {
             $query->select('user_id', 'username');
         }])->orderBy('created_at', 'DESC')->take(10)->get();
         // Favorites
         $favorites = Favorite::with(['object' => function ($query) {
             $query->select('object_id', 'title');
         }])->with(['user' => function ($query) {
             $query->select('user_id', 'username');
         }])->orderBy('created_at', 'DESC')->take(10)->get();
         // Downloads
         $downloads = Download::with(['object' => function ($query) {
             $query->select('object_id', 'title');
         }])->with(['user' => function ($query) {
             $query->select('user_id', 'username');
         }])->orderBy('created_at', 'DESC')->take(10)->get();
         return view('missionControl.home', ['upcomingMission' => Mission::future()->first(), 'leaderboards' => $leaderboards, 'objects' => $objects, 'comments' => $comments, 'favorites' => $favorites, 'downloads' => $downloads]);
     } else {
         return redirect()->action('MissionControl\\MissionControlController@about');
     }
 }
Exemple #6
0
 public function isValidKey($userId, $key)
 {
     $user = User::where('user_id', $userId)->where('key', $key)->firstOrFail();
     if (!empty($user)) {
         $user->role_id = UserRole::Member;
         return $user->save();
     }
 }
 public function comments($username)
 {
     $user = User::with('comments.object')->where('username', $username)->first();
     return view('users.profile.comments', ['user' => $user]);
 }
 /**
  * Endpoint to check if the username exists asynchronously from the signup form.
  *
  * @param $usernameChallenge
  * @return \Illuminate\Http\JsonResponse
  */
 public function isUsernameTaken($usernameChallenge)
 {
     try {
         User::byUsername($usernameChallenge);
     } catch (ModelNotFoundException $e) {
         return response()->json(['taken' => false]);
     }
     return response()->json(['taken' => true]);
 }