/** * Link new device to a user * * @param String $platform * @param Request $request * @return Response */ public function putDevice($platform, Request $request) { if (!$this->appKeyAvailable($request)) { return $this->notAuthorized($request); } if ($this->isSessionEmpty($request)) { $this->setResultError("Session token is missing", 401); } elseif (!$request->get('token') || !$request->get('udid')) { $this->setResultError("Token and UDID are both required.", 400); } elseif (strtolower($platform) != 'android' && strtolower($platform) != 'ios') { $this->setResultError("Only iOS & Android are currently supported.", 400); } elseif ($this->setSessionUser($request)) { $device = new Device(); Device::updateOrCreate(['platform' => strtolower($platform), 'udid' => $request->get('udid'), 'environment' => getenv(strtoupper($platform) . '_PUSH_ENVIRONMENT'), 'user_id' => $this->user->id], ['token' => $request->get('token')]); $device->save(); $this->setResultOk(); } else { $this->setResultError("Mismatched session token", 401); } return $this->setResponse(); }