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 function confirmAction()
 {
     $this->title = "You have confirmed your email";
     $mapper = new Application_Model_EmailHashMapper();
     $hashHash = addslashes($this->getRequest()->getParam('hash'));
     $hash = new Application_Model_EmailHash();
     $mapper->find($hashHash, $hash);
     if ($hash->getCookie() != null) {
         $this->view->hash = $hash;
         $cookieObj = $hash->fetchCookieObject();
         $cookieObj->setEmail($hash->getEmail());
         $cookieMapper = new Application_Model_CookieMapper();
         $cookieMapper->save($cookieObj);
     } else {
         $this->view->hash = false;
     }
 }
Beispiel #3
0
 public static function makeNewCookie()
 {
     $cookie = new Application_Model_Cookie(array('id' => null, 'ip' => $_SERVER['REMOTE_ADDR'], 'nick' => "Anon_" . self::generateRandomKey(6)));
     $mapper = new Application_Model_CookieMapper();
     $mapper->save($cookie);
     $cookieKey = $cookie->getId();
     try {
         setcookie('cookieKey', $cookieKey, time() + 7 * 24 * 60 * 60, "/");
     } catch (Exception $e) {
         //If we're running tests we can't set cookies. Ignore
         //errors here I guess.
     }
     return $cookie;
 }
Beispiel #4
0
 public function getCookieObject()
 {
     $mapper = new Application_Model_CookieMapper();
     return $mapper->find($this->_cookie);
 }
Beispiel #5
0
 public function fetchCookieObject()
 {
     if ($this->_cookieObj != null) {
         return $this->_cookieObj;
     } else {
         $mapper = new Application_Model_CookieMapper();
         $this->_cookieObj = $mapper->find($this->_cookie);
         return $this->_cookieObj;
     }
 }
Beispiel #6
0
 public function userAction()
 {
     /****************************************************************
      * List everything by a user. Either passed a message or 
      * a half-a-cookie. Certainly want to paginate this.
      */
     $page = $this->getRequest()->getParam('page');
     if (!$page) {
         $page = 0;
     }
     $cookie = Application_Model_DbTable_Cookie::getUserCookie();
     $cookieMapper = new Application_Model_CookieMapper();
     $mapper = new Application_Model_CommentMapper();
     //Need to grab a cookie and nick. We can do this two ways,
     if ($this->getRequest()->getParam('id')) {
         //One: Passed a partial cookie and nickname directly:
         $partialCookie = addslashes($this->getRequest()->getParam("id"));
         $viewUserCookie = $cookieMapper->findFromPartial($partialCookie);
         $nick = addslashes($this->getRequest()->getParam("nick"));
     } else {
         if ($this->getRequest()->getParam('mid')) {
             //Two: Passed a message and told "The guy who wrote this"
             $messageId = $this->getRequest()->getParam('mid');
             $message = $mapper->find($messageId);
             if ($message == null) {
                 throw new Exception("Can't find that message");
             }
             $viewUserCookie = $message->getCookieObject();
             $nick = $message->getNick();
             if ($this->getRequest()->getParam("nick")) {
                 $nick = addslashes($this->getRequest()->getParam("nick"));
             }
             if ($nick == "-1") {
                 $nick = null;
             }
         } else {
             throw new Exception("User not specified");
         }
     }
     //All the nicks this user ever used!
     $this->view->userNicks = $viewUserCookie->getAllNicks();
     //All the comments they ever posted!
     if ($viewUserCookie->getEmail()) {
         $orEmail = " or email='" . $viewUserCookie->getEmail() . "'";
     } else {
         $orEmail = "";
     }
     if ($nick != null) {
         $andNick = " and nick='" . $nick . "'";
     }
     $rows = $mapper->findWhere("(cookie='" . $viewUserCookie->getId() . "' " . $orEmail . ")" . $andNick, 50, $page * 50);
     $this->view->comments = array();
     foreach ($rows as $r) {
         $viewUserFullCookieId = $r->cookie;
         if ($messageId == null) {
             $messageId = $r->id;
         }
         $this->view->comments[] = $mapper->convertRowToArray($r, $cookie);
     }
     $this->view->askedNick = $nick;
     $this->view->userDetails = $viewUserCookie;
     $this->view->mid = $messageId;
     $this->view->title = "Messages from {$nick}";
     $this->view->page = $page;
 }