/** * Action to handle validation of a pending request for friendship. * * Handled via HTTP Response code * * @return void */ function validateAction() { $signature = post('signature'); $url = post('url'); $f = WpHerissonFriendsTable::getOneWhere("url=? AND b_youwant=1", array($url)); try { if (Encryption::i()->publicDecrypt($signature, $f->public_key) == $url) { $f->b_youwant = 0; $f->is_active = 1; $f->save(); Network::reply(200); echo "1"; exit; } else { Network::reply(417, HERISSON_EXIT); } } catch (Encryption\Exception $e) { Network::reply(417, HERISSON_EXIT); } }
/** * Test validating a friend with the wrong key * * @return void */ public function testValidateFriendWaitingError() { // create a fake request from sample site $f = new WpHerissonFriends(); $e = Encryption::i(); $e->generateKeyPairs(); $f->public_key = $e->public; $f->url = $this->herissonUrl; //$f->setUrl($this->herissonUrl); $f->b_wantsyou = 1; $f->save(); // Check the request is pending $friends = WpHerissonFriendsTable::getWhere('url=? and b_wantsyou=? and is_active=?', array($f->url, 1, 0)); $this->assertEquals(1, sizeof($friends)); $friend = $friends[0]; $friend->validateFriend(); $msgs = Message::i()->getErrors(); $msgs = array_reverse($msgs); $this->assertEquals(1, preg_match("/417/", $msgs[0])); }
/** * Handle the importation of bookmarks from a friend * * @return a list of WpHerissonBookmarks */ public function import() { $friendId = post('friendId'); if (!$friendId) { throw new Exception("Missing friend Id"); } $friend = WpHerissonFriendsTable::get(post('friendId')); if (!$friend->id) { throw new Exception("Unknown friend"); } $bookmarks = $friend->retrieveBookmarks(); return $bookmarks; }
/** * Action to list friends * * This is the default action * * @return void */ function indexAction() { $this->view->actives = WpHerissonFriendsTable::getWhere("is_active=1"); $this->view->youwant = WpHerissonFriendsTable::getWhere("b_youwant=1"); $this->view->wantsyou = WpHerissonFriendsTable::getWhere("b_wantsyou=1"); $this->view->errors = WpHerissonFriendsTable::getWhere("b_wantsyou!=1 and b_youwant!=1 and is_active!=1"); }
/** * Download a backup from friend * * @return void */ private function _retrieve() { $friend = WpHerissonFriendsTable::get(get('id')); if (!$friend->id) { Message::i()->addError(__("Friend could not be found", HERISSON_TD)); $this->indexAction(); $this->setView('index'); return; } return $friend->downloadBackup(); }