Beispiel #1
0
 public function testCookieMapper()
 {
     $mapper = new Application_Model_CookieMapper();
     $cookie = new Application_Model_Cookie();
     $cookie->setNick("testNick");
     $cookie->setEmail("*****@*****.**");
     $cookie->setDisplayMode(1);
     $cookie->setSaveName('testNickSave');
     $cookie->setPassword('testNickPass');
     $cookie->setTwitter('testNickTwit');
     $cookie->setFacebook('testNickFace');
     $cookie->setCCEmail('1');
     $mapper->save($cookie);
     $id = $cookie->getId();
     if (strlen($id) != 60) {
         $this->fail("Saving Cookie didn't create ID properly");
     }
     $cookie = null;
     $cookie = $mapper->find($id);
     if ($cookie == null) {
         $this->fail("Can't retrieve saved cookie");
     }
     if ($cookie->getId() != $id) {
         $this->fail("Saved Cookie Not Found");
     }
     $cookie = null;
     $cookie = $mapper->findFromPartial(substr($id, 0, 30));
     if ($cookie == null) {
         $this->fail("Can't retrieve saved cookie from partial");
     }
     if ($cookie->getId() != $id) {
         $this->fail("Saved Cookie Not Found From Partial");
     }
     $cookie = null;
     $cookie = $mapper->findFromPassword("*****@*****.**", "testNickPass");
     if ($cookie == null) {
         $this->fail("Can't retrieve saved cookie from password");
     }
     if ($cookie->getNick() != "testNick") {
         $this->fail("Saved Cookie Not Found From password");
     }
     $mapper->delete($cookie);
     $cookie = null;
     $cookie = $mapper->find($id);
     if ($cookie != null) {
         $this->fail("Failed to delete cookie with id '{$id}'");
     }
 }
Beispiel #2
0
 public static function getUserCookie()
 {
     /******************************************************************
      * Get the cookie object for the current user. If they
      * didn't send us a cookie then we make a new one for 'em.
      * If they did we resurect the one in the DB. Either way
      * we re-set the cookie to last another week!
      */
     $cookieKey = null;
     if (isset($_POST['cookieKey'])) {
         $cookieKey = $_POST['cookieKey'];
     } else {
         if (isset($_COOKIE['cookieKey'])) {
             $cookieKey = $_COOKIE['cookieKey'];
         }
     }
     if (is_string($cookieKey) && strlen($cookieKey) > 30) {
         //Look up a hopefully existing cookie.
         $cookie = new Application_Model_CookieMapper();
         $cookie = $cookie->find($cookieKey);
         if ($cookie != null) {
             return $cookie;
         }
     }
     //For one reason or another we can't trace their
     //Cookie. Make up a new one.
     return Application_Model_Cookie::makeNewCookie();
 }
Beispiel #3
0
 public function __construct(array $options = null)
 {
     if (is_array($options)) {
         $this->setOptions($options);
     }
     #Generate new ones with random hash built it as standard sir, for your safety!
     $this->_hash = Application_Model_Cookie::generateRandomKey();
 }
Beispiel #4
0
 protected function _generateHash()
 {
     $this->_hash = Application_Model_Cookie::generateRandomKey();
     $this->setValue($this->_hash);
     return $this->_hash;
 }
Beispiel #5
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);
 }
Beispiel #6
0
 function hydrateFromResult($row)
 {
     $entry = new Application_Model_Cookie();
     $entry->setId($row->id)->setNick($row->nick)->setEmail($row->email)->setPassword($row->password)->setDisplayMode($row->displaymode)->setSaveName($row->savename)->setTwitter($row->twitter)->setFacebook($row->facebook)->setCCEmail($row->ccemail)->setCreated($row->created)->setUpdated($row->updated);
     return $entry;
 }