コード例 #1
0
 public function about()
 {
     if (Auth::isSubscriber()) {
         return redirect('/missioncontrol');
     }
     return view('missionControl.about', ['stripePublicKey' => Config::get('services.stripe.public')]);
 }
コード例 #2
0
 public function incrementViewCounter()
 {
     // Only increment the view counter if the current user is a subscriber
     if (Auth::isSubscriber()) {
         $modelName = (new ReflectionClass($this))->getShortName();
         $modelKey = strtolower($modelName) . '_id';
         // Only increment the view counter if the user has not visited in 1 hour
         if (!Redis::exists($modelName . 'ViewByUser:'******':' . Auth::id())) {
             // Increment
             Redis::hincrby($modelName . ':' . $this->{$modelKey}, 'views', 1);
             // Add user to recent views
             Redis::setex($modelName . 'ViewByUser:'******':' . Auth::id(), 3600, true);
         }
     }
 }
コード例 #3
0
 public function favorite($object_id)
 {
     if (Auth::isSubscriber()) {
         // Create Favorite
         if (request()->isMethod('post')) {
             if (Auth::user()->favorites()->count() == 0) {
                 Favorite::create(array('object_id' => $object_id, 'user_id' => Auth::id()));
             }
             // Delete Favorite
         } elseif (request()->isMethod('delete')) {
             Auth::user()->favorites()->where('object_id', $object_id)->firstOrFail()->delete();
         }
         Redis::sadd('objects:toReindex', $object_id);
         return response()->json(null, 204);
     }
     return response()->json(false, 401);
 }
コード例 #4
0
 /**
  * GET (AJAX), /missions/{$slug}/telemetry. Fetches all mission telemetries for a specified mission,
  * ordered by the telemetry timestamp.
  *
  * @param $slug
  * @return \Illuminate\Http\JsonResponse
  */
 public function telemetry($slug)
 {
     $telemetryQuery = Telemetry::whereHas('mission', function ($q) use($slug) {
         $q->whereSlug($slug);
     })->orderBy('timestamp', 'ASC');
     if (Auth::isSubscriber()) {
         return response()->json($telemetryQuery->get());
     } else {
         return response()->json($telemetryQuery->get(['telemetry_id', 'timestamp', 'readout']));
     }
 }