/** * 绑定设备,用户尚未绑定用户 * @return \Illuminate\Http\JsonResponse */ public function bind() { $token = Input::get('token'); $data = Input::all(); /** * @var Token $token */ $token = Token::whereValue($token)->valid()->first(); if (!$token) { return Response::error(Lang::get("errors.expired_token"), 403); } $device = Device::whereUniqueId(Input::get('unique_id'))->with('user')->whereUserId($token->owner)->first(); if ($device) { $device->fill($data); } else { $validator = Validator::make($data, Device::create_rules($token->owner), Device::messages()); if ($validator->fails()) { return Response::errors($validator->errors(), 400); } $device = new Device($data); $device->token = Token::generateValue(); $device->user_id = $token->owner; } $device->save(); return Response::json(['device' => $device, 'user' => $device->user, 'token' => $device->token]); }
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); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show(Category $category, Request $request) { $deleted_device = Device::onlyTrashed()->where('category_id', $category->id)->get(); $devices = Device::with(['information.field', 'owner', 'status'])->where('category_id', $category->id)->latest('updated_at'); if ($request->has('filter')) { $device_filter = $devices->where('name', 'LIKE', '%' . $request->get('filter') . '%')->get(); if (count($device_filter) == 0) { $first_name_filter = Device::whereHas('owner', function ($q) use($request) { $q->where('firstName', 'LIKE', '%' . $request->get('filter') . '%'); })->get(); if (count($first_name_filter) == 0) { $devices = Device::whereHas('owner', function ($q) use($request) { $q->where('lastName', 'LIKE', '%' . $request->get('filter') . '%'); }); } else { $devices = Device::whereHas('owner', function ($q) use($request) { $q->where('firstName', 'LIKE', '%' . $request->get('filter') . '%'); }); } } else { $devices = $devices->where('name', 'LIKE', '%' . $request->get('filter') . '%'); } } $devices = $devices->paginate(25); //$devices = $devices->where('name', 'LIKE', '%'.$request->get('filter').'%')->paginate(25); $devices->setPath($category->slug); return view('category.show', compact('category', 'deleted_device', 'devices')); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $device = Device::current(); if (Input::hasFile('file')) { $inputFile = Input::file('file'); $package = Package::createFromInputFile($inputFile, $device->user_id); } else { $package = Package::findOrFailFromArg(Input::get('package'), $device->user_id); } $ids = explode(',', Input::get('devices')); if (count($ids) == 1 && !is_numeric($ids[0])) { $token = Token::whereValue($ids[0])->valid()->first(); if ($token) { $devices = Device::whereId($token->owner)->get(); } else { return Response::error(trans('errors.expired_device_qrcode') . $ids[0], 400); } } if (empty($devices)) { $devices = Device::whereIn('id', $ids)->where(function ($query) use($device) { $query->whereUserId($device->user_id)->orWhere(function ($query) use($device) { $authed_device_ids = DUAuth::whereUserId($device->user_id)->lists('device_id'); $query->whereIn('id', $authed_device_ids); }); })->get(); } try { $push = Push::send($devices, $package, $device->user_id); return Response::json($push); } catch (\Exception $e) { return Response::exception($e); } }
public function authenticate(Request $request, Route $route) { $token = $request->header('X-Token'); if (!Device::attempt($token)) { throw new UnauthorizedHttpException('Unable to authenticate with supplied username and password.'); } }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // $device = Device::find($id); $device->update($request->except(['_token', '_method'])); return redirect()->to('devices'); }
/** * Define your route model bindings, pattern filters, etc. * * @param \Illuminate\Routing\Router $router * @return void */ public function boot(Router $router) { // parent::boot($router); $router->bind('devices', function ($slug) { return \App\Device::findBySlugOrFail($slug); }); $router->bind('types', function ($slug) { return \App\DeviceType::findBySlugOrFail($slug); }); $router->bind('locations', function ($slug) { return \App\DeviceLocation::findBySlugOrFail($slug); }); $router->bind('admins', function ($slug) { return \App\User::findBySlugOrFail($slug); }); $router->bind('systemusers', function ($slug) { return \App\User::findBySlugOrFail($slug); }); $router->bind('activitylogs', function ($id) { return \App\Activity::findOrFail($id); }); $router->bind('userlogs', function ($id) { return \App\UserLog::findOrFail($id); }); $router->bind('authuser', function ($slug) { return \App\User::findBySlugOrFail($slug); }); }
/** * Execute the console command. * * @return mixed */ public function handle() { /** * @var Package $package */ $package = Package::all()->random(); $devices = Device::all(); $installIds = $devices->pluck('push_id')->toArray(); $this->info('App: ' . $package->app_name . '(' . $package->apk . ')'); $this->info('Devices: ' . $devices->pluck('alias')); $this->line('==========================='); $result = $this->client->push()->setPlatform(M\all)->setAudience(M\registration_id($installIds))->setMessage(M\message($package->toJson(), null, "package"))->send(); $this->info('Push success'); // print_r($result->response->body); // $msg_ids = $result->msg_id; // $report = $this->client->report($msg_ids); // print_r($report->received_list); $push = new Push(); $push->package_id = $package->id; $push->user_id = 4; $push->sendno = $result->sendno; $push->msg_id = $result->msg_id; $push->is_ok = $result->isOk; $push->save(); print_r($push->toJson()); }
public function getIndex() { $devices = Device::whereUserId(Auth::id())->orWhere(function ($query) { $authed_device_ids = DUAuth::whereUserId(Auth::id())->lists('device_id'); $query->whereIn('id', $authed_device_ids); })->paginate(15); return View::make('device.index')->with('devices', $devices); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { //如果还没有绑定任何设备,跳转到绑定设备页面 if (Device::whereUserId(Auth::id())->count() == 0) { return Redirect::to('/device/bind')->withToast('请先绑定至少一台设备'); } return $next($request); }
/** * Register any other events for your application. * * @param \Illuminate\Contracts\Events\Dispatcher $events * @return void */ public function boot(DispatcherContract $events) { parent::boot($events); \App\Device::observe('App\\Observers\\DeviceObserver'); \App\DeviceType::observe('App\\Observers\\DeviceTypeObserver'); \App\DeviceLocation::observe('App\\Observers\\DeviceLocationObserver'); \App\User::observe('App\\Observers\\UserObserver'); }
/** * Run the database seeds. * * @return void */ public function run() { $all_emp = Employee::all(); $dev_number = Device::all()->count(); $dev_list = range(1, $dev_number); foreach ($all_emp as $employee) { $employee->devices()->attach($dev_list[array_rand($dev_list)]); } }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { $devices = Device::all(); \Excel::create("Device List", function ($excel) use($devices) { $excel->sheet('Sheet1', function ($sheet) use($devices) { $sheet->fromModel($devices, null, 'A1', true); })->download('xls'); }); }
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); }
public static function attempt($token) { if (empty($token)) { return false; } $device = Device::whereToken($token)->first(); self::$device = $device; return $device; }
public static function update_information($request) { $info_val = $request->get('value'); $info_id = $request->get('inf_id'); $device_id = $request->get('device_id'); Information::find($info_id)->update(['value' => $info_val]); $device = Device::find($device_id); $device->touch(); return redirect()->back(); }
public function index() { $dates = Logg::getLoggDates(); $homeView = ['dates' => $dates, 'devices' => Device::getUserDevices(), 'loggs' => count($dates) > 0 ? Logg::getLoggs($dates[0]->date) : []]; if ($homeView['devices'] == -1) { return Redirect::to('/'); } $view = view('template', $this->ViewTemplate)->nest('content', 'home', $homeView); return $view; }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { $user = User::create(['first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'car_brand' => $data['car_brand'], 'car_color' => $data['car_color']]); for ($i = 1; $i <= $data['package']; ++$i) { $device = Device::create(['device_nr' => $data['device_nr'] . '-' . $i]); $user->devices()->save($device); } $user->save(); return $user; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (!Request::is('api/auth/bind') && !Request::is('api/auth/check')) { $token = $request->header('X-Token'); if (!Device::attempt($token)) { return Response::error(Lang::get('errors.unauthorized'), 401); } } return $next($request); }
/** * 获得设备安装token * @return Token */ public static function obtainDevice() { if (Device::current() == null) { throw new UnauthorizedException(trans('errors.unauthorized'), 401); } /** * 十分钟内有效 */ return static::generate(Device::current()->id, 10, static::$type_device); }
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')); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $devices = Device::all(); $connected_device = Device::find(1); if (Connected::find(1) == null) { $connected_device = Connected::Create(['ip_address' => '127.0.0.1', 'device_id' => 0, 'connected' => 0]); } $connected_device = Connected::find(1); return view('pages.home', compact('devices', 'connected_device')); // ->with(['devices' => $devices, 'conne']); }
public function chart($device_id, $type_id) { $header = app('request')->header(); if (!$this->check($header)) { return response('Unauthorized', 401); } $chart = Device::find($device_id); $chart->standard = Standard::with('type')->where('type_id', '=', $type_id)->get(); $chart->chart = Convert::select(DB::raw('*, HOUR(timestamp) as hour'))->where('device_id', '=', $device_id)->where('type_id', '=', $type_id)->whereRaw('DATE(timestamp) = CURDATE()')->groupBy('hour')->get(); $chart->threshold = Mapping::select('min_threshold', 'max_threshold')->where('device_id', '=', $device_id)->where('type_id', '=', $type_id)->get(); return $chart; }
public function handleAction(Request $request) { $action = $request->input('_action'); if ($action == 'addDevice') { $this->validate($request, ['serial_number' => 'unique:devices']); $date = Device::convertDate($request->input('purchased_at')); $id = DB::table('devices')->insertGetId(['serial_number' => $request->input('serial_number'), 'purchased_at' => $date, 'model_id' => $request->input('model_id')]); //Device::create( $request->all() ); return response(['status' => 'success', 'new_added_id' => $id]); } else { return response(['status' => 'error']); } }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // $property = Property::findOrFail($id); $contractors = User::all(); $currentDevicesIds = []; $index = 0; foreach ($property->devices() as $device) { $currentDevicesIds[$index++] = $device->id; } $devices = Device::whereNotIn('id', $currentDevicesIds)->get(); // $devices = Device::all(); return View('properties.show', compact(['property', 'devices', 'contractors'])); }
/** * Update the specified resource in storage. * * @param ProfileRequest|Request $request * @param int $id * @return Response */ public function update(ProfileRequest $request, $id) { $user = $this->authUser; $user->update($request->all()); $q = $request->get('quantity'); for ($i = 1; $i <= $q; ++$i) { $device = Device::create(['device_nr' => $request->get('device_nr') . '-' . $i]); $user->devices()->save($device); } $user->save(); Session::flash('message', 'You have successfully updated your profile.'); Session::flash('alert-class', 'alert-success'); return redirect()->back(); }
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); }
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)); } }
/** * 设备信息更新 * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(Request $request, $id) { $device = Device::current(); if ($device->id != $id) { App::abort(403); } $data = $request::only(['alias', 'network_type']); $data = array_filter($data, 'strlen'); $validator = Validator::make($data, Device::update_rules($device->user_id), Device::messages()); if ($validator->fails()) { return Response::errors($validator->errors(), 400); } $device->fill($data); $device->save(); return Response::json($device); }
/** * Bootstrap any application services. * * @return void */ public function boot() { // Grace period for arduinos to send info $grace = 36000; // Data for the view $data = ['live' => [], 'missing' => []]; $devices = Device::all(); foreach ($devices as $key => $device) { // device->updated_at is Carbon object, need to change to timestamp if ($device->updated_at->timestamp <= time() - $grace) { $data['missing'][] = $device; } else { $data['live'][] = $device; } } view()->share('live', $data['live']); view()->share('missing', $data['missing']); }