コード例 #1
2
 public function apiRegister(Request $request)
 {
     $model = $request->Input('model');
     $manufacturer = $request->Input('manufacturer');
     $product = $request->Input('product');
     $sdk_version = $request->Input('sdk_version');
     $serial_number = $request->Input('serial_number');
     $latitude = $request->Input('latitude');
     $longitude = $request->input('longitude');
     // Check if serial number exists in database
     $newDevice = Device::where('serial_number', '=', $serial_number)->first();
     if (null == $newDevice) {
         $newDevice = new Device();
         $newDevice->model = $model;
         $newDevice->manufacturer = $manufacturer;
         $newDevice->product = $product;
         $newDevice->sdk_version = $sdk_version;
         $newDevice->serial_number = $serial_number;
         $newDevice->latitude = $latitude;
         $newDevice->longitude = $longitude;
         $newDevice->save();
     }
     return $newDevice->jsonSerializable();
 }
コード例 #2
0
ファイル: Status.php プロジェクト: encry2024/inv_5_2
 public static function fetch_available()
 {
     $json = array();
     $defectiveStatuses = Device::where('status_id', 0)->get();
     foreach ($defectiveStatuses as $defectiveStatus) {
         $json[] = ['device_id' => $defectiveStatus->id, 'device_name' => $defectiveStatus->name, 'category' => $defectiveStatus->category->name, 'category_id' => $defectiveStatus->category->id];
     }
     return json_encode($json);
 }
コード例 #3
0
 public function response($id)
 {
     $device = Device::where('user_id', $id)->first();
     $state = $device->state;
     $state = mt_rand(0, 1);
     /**
      * return the state of the lock;
      *  1 = isLocked; 0 = isNotLocked;
      **/
     return view('device.index', compact('state'));
 }
コード例 #4
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function index()
 {
     $device = Device::current();
     $devices = Device::where(function ($query) use($device) {
         $query->whereUserId($device->user_id)->where('id', '<>', $device->id);
     })->orWhere(function ($query) use($device) {
         $authed_device_ids = DUAuth::whereUserId($device->user_id)->lists('device_id');
         $query->whereIn('id', $authed_device_ids);
     })->paginate(15);
     return Response::json($devices);
 }
コード例 #5
0
 public function logdevice(Request $request)
 {
     $uid = $request->uid;
     $status = $request->status;
     $device = Device::where('uid', $uid)->first();
     if (!empty($device)) {
         $device->status = $status;
         $device->update();
         $msg = 'Device status updated';
     } else {
         $msg = 'Device not found';
     }
     return response()->json(['msg' => $msg], 200);
 }
コード例 #6
0
 public function testDeviceDelete()
 {
     $admin = User::find(1);
     $device = new Device();
     $device->model = "Nexus 6P";
     $device->manufacturer = "LGE";
     $device->product = "bullhead";
     $device->sdk_version = "23";
     $device->serial_number = "009f582e7941a8e7";
     $device->latitude = "51.5034070";
     $device->longitude = "-0.1275920";
     $device->save();
     $savedDevice = Device::where('serial_number', '=', '009f582e7941a8e7')->first();
     $this->actingAs($admin)->withSession(['foo' => 'bar'])->visit($this->modelUrl . (string) $savedDevice->id)->press('Delete')->seePageIs($this->modelUrl);
 }
コード例 #7
0
 public function auth(Request $request)
 {
     $device_id = $request->device_id;
     $usernameinput = $request->email;
     $password = $request->pwd;
     $version = $request->version;
     // dd($request);
     $field = $usernameinput ? 'email' : 'username';
     if (\Auth::attempt(array('username' => $usernameinput, 'password' => $password), false)) {
         $user = \Auth::user();
         $device = Device::where('device_id', $device_id)->first();
         if ($request->has('version')) {
             if (!empty($device)) {
                 $device->version = $version;
                 $device->username = $usernameinput;
                 $device->update();
             } else {
                 Device::create(['device_id' => $device_id, 'version' => $version, 'username' => $usernameinput]);
             }
         }
         if ($user->log_status == 0 || $user->device_id == $device_id) {
             $user->log_status = 1;
             $user->device_id = $device_id;
             $user->last_login = date('Y-m-d H:i:s');
             $user->update();
             $hash = UpdateHash::find(1);
             $user->hash = $hash->hash;
             return response()->json($user);
         } else {
             $t1 = StrToTime(date('Y-m-d H:i:s'));
             $t2 = StrToTime($user->last_login);
             $diff = ($t1 - $t2) / (60 * 60);
             if ($diff >= 24) {
                 $user->log_status = 1;
                 $user->device_id = $device_id;
                 $user->last_login = date('Y-m-d H:i:s');
                 $user->update();
                 $hash = UpdateHash::find(1);
                 $user->hash = $hash->hash;
                 return response()->json($user);
             } else {
                 return response()->json(array('msg' => 'User already logged on another device.', 'status' => 0, 'hr' => $diff));
             }
         }
     } else {
         return response()->json(array('msg' => 'user not found', 'status' => 0));
     }
 }
コード例 #8
0
ファイル: DeviceController.php プロジェクト: hew86i/timeattd
 public function connectToIp($ip = '127.0.0.1')
 {
     $tadf = new TADFactory(['ip' => $ip]);
     $this->tad = $tadf->get_instance();
     $status = $this->tad->is_alive();
     $device = Device::where('ip_address', $ip)->first();
     $connected_device = Connected::find(1);
     $connected_device->ip_address = $ip;
     $connected_device->device_id = $device->id;
     if ($status) {
         $connected_device->connected = 1;
     } else {
         $connected_device->connected = 0;
     }
     $connected_device->save();
     return array($status);
 }
コード例 #9
0
ファイル: DeviceController.php プロジェクト: BooMamoo/server
 public function device($local_id)
 {
     $devices = Device::where('local_id', '=', $local_id)->get();
     return $devices;
 }
コード例 #10
0
ファイル: Device.php プロジェクト: encry2024/inv_5_2
 public static function getCountOfDefectiveDevices()
 {
     return count(Device::where('status_id', '!=', 1)->get());
 }
コード例 #11
0
ファイル: Category.php プロジェクト: encry2024/inv_5_2
 public static function fetch_devices_info_value($info_id, $category_id)
 {
     $json = [];
     $info = "";
     $devices = Device::where('category_id', $category_id)->get();
     foreach ($devices as $device) {
         foreach ($device->information as $dev_info) {
             if ($dev_info->field_id == $info_id) {
                 $json[] = ['inf_value' => $dev_info->value, 'device_name' => $device->name];
             }
         }
     }
     return json_encode($json);
 }
コード例 #12
0
ファイル: Func.php プロジェクト: bbig979/shoppyst
 public static function logAppActivity()
 {
     $user = \Auth::user();
     $device_type = '';
     $device_token = '';
     if (isset($_COOKIE['device_type'])) {
         $device_type = $_COOKIE['device_type'];
     }
     if (isset($_COOKIE['device_token'])) {
         $device_token = $_COOKIE['device_token'];
     }
     if ($device_type != 'ignore' && !empty($device_token)) {
         $device = \App\Device::where('token', $device_token)->first();
         if (empty($device)) {
             $device = new \App\Device();
             $device->user_id = $user->id;
             $device->type = $device_type;
             $device->token = $device_token;
         }
         $device->last_activity_at = date('Y-m-d H:i:s');
         $device->save();
     }
 }
コード例 #13
0
 public function show($id)
 {
     $device = \App\Device::where('id', $id)->take(1)->get();
     return response()->json($device);
 }