/**
  * Detect timezone for coord
  * @author zbrown
  *
  * @param Request $requestObject
  */
 public function distanceAction(Request $requestObject)
 {
     $calculateModel = new CalculateModel();
     $apiRequest = $calculateModel->prepareRequestData($requestObject, 'detectTimezone');
     if (!$apiRequest instanceof ApiRequestObject) {
         new JsonResponse(ResponseHelper::prepareResponse($apiRequest['status'], $apiRequest['reason'], $apiRequest['msg']));
     }
     $dataTimezone = $calculateModel->calculateDistance($apiRequest);
     new JsonResponse(ResponseHelper::prepareResponse(Strings::API_STATUS_SUCCESS, Strings::API_REASON_SUCCESS, Strings::API_MSG_SUCCESS, $dataTimezone));
 }
 public function countryAction(Request $requestObject)
 {
     $detectionModel = $this->get('detection_model');
     $apiRequest = $detectionModel->prepareRequestData($requestObject, 'detectTimezone');
     if (!$apiRequest instanceof ApiRequestObject) {
         return new JsonResponse(ResponseHelper::prepareResponse($apiRequest['status'], $apiRequest['reason'], $apiRequest['msg']));
     }
     $dataCountry = $detectionModel->detectCountry($apiRequest);
     return new JsonResponse(ResponseHelper::prepareResponse(Strings::API_STATUS_SUCCESS, Strings::API_REASON_SUCCESS, Strings::API_MSG_SUCCESS, $dataCountry));
 }
 /**
  * Reverse geocode coords
  * @auhtor zbrown
  *
  * @param Request $requestObject
  */
 public function reverseAction(Request $requestObject)
 {
     $geocodeModel = new GeocodeModel();
     $apiRequest = $geocodeModel->prepareRequestData($requestObject, 'reverseGeocode');
     if (!$apiRequest instanceof ApiRequestObject) {
         ResponseHelper::prepareResponse($apiRequest['status'], $apiRequest['reason'], $apiRequest['msg']);
     }
     $dataReverse = $geocodeModel->reverseGeocode($apiRequest);
     ResponseHelper::prepareResponse(Strings::API_STATUS_SUCCESS, Strings::API_REASON_SUCCESS, Strings::API_MSG_SUCCESS, $dataReverse);
 }
 /**
  * Create new API session token
  * @author zbrown
  *
  * @param Request $requestObject
  * @return JsonResponse
  */
 public function sessionAction(Request $requestObject)
 {
     $authModel = $this->get('authenticate_model');
     $apiRequest = $authModel->prepareRequestData($requestObject, 'authenticate');
     if (!$apiRequest instanceof ApiRequestObject) {
         return new JsonResponse(ResponseHelper::prepareResponse($apiRequest['status'], $apiRequest['reason'], $apiRequest['msg']));
     }
     $applicationObject = $authModel->getApplicationObject($apiRequest);
     if (is_null($applicationObject)) {
         return new JsonResponse(ResponseHelper::prepareResponse(Strings::API_STATUS_FATAL, Strings::API_REASON_FORBIDDEN, Strings::API_MSG_MISSING_CREDENTIALS));
     }
     if ($applicationObject->getAssoc() === null) {
         return new JsonResponse(ResponseHelper::prepareResponse(Strings::API_STATUS_FATAL, Strings::API_REASON_APP_CONVERSION, Strings::API_MSG_APP_CONVERSION_REQUIRED));
     }
     $appId = $applicationObject->getId();
     $appStatus = $applicationObject->getStatus();
     if ($appStatus != 'Active') {
         return new JsonResponse(ResponseHelper::prepareResponse(Strings::API_STATUS_FATAL, Strings::API_REASON_FORBIDDEN, Strings::API_MSG_REVOKED_CREDENTIALS));
     }
     $sessionToken = $authModel->persistNewAppSession($apiRequest, $appId);
     $payload = array('session' => $sessionToken);
     return new JsonResponse(ResponseHelper::prepareResponse(Strings::API_STATUS_SUCCESS, Strings::API_REASON_SUCCESS, Strings::API_MSG_SUCCESS, $payload));
 }
Esempio n. 5
0
 /**
  * Reset API keyset
  * @author zbrown
  *
  * @param Request $request
  * @return JsonResponse
  */
 public function resetKeysAction(Request $request)
 {
     $postData = $this->get('request')->request->all();
     $apiRequest = new ApiRequestObject();
     $apiRequest->setAttributesByArray($postData);
     if ($this->dataHelper->getSessionType($apiRequest) == 1) {
         //This is just a status check
         return ResponseHelper::prepareResponse(Strings::API_STATUS_SUCCESS, Strings::API_REASON_SUCCESS, Strings::API_MSG_STATUS_ONLINE);
     }
     if (!$this->dataHelper->verifyAppSession($apiRequest)) {
         return ResponseHelper::prepareResponse(Strings::API_STATUS_FATAL, Strings::API_REASON_INVALID_SESSION, Strings::API_MSG_INVALID_SESSION);
     }
     $appSession = $this->dataHelper->fetchAppSession($apiRequest);
     if (!$appSession) {
         return ResponseHelper::prepareResponse(Strings::API_STATUS_FATAL, Strings::API_REASON_INVALID_SESSION, Strings::API_MSG_ERROR_LOCATING_SESSION);
     }
     $publicKey = md5(time() . $appSession->getPublic() . time());
     $privateKey = md5(time() . time() . $appSession->getSecret() . time());
     $appId = $appSession->getAppid();
     if ($this->dataHelper->resetKeys($apiRequest, $appId) === false) {
         return ResponseHelper::prepareResponse(Strings::API_STATUS_FATAL, Strings::API_REASON_DB_ERROR, Strings::API_MSG_KEY_RESET_FAILED_DB);
     }
     $app = $this->dataHelper->fetchAppById($appId);
     $contactEmail = $app->getEmail();
     $appTitle = $app->getApptitle();
     $contactFirstName = $app->getFirstname();
     $message = $this->dataHelper->prepareMessage($contactEmail, $contactFirstName, $appTitle, $publicKey, $privateKey);
     $this->sendEmailWithMailgun($message);
     return ResponseHelper::prepareResponse(Strings::API_STATUS_SUCCESS, Strings::API_REASON_SUCCESS, Strings::API_MSG_KEY_RESET_SUCCESS);
 }
 /**
  * Get nearby ports
  * @author zbrown
  *
  * @param Request $requestObject
  * @return JsonResponse
  */
 public function portsAction(Request $requestObject)
 {
     $findNearModel = $this->get('FindNearModel');
     $apiRequest = $findNearModel->prepareRequestData($requestObject, 'findNearPorts');
     if (!$apiRequest instanceof ApiRequestObject) {
         new JsonResponse(ResponseHelper::prepareResponse($apiRequest['status'], $apiRequest['reason'], $apiRequest['msg']));
     }
     $dataPorts = $findNearModel->getNearbyPorts($apiRequest);
     return new JsonResponse(ResponseHelper::prepareResponse(Strings::API_STATUS_SUCCESS, Strings::API_REASON_SUCCESS, Strings::API_MSG_SUCCESS, $dataPorts));
 }