public function isValid($value)
 {
     $ret = parent::isValid($value);
     if ($ret) {
         $mapper = new Application_Model_CsrfhashMapper();
         $mapper->deleteByCsrf($value);
     }
     return $ret;
 }
Beispiel #2
0
function deleteOldCsrf()
{
    echo "  Deleting old stale CSRFs.";
    $mapper = new Application_Model_CsrfhashMapper();
    $delete = $mapper->getdbtable()->delete("created<date_sub(now(),interval 1 minute)");
}
Beispiel #3
0
 public function initCsrfToken()
 {
     $mapper = new Application_Model_CsrfhashMapper();
     $csrfhash = $mapper->findOrCreate($this->getCookieKey(), $this->getHash());
     $this->hash = $csrfhash->getCsrf();
 }
Beispiel #4
0
 public function doPollingStuffAndOutputJSON($jsonArray = array())
 {
     /***************************************************************
      * Every actions wants to return the polling data I reckon,
      * say if there's any new posts, update the CSRF etc.
      * so they all call this. Even the pollAction, which does
      * very little lese.
      */
     $cookie = Application_Model_DbTable_Cookie::getUserCookie();
     //Generate a new CSRF if this one is too old and tired.
     $csrf = $this->getRequest()->getParam('csrf');
     $csrfmapper = new Application_Model_CsrfhashMapper();
     $age = $csrfmapper->findAge($cookie->getId(), $csrf);
     if ($age == null || $age > 30) {
         //Either no or old CSR, give a new one.
         $csrf = Application_Model_Cookie::generateRandomKey();
         $csrfObj = $csrfmapper->findOrCreate($cookie->getId(), $csrf);
     }
     $url = addslashes($this->getRequest()->getParam('url'));
     $max = (int) $this->getRequest()->getParam('maxCommentId');
     $min = (int) $this->getRequest()->getParam('minCommentId');
     //Get all the comments for this URL that are higher in ID than $max.
     $this->comments = array();
     $dp = $this->convertUrlToDP($url);
     if (is_array($dp)) {
         $mapper = new Application_Model_CommentMapper();
         $dom = addslashes($dp['domain']);
         $path = addslashes($dp['path']);
         if ($min == null) {
             $minmax = "id > {$max}";
         } else {
             $minmax = "id < {$min}";
         }
         if ($cookie->getDisplayMode() == 2) {
             //All posts from the entire internet!? Are ou CRAZY!
             $rows = $mapper->findWhere($minmax);
         } else {
             if ($cookie->getDisplayMode() == 1) {
                 //All posts to any page on this domain. Sorted.
                 $rows = $mapper->findWhere("domain='" . $dom . "' and " . $minmax);
             } else {
                 $rows = $mapper->findWhere("domain='" . $dom . "' and path='" . $path . "' and " . $minmax);
             }
         }
         foreach ($rows as $r) {
             $this->comments[] = $mapper->convertRowToArray($r, $cookie);
         }
     }
     $sendArray = array_merge($jsonArray, array("comments" => $this->comments, "success" => "true", "setCookie" => $cookie->getId(), "url" => $url, "csrf" => $csrf));
     $this->getHelper('json')->sendJSON($sendArray);
 }