/**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function logout()
 {
     $input = Input::all();
     $device = Device::where('device_id', $input['device_id'])->where('user_id', $input['user_id'])->first();
     if ($device) {
         if ($device->session_id == $input['session_id']) {
             Device::find($device->id)->update(['session_id' => null]);
             return Common::returnData(200, SUCCESS, $input['user_id'], '');
         } else {
             throw new Prototype\Exceptions\UserSessionErrorException();
         }
     }
     throw new Prototype\Exceptions\DeviceErrorException();
 }
Beispiel #2
0
 public static function getSessionId($input, $userId)
 {
     $device = Device::where('device_id', $input['device_id'])->where('user_id', $userId)->first();
     if ($device) {
         if (empty($input['session_id'])) {
             $sessionId = $device->session_id;
             if (!$sessionId) {
                 $sessionId = generateRandomString();
                 Device::find($device->id)->update(['session_id' => $sessionId]);
             }
         } else {
             if ($device->session_id == $input['session_id']) {
                 $sessionId = $input['session_id'];
             } else {
                 throw new Prototype\Exceptions\UserSessionErrorException();
             }
         }
     } else {
         $sessionId = generateRandomString();
         Device::create(['device_id' => $input['device_id'], 'user_id' => $userId, 'session_id' => $sessionId]);
     }
     return $sessionId;
 }
Beispiel #3
0
 function parseDevices($domainNode, $domainName)
 {
     $i = 0;
     $deviceNodes = $this->xpath->query(".//x:node", $domainNode);
     if ($deviceNodes) {
         foreach ($deviceNodes as $deviceNode) {
             $idString = $deviceNode->getAttribute('id');
             $id = explode("=", $idString);
             $deviceName = $id[count($id) - 1];
             $geo = Device::find()->where(['domain' => $domainName, 'node' => $deviceName])->asArray()->one();
             if (!$geo) {
                 $geo = $this->parseLocation($domainName, $deviceName);
                 Device::createIfNew($domainName, $deviceName, $geo['lat'], $geo['lng'], $geo['address']);
                 $i++;
             }
             $location = $this->xml->createElement('CtrlPlane:location');
             $lat = $this->xml->createElement('CtrlPlane:latitude', $geo['lat']);
             $lng = $this->xml->createElement('CtrlPlane:longitude', $geo['lng']);
             $address = $this->xml->createElement('CtrlPlane:address', $geo['address']);
             $location->appendChild($lat);
             $location->appendChild($lng);
             $location->appendChild($address);
             $deviceNode->appendChild($location);
         }
         if ($i > 3) {
             $i = 0;
             sleep(1);
         }
     }
 }
Beispiel #4
0
 public function edit($id)
 {
     $device = Device::find($id);
     return View::make('devices.edit', array('device' => $device, 'status' => $this->status, 'types' => $this->types, 'users' => $this->users, 'region' => $this->region));
 }