/**
  * Authorize a Request Using the API Key
  * Extend access expiry by 5 minutes thereafter
  *
  * @param $privateKey
  *
  * @throws HTTPException
  * @return bool
  */
 public function loginWithPrivateKey($privateKey)
 {
     /** @var User $user */
     $user = User::findFirstByPrivateKey($privateKey);
     if ($user) {
         if (strtotime($user->getExpires()) > strtotime("now")) {
             $user->setExpires(date("Y-m-d H:i:s", strtotime("+20 minutes")));
             $user->save();
             $this->session->set("user", $user);
             return true;
         } else {
             throw new \PhalconRest\Exceptions\HTTPException("Application Access has expired. Please login again", 409);
         }
     }
     return false;
 }
 /**
  * Write Action Log
  *
  * @param $action
  * @param $count
  * @param $meta
  */
 private function writeLog($action, $count, $meta)
 {
     $headers = apache_request_headers();
     $userKey = $headers['X_API_KEY'];
     // Fetch User BY Key
     $user = User::findFirstByPrivateKey($userKey);
     if ($user) {
         $al = new ActionLog();
         $al->setUserId($user->getId())->setAction($action)->setItems($count)->setMeta($meta);
         $al->create();
         if ($al->getMessages()) {
             error_log(print_r($this->modelError($al), true));
         }
     }
 }