/**
  * Persist new app session to DB
  * @author zbrown
  *
  * @param ApiRequestObject $apiRequest
  * @param $applicationId
  * @return string
  */
 public function persistNewAppSession(ApiRequestObject $apiRequest, $applicationId)
 {
     $publicKey = $apiRequest->getPublicKey();
     $privateKey = $apiRequest->getPrivateKey();
     $sessionToken = $this->generateSessionToken($applicationId);
     $session = new Session();
     $session->setSession($sessionToken);
     $session->setPublic($publicKey);
     $session->setSecret($privateKey);
     $session->setAppid($applicationId);
     $now = new DateTime('now');
     $session->setTimestamp($now);
     $this->getDoctrine()->getEntityManager()->persist($session);
     $this->getDoctrine()->getEntityManager()->flush();
     return $sessionToken;
 }
 public function authAction(Request $request)
 {
     if ($request->request->has('public') === false || $request->request->has('secret') === false) {
         $resp = array('status' => 'fatal', 'reason' => 'Unauthorized', 'message' => 'Provide app API credentials.', 'request' => $request->request->all());
         return new JsonResponse($resp);
     }
     $public = $request->request->get('public');
     $secret = $request->request->get('secret');
     $app = $this->getDoctrine()->getRepository('YupItsZacFreeGeoBundle:Apps')->findOneBy(array('publickey' => $public));
     if ($app === null) {
         $resp = array('status' => 'fatal', 'reason' => 'unauthroized', 'message' => 'The supplied API credentials are invalid, or revoked.');
         return new JsonResponse($resp);
     }
     $appId = $app->getId();
     $appTitle = $app->getApptitle();
     $appStatus = $app->getStatus();
     if ($appStatus != 'Active') {
         $resp = array('status' => 'fatal', 'reason' => 'Unauthorized', 'message' => 'App for public key ' . $public . ' is no longer active. The status is ' . $appStatus . '. For questions, contact support online at freegeo.yupitszac.com');
         return new JsonResponse($resp);
     }
     $sessionKey = md5(time() . $public . time() . $secret . time() . $appId);
     $em = $this->getDoctrine()->getEntityManager();
     $session = new Session();
     $session->setSession($sessionKey);
     $session->setPublic($public);
     $session->setSecret($secret);
     $session->setAppid($appId);
     $now = new DateTime('now');
     $session->setTimestamp($now);
     $em->persist($session);
     $em->flush();
     $resp = array('status' => 'success', 'reason' => 'authorized', 'payload' => array('session' => $sessionKey));
     return new JsonResponse($resp);
 }
 public function persistNewSession($publicKey, $privateKey, $appId)
 {
     $sessionToken = $this->generateSessionToken();
     $session = new Session();
     $session->setSession($sessionToken);
     $session->setPublic($publicKey);
     $session->setSecret($privateKey);
     $session->setAppid($appId);
     $now = new DateTime('now');
     $session->setTimestamp($now);
     $this->entityManager->persist($session);
     $this->entityManager->flush();
 }