Example #1
0
 public function logNotification($type, $name, $data)
 {
     $l = new OutgoingMessage();
     $l->user_id = $this->user->id;
     $l->type = $type;
     $l->name = $name;
     $l->data = json_encode($data);
     $l->save();
     AnalyticsController::log($this->user->id, 'outgoing-' . $type, $data);
     Log::info('[NOTIFIER] ' . $type . ' sent to id#' . $this->user->id . '. data: ' . json_encode($data));
 }
Example #2
0
 public function scan(Request $request)
 {
     $isAdmin = false;
     try {
         $exec = JWTAuth::parseToken()->toUser();
     } catch (\Exception $e) {
         $exec = null;
     }
     if ($exec) {
         $isExecAuthValid = $exec->hasRole('exec');
     }
     $isPodAuthValid = $request->pod_key == env('PODPOD_KEY');
     if (!$isPodAuthValid && !$isExecAuthValid) {
         //allow authorized pod clients OR execs
         return ['success' => false, "message" => "auth error"];
     }
     $pod = Pod::find($request->pod_id);
     if (!$pod) {
         return ['success' => false, "message" => 'error with pod_id'];
     }
     $scan = new PodScan();
     $scan->ip = $request->ip();
     $scan->pod_id = $pod->id;
     $scan->event_id = $pod->current_event_id;
     $scan->message = "ok";
     //default to good
     $scan->success = true;
     //default to good
     if ($pod->current_event_id == NULL) {
         //pod is not assigned to an event
         $scan->success = false;
         //todo: check if the event is 'active'
         $scan->message = "this pod is currently not assigned to an event";
         $scan->save();
         return $scan;
     }
     $event = Event::find($scan->event_id);
     if ($request->code == null || !isset($request->code)) {
         //todo: robustness in case this doesnt exist
         $scan->success = false;
         $scan->message = "somehting wrong with the code!";
         $scan->save();
         return $scan;
     }
     $scan->input = $request->code;
     $user = User::where('identifier', $request->code)->first();
     if (!$user) {
         //this would really only happen if someone is trying to hack us!
         //can't find a user behind the code
         //todo: robustness
         $scan->success = false;
         $scan->message = "user id not valid!";
         $scan->save();
         return $scan;
     }
     //todo: see if the user has already scanned for this event
     $scan->user_id = $user->id;
     $scan->message = "processed pod scan from pod: " . $pod->name . " (#" . $pod->id . ") for event: " . $event->name . " (#" . $event->id . ") from user: "******" @ " . $request->ip();
     Log::info("[POD] " . $scan->message);
     AnalyticsController::log($user->id, 'pod-scan', ['pod_id' => $pod->id, 'pod_name' => $pod->name, 'event' => $event, 'scan' => $scan], ['client' => 'pod-' . $pod->id, 'ip' => $request->ip()]);
     $scan->save();
     return $scan;
 }