@@ -7,37 +7,37 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Handler extends ExceptionHandler |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * A list of the exception types that should not be reported. |
|
| 12 | - * |
|
| 13 | - * @var array |
|
| 14 | - */ |
|
| 15 | - protected $dontReport = [ |
|
| 16 | - 'Symfony\Component\HttpKernel\Exception\HttpException', |
|
| 17 | - ]; |
|
| 10 | + /** |
|
| 11 | + * A list of the exception types that should not be reported. |
|
| 12 | + * |
|
| 13 | + * @var array |
|
| 14 | + */ |
|
| 15 | + protected $dontReport = [ |
|
| 16 | + 'Symfony\Component\HttpKernel\Exception\HttpException', |
|
| 17 | + ]; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Report or log an exception. |
|
| 21 | - * |
|
| 22 | - * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
|
| 23 | - * |
|
| 24 | - * @param \Exception $e |
|
| 25 | - */ |
|
| 26 | - public function report(Exception $e) |
|
| 27 | - { |
|
| 28 | - return parent::report($e); |
|
| 29 | - } |
|
| 19 | + /** |
|
| 20 | + * Report or log an exception. |
|
| 21 | + * |
|
| 22 | + * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
|
| 23 | + * |
|
| 24 | + * @param \Exception $e |
|
| 25 | + */ |
|
| 26 | + public function report(Exception $e) |
|
| 27 | + { |
|
| 28 | + return parent::report($e); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Render an exception into an HTTP response. |
|
| 33 | - * |
|
| 34 | - * @param \Illuminate\Http\Request $request |
|
| 35 | - * @param \Exception $e |
|
| 36 | - * |
|
| 37 | - * @return \Illuminate\Http\Response |
|
| 38 | - */ |
|
| 39 | - public function render($request, Exception $e) |
|
| 40 | - { |
|
| 41 | - return parent::render($request, $e); |
|
| 42 | - } |
|
| 31 | + /** |
|
| 32 | + * Render an exception into an HTTP response. |
|
| 33 | + * |
|
| 34 | + * @param \Illuminate\Http\Request $request |
|
| 35 | + * @param \Exception $e |
|
| 36 | + * |
|
| 37 | + * @return \Illuminate\Http\Response |
|
| 38 | + */ |
|
| 39 | + public function render($request, Exception $e) |
|
| 40 | + { |
|
| 41 | + return parent::render($request, $e); |
|
| 42 | + } |
|
| 43 | 43 | } |
@@ -7,41 +7,41 @@ |
||
| 7 | 7 | |
| 8 | 8 | class NotifyUsersAboutPoke |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * The Pusher instance. |
|
| 12 | - * |
|
| 13 | - * @var PusherManager |
|
| 14 | - */ |
|
| 15 | - protected $pusher; |
|
| 10 | + /** |
|
| 11 | + * The Pusher instance. |
|
| 12 | + * |
|
| 13 | + * @var PusherManager |
|
| 14 | + */ |
|
| 15 | + protected $pusher; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Create the event handler. |
|
| 19 | - * |
|
| 20 | - * @param PusherManager $pusher |
|
| 21 | - */ |
|
| 22 | - public function __construct(PusherManager $pusher) |
|
| 23 | - { |
|
| 24 | - $this->pusher = $pusher; |
|
| 25 | - } |
|
| 17 | + /** |
|
| 18 | + * Create the event handler. |
|
| 19 | + * |
|
| 20 | + * @param PusherManager $pusher |
|
| 21 | + */ |
|
| 22 | + public function __construct(PusherManager $pusher) |
|
| 23 | + { |
|
| 24 | + $this->pusher = $pusher; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Handle the server was poked event. |
|
| 29 | - * |
|
| 30 | - * @param ServerWasPoked $event |
|
| 31 | - * |
|
| 32 | - * @return void |
|
| 33 | - */ |
|
| 34 | - public function handle(ServerWasPoked $event) |
|
| 35 | - { |
|
| 36 | - $channel = env('PUSHER_CHANNEL', 'pi-finder'); |
|
| 37 | - $device = $event->getDevice(); |
|
| 27 | + /** |
|
| 28 | + * Handle the server was poked event. |
|
| 29 | + * |
|
| 30 | + * @param ServerWasPoked $event |
|
| 31 | + * |
|
| 32 | + * @return void |
|
| 33 | + */ |
|
| 34 | + public function handle(ServerWasPoked $event) |
|
| 35 | + { |
|
| 36 | + $channel = env('PUSHER_CHANNEL', 'pi-finder'); |
|
| 37 | + $device = $event->getDevice(); |
|
| 38 | 38 | |
| 39 | - if ($device->isPublic()) { |
|
| 40 | - $this->pusher->trigger($channel, 'ServerWasPoked', ['device' => $device->toArray()]); |
|
| 41 | - } else { |
|
| 42 | - $channel = $channel.'-'.$device->group; |
|
| 39 | + if ($device->isPublic()) { |
|
| 40 | + $this->pusher->trigger($channel, 'ServerWasPoked', ['device' => $device->toArray()]); |
|
| 41 | + } else { |
|
| 42 | + $channel = $channel.'-'.$device->group; |
|
| 43 | 43 | |
| 44 | - $this->pusher->trigger($channel, 'ServerWasPoked', ['device' => $device->toArray()]); |
|
| 45 | - } |
|
| 46 | - } |
|
| 44 | + $this->pusher->trigger($channel, 'ServerWasPoked', ['device' => $device->toArray()]); |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -39,7 +39,7 @@ |
||
| 39 | 39 | if ($device->isPublic()) { |
| 40 | 40 | $this->pusher->trigger($channel, 'ServerWasPoked', ['device' => $device->toArray()]); |
| 41 | 41 | } else { |
| 42 | - $channel = $channel.'-'.$device->group; |
|
| 42 | + $channel = $channel . '-' . $device->group; |
|
| 43 | 43 | |
| 44 | 44 | $this->pusher->trigger($channel, 'ServerWasPoked', ['device' => $device->toArray()]); |
| 45 | 45 | } |
@@ -7,15 +7,15 @@ |
||
| 7 | 7 | |
| 8 | 8 | class UpdateStatistics |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * Handle the event. |
|
| 12 | - * |
|
| 13 | - * @param ServerWasPoked $event |
|
| 14 | - * |
|
| 15 | - * @return void |
|
| 16 | - */ |
|
| 17 | - public function handle(ServerWasPoked $event) |
|
| 18 | - { |
|
| 19 | - Poke::create($event->getDevice()->toArray()); |
|
| 20 | - } |
|
| 10 | + /** |
|
| 11 | + * Handle the event. |
|
| 12 | + * |
|
| 13 | + * @param ServerWasPoked $event |
|
| 14 | + * |
|
| 15 | + * @return void |
|
| 16 | + */ |
|
| 17 | + public function handle(ServerWasPoked $event) |
|
| 18 | + { |
|
| 19 | + Poke::create($event->getDevice()->toArray()); |
|
| 20 | + } |
|
| 21 | 21 | } |
@@ -7,102 +7,102 @@ |
||
| 7 | 7 | |
| 8 | 8 | class ApiController extends Controller |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * Default Status Code. |
|
| 12 | - * |
|
| 13 | - * @var int |
|
| 14 | - */ |
|
| 15 | - protected $statusCode = 200; |
|
| 10 | + /** |
|
| 11 | + * Default Status Code. |
|
| 12 | + * |
|
| 13 | + * @var int |
|
| 14 | + */ |
|
| 15 | + protected $statusCode = 200; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @return int |
|
| 19 | - */ |
|
| 20 | - public function getStatusCode() |
|
| 21 | - { |
|
| 22 | - return $this->statusCode; |
|
| 23 | - } |
|
| 17 | + /** |
|
| 18 | + * @return int |
|
| 19 | + */ |
|
| 20 | + public function getStatusCode() |
|
| 21 | + { |
|
| 22 | + return $this->statusCode; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @param int $statusCode |
|
| 27 | - * |
|
| 28 | - * @return $this |
|
| 29 | - */ |
|
| 30 | - public function setStatusCode($statusCode) |
|
| 31 | - { |
|
| 32 | - $this->statusCode = $statusCode; |
|
| 25 | + /** |
|
| 26 | + * @param int $statusCode |
|
| 27 | + * |
|
| 28 | + * @return $this |
|
| 29 | + */ |
|
| 30 | + public function setStatusCode($statusCode) |
|
| 31 | + { |
|
| 32 | + $this->statusCode = $statusCode; |
|
| 33 | 33 | |
| 34 | - return $this; |
|
| 35 | - } |
|
| 34 | + return $this; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param array $data |
|
| 39 | - * |
|
| 40 | - * @return mixed |
|
| 41 | - */ |
|
| 42 | - public function respondCreated($data, $id) |
|
| 43 | - { |
|
| 44 | - $headers = [ |
|
| 45 | - 'Location' => route('api.v1.devices.show', $id), |
|
| 46 | - ]; |
|
| 37 | + /** |
|
| 38 | + * @param array $data |
|
| 39 | + * |
|
| 40 | + * @return mixed |
|
| 41 | + */ |
|
| 42 | + public function respondCreated($data, $id) |
|
| 43 | + { |
|
| 44 | + $headers = [ |
|
| 45 | + 'Location' => route('api.v1.devices.show', $id), |
|
| 46 | + ]; |
|
| 47 | 47 | |
| 48 | - return $this->setStatusCode(201)->respond(compact('data'), $headers); |
|
| 49 | - } |
|
| 48 | + return $this->setStatusCode(201)->respond(compact('data'), $headers); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param array $data |
|
| 53 | - * |
|
| 54 | - * @return mixed |
|
| 55 | - */ |
|
| 56 | - public function respondPoked($data, $id) |
|
| 57 | - { |
|
| 58 | - $headers = [ |
|
| 59 | - 'Location' => route('api.v1.devices.show', $id), |
|
| 60 | - ]; |
|
| 51 | + /** |
|
| 52 | + * @param array $data |
|
| 53 | + * |
|
| 54 | + * @return mixed |
|
| 55 | + */ |
|
| 56 | + public function respondPoked($data, $id) |
|
| 57 | + { |
|
| 58 | + $headers = [ |
|
| 59 | + 'Location' => route('api.v1.devices.show', $id), |
|
| 60 | + ]; |
|
| 61 | 61 | |
| 62 | - return $this->setStatusCode(200)->respond(compact('data'), $headers); |
|
| 63 | - } |
|
| 62 | + return $this->setStatusCode(200)->respond(compact('data'), $headers); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @return mixed |
|
| 67 | - */ |
|
| 68 | - public function respondNoContent() |
|
| 69 | - { |
|
| 70 | - return $this->setStatusCode(204)->respond([]); |
|
| 71 | - } |
|
| 65 | + /** |
|
| 66 | + * @return mixed |
|
| 67 | + */ |
|
| 68 | + public function respondNoContent() |
|
| 69 | + { |
|
| 70 | + return $this->setStatusCode(204)->respond([]); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @param string $message |
|
| 75 | - * |
|
| 76 | - * @return mixed |
|
| 77 | - */ |
|
| 78 | - public function respondNotFound($message = 'Did not find the resource you are looking for!') |
|
| 79 | - { |
|
| 80 | - return $this->setStatusCode(404)->respondWithError($message); |
|
| 81 | - } |
|
| 73 | + /** |
|
| 74 | + * @param string $message |
|
| 75 | + * |
|
| 76 | + * @return mixed |
|
| 77 | + */ |
|
| 78 | + public function respondNotFound($message = 'Did not find the resource you are looking for!') |
|
| 79 | + { |
|
| 80 | + return $this->setStatusCode(404)->respondWithError($message); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * @param $data |
|
| 85 | - * @param array $headers |
|
| 86 | - * |
|
| 87 | - * @return mixed |
|
| 88 | - */ |
|
| 89 | - public function respond($data, $headers = []) |
|
| 90 | - { |
|
| 91 | - return Response::json($data, $this->getStatusCode(), $headers); |
|
| 92 | - } |
|
| 83 | + /** |
|
| 84 | + * @param $data |
|
| 85 | + * @param array $headers |
|
| 86 | + * |
|
| 87 | + * @return mixed |
|
| 88 | + */ |
|
| 89 | + public function respond($data, $headers = []) |
|
| 90 | + { |
|
| 91 | + return Response::json($data, $this->getStatusCode(), $headers); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @param $message |
|
| 96 | - * |
|
| 97 | - * @return mixed |
|
| 98 | - */ |
|
| 99 | - public function respondWithError($message) |
|
| 100 | - { |
|
| 101 | - return $this->respond([ |
|
| 102 | - 'errors' => [ |
|
| 103 | - 'title' => $message, |
|
| 104 | - 'status' => $this->getStatusCode(), |
|
| 105 | - ], |
|
| 106 | - ]); |
|
| 107 | - } |
|
| 94 | + /** |
|
| 95 | + * @param $message |
|
| 96 | + * |
|
| 97 | + * @return mixed |
|
| 98 | + */ |
|
| 99 | + public function respondWithError($message) |
|
| 100 | + { |
|
| 101 | + return $this->respond([ |
|
| 102 | + 'errors' => [ |
|
| 103 | + 'title' => $message, |
|
| 104 | + 'status' => $this->getStatusCode(), |
|
| 105 | + ], |
|
| 106 | + ]); |
|
| 107 | + } |
|
| 108 | 108 | } |
@@ -10,135 +10,135 @@ |
||
| 10 | 10 | |
| 11 | 11 | class DeviceController extends ApiController |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @var DeviceTransformer |
|
| 15 | - */ |
|
| 16 | - private $transformer; |
|
| 17 | - |
|
| 18 | - public function __construct(DeviceTransformer $transformer) |
|
| 19 | - { |
|
| 20 | - $this->middleware('auth.basic', ['except' => ['poke', 'show']]); |
|
| 21 | - |
|
| 22 | - $this->transformer = $transformer; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Display a listing of the resource. |
|
| 27 | - * |
|
| 28 | - * @return Response |
|
| 29 | - */ |
|
| 30 | - public function index() |
|
| 31 | - { |
|
| 32 | - $devices = Device::all(); |
|
| 33 | - |
|
| 34 | - return $this->respond([ |
|
| 35 | - 'data' => $this->transformer->transformCollection($devices->all()), |
|
| 36 | - ]); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Store a newly created resource in storage. |
|
| 41 | - * |
|
| 42 | - * @param StoreComputerRequest $request |
|
| 43 | - * |
|
| 44 | - * @return Response |
|
| 45 | - */ |
|
| 46 | - public function store(StoreComputerRequest $request) |
|
| 47 | - { |
|
| 48 | - $device = Device::create($request->all()); |
|
| 49 | - |
|
| 50 | - $device->public = $request->get('public', 'auto'); |
|
| 51 | - |
|
| 52 | - return $this->respondCreated($this->transformer->transform($device), $device->id); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Display the specified resource. |
|
| 57 | - * |
|
| 58 | - * @param int $id |
|
| 59 | - * |
|
| 60 | - * @return Response |
|
| 61 | - */ |
|
| 62 | - public function show($id) |
|
| 63 | - { |
|
| 64 | - $device = Device::find($id); |
|
| 65 | - |
|
| 66 | - if (!$device) { |
|
| 67 | - return $this->respondNotFound('Did not find the device you are looking for!'); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - return $this->respond([ |
|
| 71 | - 'data' => $this->transformer->transform($device), |
|
| 72 | - ]); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Update the specified resource in storage. |
|
| 77 | - * |
|
| 78 | - * @param StoreComputerRequest $request |
|
| 79 | - * @param int $id |
|
| 80 | - * |
|
| 81 | - * @return Response |
|
| 82 | - */ |
|
| 83 | - public function update(StoreComputerRequest $request, $id) |
|
| 84 | - { |
|
| 85 | - $device = Device::find($id); |
|
| 86 | - |
|
| 87 | - if (!$device) { |
|
| 88 | - return $this->respondNotFound('Did not find the device you are looking for!'); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $device = $device->fill($request->all()); |
|
| 92 | - |
|
| 93 | - $device->save(); |
|
| 94 | - |
|
| 95 | - return $this->respond([ |
|
| 96 | - 'data' => $this->transformer->transform($device), |
|
| 97 | - ]); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Remove the specified resource from storage. |
|
| 102 | - * |
|
| 103 | - * @param int $id |
|
| 104 | - * |
|
| 105 | - * @return Response |
|
| 106 | - */ |
|
| 107 | - public function destroy($id) |
|
| 108 | - { |
|
| 109 | - $device = Device::find($id); |
|
| 110 | - |
|
| 111 | - if (!$device) { |
|
| 112 | - return $this->respondNotFound('Did not find the device you are looking for!'); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $device->delete(); |
|
| 116 | - |
|
| 117 | - return $this->respondNoContent(); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Handle device pokes. |
|
| 122 | - * |
|
| 123 | - * @param StoreComputerRequest $request |
|
| 124 | - * |
|
| 125 | - * @throws \Exception |
|
| 126 | - * |
|
| 127 | - * @return Response |
|
| 128 | - */ |
|
| 129 | - public function poke(StoreComputerRequest $request) |
|
| 130 | - { |
|
| 131 | - $device = Device::firstOrNew(['mac' => $request->mac]); |
|
| 132 | - |
|
| 133 | - $device->fill($request->all()); |
|
| 134 | - |
|
| 135 | - $device->group = $request->get('group', null); |
|
| 136 | - $device->public = $request->get('public', 'auto'); |
|
| 137 | - |
|
| 138 | - $device->touch(); |
|
| 139 | - |
|
| 140 | - event(new ServerWasPoked(array_add($device, 'server_time', Carbon::now()->toDateTimeString()))); |
|
| 141 | - |
|
| 142 | - return $this->respondPoked($this->transformer->transform($device), $device->id); |
|
| 143 | - } |
|
| 13 | + /** |
|
| 14 | + * @var DeviceTransformer |
|
| 15 | + */ |
|
| 16 | + private $transformer; |
|
| 17 | + |
|
| 18 | + public function __construct(DeviceTransformer $transformer) |
|
| 19 | + { |
|
| 20 | + $this->middleware('auth.basic', ['except' => ['poke', 'show']]); |
|
| 21 | + |
|
| 22 | + $this->transformer = $transformer; |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Display a listing of the resource. |
|
| 27 | + * |
|
| 28 | + * @return Response |
|
| 29 | + */ |
|
| 30 | + public function index() |
|
| 31 | + { |
|
| 32 | + $devices = Device::all(); |
|
| 33 | + |
|
| 34 | + return $this->respond([ |
|
| 35 | + 'data' => $this->transformer->transformCollection($devices->all()), |
|
| 36 | + ]); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Store a newly created resource in storage. |
|
| 41 | + * |
|
| 42 | + * @param StoreComputerRequest $request |
|
| 43 | + * |
|
| 44 | + * @return Response |
|
| 45 | + */ |
|
| 46 | + public function store(StoreComputerRequest $request) |
|
| 47 | + { |
|
| 48 | + $device = Device::create($request->all()); |
|
| 49 | + |
|
| 50 | + $device->public = $request->get('public', 'auto'); |
|
| 51 | + |
|
| 52 | + return $this->respondCreated($this->transformer->transform($device), $device->id); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Display the specified resource. |
|
| 57 | + * |
|
| 58 | + * @param int $id |
|
| 59 | + * |
|
| 60 | + * @return Response |
|
| 61 | + */ |
|
| 62 | + public function show($id) |
|
| 63 | + { |
|
| 64 | + $device = Device::find($id); |
|
| 65 | + |
|
| 66 | + if (!$device) { |
|
| 67 | + return $this->respondNotFound('Did not find the device you are looking for!'); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + return $this->respond([ |
|
| 71 | + 'data' => $this->transformer->transform($device), |
|
| 72 | + ]); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Update the specified resource in storage. |
|
| 77 | + * |
|
| 78 | + * @param StoreComputerRequest $request |
|
| 79 | + * @param int $id |
|
| 80 | + * |
|
| 81 | + * @return Response |
|
| 82 | + */ |
|
| 83 | + public function update(StoreComputerRequest $request, $id) |
|
| 84 | + { |
|
| 85 | + $device = Device::find($id); |
|
| 86 | + |
|
| 87 | + if (!$device) { |
|
| 88 | + return $this->respondNotFound('Did not find the device you are looking for!'); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $device = $device->fill($request->all()); |
|
| 92 | + |
|
| 93 | + $device->save(); |
|
| 94 | + |
|
| 95 | + return $this->respond([ |
|
| 96 | + 'data' => $this->transformer->transform($device), |
|
| 97 | + ]); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Remove the specified resource from storage. |
|
| 102 | + * |
|
| 103 | + * @param int $id |
|
| 104 | + * |
|
| 105 | + * @return Response |
|
| 106 | + */ |
|
| 107 | + public function destroy($id) |
|
| 108 | + { |
|
| 109 | + $device = Device::find($id); |
|
| 110 | + |
|
| 111 | + if (!$device) { |
|
| 112 | + return $this->respondNotFound('Did not find the device you are looking for!'); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $device->delete(); |
|
| 116 | + |
|
| 117 | + return $this->respondNoContent(); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Handle device pokes. |
|
| 122 | + * |
|
| 123 | + * @param StoreComputerRequest $request |
|
| 124 | + * |
|
| 125 | + * @throws \Exception |
|
| 126 | + * |
|
| 127 | + * @return Response |
|
| 128 | + */ |
|
| 129 | + public function poke(StoreComputerRequest $request) |
|
| 130 | + { |
|
| 131 | + $device = Device::firstOrNew(['mac' => $request->mac]); |
|
| 132 | + |
|
| 133 | + $device->fill($request->all()); |
|
| 134 | + |
|
| 135 | + $device->group = $request->get('group', null); |
|
| 136 | + $device->public = $request->get('public', 'auto'); |
|
| 137 | + |
|
| 138 | + $device->touch(); |
|
| 139 | + |
|
| 140 | + event(new ServerWasPoked(array_add($device, 'server_time', Carbon::now()->toDateTimeString()))); |
|
| 141 | + |
|
| 142 | + return $this->respondPoked($this->transformer->transform($device), $device->id); |
|
| 143 | + } |
|
| 144 | 144 | } |
@@ -8,5 +8,5 @@ |
||
| 8 | 8 | |
| 9 | 9 | abstract class Controller extends BaseController |
| 10 | 10 | { |
| 11 | - use DispatchesCommands, ValidatesRequests; |
|
| 11 | + use DispatchesCommands, ValidatesRequests; |
|
| 12 | 12 | } |
@@ -6,28 +6,28 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Kernel extends HttpKernel |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * The application's global HTTP middleware stack. |
|
| 11 | - * |
|
| 12 | - * @var array |
|
| 13 | - */ |
|
| 14 | - protected $middleware = [ |
|
| 15 | - 'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode', |
|
| 16 | - 'Illuminate\Cookie\Middleware\EncryptCookies', |
|
| 17 | - 'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse', |
|
| 18 | - 'Illuminate\Session\Middleware\StartSession', |
|
| 19 | - 'Illuminate\View\Middleware\ShareErrorsFromSession', |
|
| 20 | - 'PiFinder\Http\Middleware\VerifyCsrfToken', |
|
| 21 | - ]; |
|
| 9 | + /** |
|
| 10 | + * The application's global HTTP middleware stack. |
|
| 11 | + * |
|
| 12 | + * @var array |
|
| 13 | + */ |
|
| 14 | + protected $middleware = [ |
|
| 15 | + 'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode', |
|
| 16 | + 'Illuminate\Cookie\Middleware\EncryptCookies', |
|
| 17 | + 'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse', |
|
| 18 | + 'Illuminate\Session\Middleware\StartSession', |
|
| 19 | + 'Illuminate\View\Middleware\ShareErrorsFromSession', |
|
| 20 | + 'PiFinder\Http\Middleware\VerifyCsrfToken', |
|
| 21 | + ]; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * The application's route middleware. |
|
| 25 | - * |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - protected $routeMiddleware = [ |
|
| 29 | - 'auth' => 'PiFinder\Http\Middleware\Authenticate', |
|
| 30 | - 'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth', |
|
| 31 | - 'guest' => 'PiFinder\Http\Middleware\RedirectIfAuthenticated', |
|
| 32 | - ]; |
|
| 23 | + /** |
|
| 24 | + * The application's route middleware. |
|
| 25 | + * |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + protected $routeMiddleware = [ |
|
| 29 | + 'auth' => 'PiFinder\Http\Middleware\Authenticate', |
|
| 30 | + 'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth', |
|
| 31 | + 'guest' => 'PiFinder\Http\Middleware\RedirectIfAuthenticated', |
|
| 32 | + ]; |
|
| 33 | 33 | } |
@@ -7,41 +7,41 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Authenticate |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * The Guard implementation. |
|
| 12 | - * |
|
| 13 | - * @var Guard |
|
| 14 | - */ |
|
| 15 | - protected $auth; |
|
| 10 | + /** |
|
| 11 | + * The Guard implementation. |
|
| 12 | + * |
|
| 13 | + * @var Guard |
|
| 14 | + */ |
|
| 15 | + protected $auth; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Create a new filter instance. |
|
| 19 | - * |
|
| 20 | - * @param Guard $auth |
|
| 21 | - */ |
|
| 22 | - public function __construct(Guard $auth) |
|
| 23 | - { |
|
| 24 | - $this->auth = $auth; |
|
| 25 | - } |
|
| 17 | + /** |
|
| 18 | + * Create a new filter instance. |
|
| 19 | + * |
|
| 20 | + * @param Guard $auth |
|
| 21 | + */ |
|
| 22 | + public function __construct(Guard $auth) |
|
| 23 | + { |
|
| 24 | + $this->auth = $auth; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Handle an incoming request. |
|
| 29 | - * |
|
| 30 | - * @param \Illuminate\Http\Request $request |
|
| 31 | - * @param \Closure $next |
|
| 32 | - * |
|
| 33 | - * @return mixed |
|
| 34 | - */ |
|
| 35 | - public function handle($request, Closure $next) |
|
| 36 | - { |
|
| 37 | - if ($this->auth->guest()) { |
|
| 38 | - if ($request->ajax()) { |
|
| 39 | - return response('Unauthorized.', 401); |
|
| 40 | - } else { |
|
| 41 | - return redirect()->guest('auth/login'); |
|
| 42 | - } |
|
| 43 | - } |
|
| 27 | + /** |
|
| 28 | + * Handle an incoming request. |
|
| 29 | + * |
|
| 30 | + * @param \Illuminate\Http\Request $request |
|
| 31 | + * @param \Closure $next |
|
| 32 | + * |
|
| 33 | + * @return mixed |
|
| 34 | + */ |
|
| 35 | + public function handle($request, Closure $next) |
|
| 36 | + { |
|
| 37 | + if ($this->auth->guest()) { |
|
| 38 | + if ($request->ajax()) { |
|
| 39 | + return response('Unauthorized.', 401); |
|
| 40 | + } else { |
|
| 41 | + return redirect()->guest('auth/login'); |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - return $next($request); |
|
| 46 | - } |
|
| 45 | + return $next($request); |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -8,37 +8,37 @@ |
||
| 8 | 8 | |
| 9 | 9 | class RedirectIfAuthenticated |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * The Guard implementation. |
|
| 13 | - * |
|
| 14 | - * @var Guard |
|
| 15 | - */ |
|
| 16 | - protected $auth; |
|
| 11 | + /** |
|
| 12 | + * The Guard implementation. |
|
| 13 | + * |
|
| 14 | + * @var Guard |
|
| 15 | + */ |
|
| 16 | + protected $auth; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Create a new filter instance. |
|
| 20 | - * |
|
| 21 | - * @param Guard $auth |
|
| 22 | - */ |
|
| 23 | - public function __construct(Guard $auth) |
|
| 24 | - { |
|
| 25 | - $this->auth = $auth; |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * Create a new filter instance. |
|
| 20 | + * |
|
| 21 | + * @param Guard $auth |
|
| 22 | + */ |
|
| 23 | + public function __construct(Guard $auth) |
|
| 24 | + { |
|
| 25 | + $this->auth = $auth; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Handle an incoming request. |
|
| 30 | - * |
|
| 31 | - * @param \Illuminate\Http\Request $request |
|
| 32 | - * @param \Closure $next |
|
| 33 | - * |
|
| 34 | - * @return mixed |
|
| 35 | - */ |
|
| 36 | - public function handle($request, Closure $next) |
|
| 37 | - { |
|
| 38 | - if ($this->auth->check()) { |
|
| 39 | - return new RedirectResponse(url('/home')); |
|
| 40 | - } |
|
| 28 | + /** |
|
| 29 | + * Handle an incoming request. |
|
| 30 | + * |
|
| 31 | + * @param \Illuminate\Http\Request $request |
|
| 32 | + * @param \Closure $next |
|
| 33 | + * |
|
| 34 | + * @return mixed |
|
| 35 | + */ |
|
| 36 | + public function handle($request, Closure $next) |
|
| 37 | + { |
|
| 38 | + if ($this->auth->check()) { |
|
| 39 | + return new RedirectResponse(url('/home')); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - return $next($request); |
|
| 43 | - } |
|
| 42 | + return $next($request); |
|
| 43 | + } |
|
| 44 | 44 | } |