protected function getUserIdFromApi()
 {
     // Create a LinkedIn object
     $linkedInApiConfig = array('appKey' => LI_API_KEY, 'appSecret' => LI_SECRET, 'callbackUrl' => APP_URL . '/' . Content::l() . '/login/linkedincallback/' . (!empty($_GET['nextPage']) ? $_GET['nextPage'] : ''));
     $linkedIn = new LinkedIn($linkedInApiConfig);
     try {
         $response = $linkedIn->retrieveTokenAccess($_GET['oauth_token'], $_SESSION['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']);
     } catch (Error $e) {
         Debug::l('Error. Could not retrieve LinkedIn access token. ' . $e);
         header('Location: ' . APP_URL . '/' . Content::l() . '/login/linkedin/');
         exit;
     }
     if ($response['success'] === TRUE) {
         // The request went through without an error, gather user's access tokens
         $_SESSION['oauth']['linkedin']['access'] = $response['linkedin'];
         // Set the user as authorized for future quick reference
         $_SESSION['oauth']['linkedin']['authorized'] = true;
     } else {
         $this->exitWithMessage('Error. The OAuth access token was not retrieved. ' . print_r($response, 1));
     }
     $this->accessToken = serialize($response['linkedin']);
     /*
     Retrieve the user ID
     The XML response will look like one of these:
     
     <person>
       <id>8GhzNjjaOi</id>
     </person>
     
     <error>
       <status>401</status>
       <timestamp>1288518358054</timestamp>
       <error-code>0</error-code>
       <message>[unauthorized]. The token used in the OAuth request is not valid.</message>
     </error>
     */
     try {
         $response = $linkedIn->profile('~:(id,first-name,last-name)');
         if ($response['success'] === TRUE) {
             $response['linkedin'] = new SimpleXMLElement($response['linkedin']);
             if ($response['linkedin']->getName() != 'person') {
                 Debug::l('Error. Could not retrieve person data from LinkedIn. ' . print_r($response, 1));
                 header('Location: ' . APP_URL . '/' . Content::l() . '/login/linkedin/');
                 exit;
             }
         } else {
             Debug::l('Error. Could not retrieve person data from LinkedIn. ' . print_r($response, 1));
             header('Location: ' . APP_URL . '/' . Content::l() . '/login/linkedin/');
             exit;
         }
         $this->linkedInId = (string) $response['linkedin']->id;
         $this->name = $response['linkedin']->{'first-name'} . ' ' . $response['linkedin']->{'last-name'};
     } catch (Error $e) {
         Debug::l('Error. Could not retrieve person ID from LinkedIn. ' . $e);
         header('Location: ' . APP_URL . '/' . Content::l() . '/login/linkedin/');
         exit;
     }
 }
示例#2
0
 public function __construct()
 {
     session_start();
     header('Content-type: text/json');
     // Get the website user
     $userId = SessionManager::getInstance()->getUserId();
     // Make sure a user is logged in
     if (empty($userId)) {
         Debug::l('No user logged in');
         $json['result'] = 'false';
         echo json_encode($json);
         exit;
     }
     // Validate input
     if (empty($_POST['email']) || !filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL)) {
         Debug::l('Invalid email');
         $json['result'] = 'false';
         echo json_encode($json);
         exit;
     }
     // Update email address
     $db = Database::getInstance();
     $sth = $db->prepare('UPDATE person SET email = :email WHERE id = :id');
     $sth->execute(array(':email' => $_POST['email'], ':id' => $userId));
     $json['result'] = 'true';
     echo json_encode($json);
 }
 protected function getUserIdFromApi()
 {
     // If the oauth_token is old redirect to the connect page
     if (!isset($_SESSION['twitterOAuthToken']) || !isset($_REQUEST['oauth_token']) || $_SESSION['twitterOAuthToken'] !== $_REQUEST['oauth_token']) {
         Debug::l('Bad Twitter OAuth token');
         header('Location: ' . APP_URL . '/' . Content::l() . '/login/twitter/');
         exit;
     }
     // Create TwitterOAuth object with app key/secret and token key/secret from default phase
     $this->twitter = new TwitterOAuth(TW_CONSUMER, TW_SECRET, $_SESSION['twitterOAuthToken'], $_SESSION['twitterOAuthTokenSecret']);
     // Request access tokens from twitter
     $twitterAccessToken = $this->twitter->getAccessToken($_REQUEST['oauth_verifier']);
     // Remove no longer needed request tokens
     unset($_SESSION['twitterOAuthToken']);
     unset($_SESSION['twitterOAuthTokenSecret']);
     // If HTTP response is 200 continue otherwise send to connect page to retry
     if ($this->twitter->http_code != 200) {
         Debug::l('Error logging in to Twitter. Could not retrieve access token.');
         header('Location: ' . APP_URL . '/' . Content::l() . '/login/twitter/');
         exit;
     }
     // The user has been verified and the access tokens can be saved for future use
     $this->twitterId = $twitterAccessToken['user_id'];
     $this->accessToken = serialize($twitterAccessToken);
 }
 public function __construct()
 {
     session_start();
     // Connect to the database
     $this->db = Database::getInstance();
     // Get the website user
     $userId = SessionManager::getInstance()->getUserId();
     if (empty($userId)) {
         Debug::l('No user logged in');
         header('Location: ' . APP_URL . '/' . Content::l() . '/');
         exit;
     }
     // Get the introduction that hasn't been sent yet
     $this->introductionQ = $this->db->prepare('SELECT id, introducee1_id, introducee2_id, introducee1_notified, introducee2_notified, link_password FROM introduction WHERE introducer_id = :id AND (introducee1_notified IS NULL OR introducee2_notified IS NULL) ORDER BY time DESC LIMIT 1');
     $this->introductionQ->execute(array(':id' => $userId));
     $this->introduction = $this->introductionQ->fetch(PDO::FETCH_ASSOC);
     if (empty($this->introduction)) {
         Debug::l('No unsent introductions found');
         header('Location: ' . APP_URL . '/' . Content::l() . '/');
         exit;
     }
     $introducee1 = new Person(array());
     $introducee1->getDataFromId($this->introduction['introducee1_id']);
     $introducee2 = new Person(array());
     $introducee2->getDataFromId($this->introduction['introducee2_id']);
     // Notify introducee 1
     if (empty($this->introduction['introducee1_notified'])) {
         $notifyManager = new NotifyManager($this->introduction['id'], $introducee1, $introducee2);
         $updateQ = $this->db->prepare('UPDATE introduction SET introducee1_notified = :method WHERE id = :id');
         $this->notifyPerson($notifyManager, $introducee1, $updateQ);
     }
     // Notify introducee 2
     if (empty($this->introduction['introducee2_notified'])) {
         $notifyManager = new NotifyManager($this->introduction['id'], $introducee2, $introducee1);
         $updateQ = $this->db->prepare('UPDATE introduction SET introducee2_notified = :method WHERE id = :id');
         $this->notifyPerson($notifyManager, $introducee2, $updateQ);
     }
     $base62 = BaseConvert::base10ToBase62($this->introduction['id']);
     // Redirect to introduction page
     header('Location: ' . APP_URL . '/' . Content::l() . '/A' . $this->introduction['link_password'] . $base62);
 }
示例#5
0
 public function __construct()
 {
     session_start();
     // Connect to the database
     $this->db = Database::getInstance();
     // Get the website user
     $this->userId = SessionManager::getInstance()->getUserId();
     if (empty($this->userId)) {
         Debug::l('No user logged in');
         header('Location: ' . Content::getInstance()->getRootUrl());
         exit;
     }
     $userDetailsQ = $this->db->prepare('SELECT p.email, f.id as facebook_id, f.access_token as facebook_access_token, l.id as linkedin_id, l.access_token as linkedin_access_token, t.id as twitter_id, t.access_token as twitter_access_token FROM person p LEFT JOIN facebook f ON p.id = f.person_id LEFT JOIN linkedin l ON p.id = l.person_id LEFT JOIN twitter t ON p.id = t.person_id WHERE p.id = :id');
     $userDetailsQ->execute(array(':id' => $this->userId));
     $this->userDetails = $userDetailsQ->fetch(PDO::FETCH_ASSOC);
     $top = new Top('', 'settingsPage');
     echo $top->getOutput();
     echo '<h1>' . Content::c()->settings->title . '</h1>' . '<h2>' . Content::c()->settings->profiles . '</h2>' . $this->showConnectedProfiles() . '<h2>' . Content::c()->settings->email . '</h2>' . '<form id="formEmail" class="clearfix">' . '<input type="email" name="email" id="email" value="' . $this->userDetails['email'] . '" placeholder="' . Content::c()->view->email_request->placeholder . '" />' . '<input id="submitEmail" class="button" type="submit" value="' . Content::c()->settings->submit . '" />' . '</form>' . '';
     $script = '<script>' . 'var introduceme = (function (module) {' . 'module.content = module.content || {};' . 'module.content.success = "' . Content::c()->settings->success . '";' . 'module.content.saved = "' . Content::c()->settings->saved . '";' . 'return module;' . '}(introduceme || {}));' . '</script>';
     $bottom = new Bottom($script);
     echo $bottom->getOutput();
 }
 private function checkSessionsForUser()
 {
     // Check the session for a logged in user
     if (!empty($_SESSION['loggedInPersonId'])) {
         return $_SESSION['loggedInPersonId'];
     }
     $db = Database::getInstance();
     // See if there is a Facebook session
     $facebookUser = $this->getFacebook()->getUser();
     if (!empty($facebookUser)) {
         // See if this Facebook user is already in the database
         $userDetailsQ = $db->prepare('SELECT p.id FROM person p, facebook f WHERE p.id = f.person_id AND f.id = :facebook_id');
         $userDetailsQ->execute(array(':facebook_id' => $facebookUser));
         $userDetails = $userDetailsQ->fetch(PDO::FETCH_ASSOC);
         if ($userDetails) {
             // Save the user's person_id to the session
             Debug::l('SessionManager :: Got the active session from Facebook.');
             $_SESSION['loggedInPersonId'] = $userDetails['id'];
             return $_SESSION['loggedInPersonId'];
         }
     }
     // No session was found so return null
     return null;
 }
 public function __construct()
 {
     session_start();
     // Get the website user
     $userId = SessionManager::getInstance()->getUserId();
     // Require logged in user
     if (!isset($userId)) {
         Debug::l('No user logged in');
         header('Location: ' . APP_URL . '/' . Content::l() . '/settings/');
         exit;
     }
     // Make sure the network param is valid
     if (empty($_GET['network']) || !in_array($_GET['network'], array('Facebook', 'LinkedIn', 'Twitter'))) {
         Debug::l('Bad network param');
         header('Location: ' . APP_URL . '/' . Content::l() . '/settings/');
         exit;
     }
     // Connect to the database
     $db = Database::getInstance();
     // Remove the network
     switch ($_GET['network']) {
         case 'Facebook':
             $update = $db->prepare('UPDATE facebook SET access_token="" WHERE person_id = :person_id');
             $update->execute(array(':person_id' => $userId));
             break;
         case 'LinkedIn':
             $update = $db->prepare('UPDATE linkedin SET access_token="" WHERE person_id = :person_id');
             $update->execute(array(':person_id' => $userId));
             break;
         case 'Twitter':
             $update = $db->prepare('UPDATE twitter SET access_token="" WHERE person_id = :person_id');
             $update->execute(array(':person_id' => $userId));
             break;
     }
     header('Location: ' . APP_URL . '/' . Content::l() . '/settings/');
 }
示例#8
0
 private function exitWithMessage($message)
 {
     Debug::l($message);
     echo $message;
     exit;
 }
 private function loadProfiles($person, $personIsUser)
 {
     $profiles = array();
     if (!empty($person['facebook_access_token']) && (!$personIsUser || $this->mergeNetwork != 'Facebook')) {
         try {
             //$params = array('access_token' => $user['facebook_access_token']);
             $facebookProfile = SessionManager::getInstance()->getFacebook()->api('/' . $person['facebook_id']);
         } catch (FacebookApiException $e) {
             Debug::l('Error loading Facebook profile for ' . ($personIsUser ? 'current' : 'other') . ' user. ' . $e);
         }
         if (isset($facebookProfile)) {
             $profiles[] = '<a href="' . $facebookProfile['link'] . '" target="_blank" class="profile"><img src="https://graph.facebook.com/' . $person['facebook_id'] . '/picture?type=square" /> ' . $facebookProfile['name'] . ' on Facebook</a>';
         }
     }
     if (!empty($person['linkedin_access_token']) && (!$personIsUser || $this->mergeNetwork != 'LinkedIn')) {
         $API_CONFIG = array('appKey' => LI_API_KEY, 'appSecret' => LI_SECRET, 'callbackUrl' => '');
         $OBJ_linkedin = new LinkedIn($API_CONFIG);
         $OBJ_linkedin->setTokenAccess(unserialize($person['linkedin_access_token']));
         try {
             $linkedInProfile = $OBJ_linkedin->profile('id=' . $person['linkedin_id'] . ':(first-name,last-name,public-profile-url,picture-url)');
         } catch (ErrorException $e) {
             Debug::l('Error loading LinkedIn profile for ' . ($personIsUser ? 'current' : 'other') . ' user. ' . $e);
         }
         if ($linkedInProfile['success'] === TRUE) {
             $linkedInProfile['linkedin'] = new SimpleXMLElement($linkedInProfile['linkedin']);
             if ($linkedInProfile['linkedin']->getName() == 'person') {
                 $li_pr = (string) $linkedInProfile['linkedin']->{'public-profile-url'};
                 $li_pi = (string) $linkedInProfile['linkedin']->{'picture-url'};
                 $li_fn = (string) $linkedInProfile['linkedin']->{'first-name'};
                 $li_ln = (string) $linkedInProfile['linkedin']->{'last-name'};
                 $profiles[] = '<a href="' . $li_pr . '" target="_blank" class="profile"><img src="' . $li_pi . '" /> ' . $li_fn . ' ' . $li_ln . ' on LinkedIn</a>';
             }
         }
     }
     if (!empty($person['twitter_access_token']) && ($personIsUser || $this->mergeNetwork != 'Twitter')) {
         try {
             $twitterAccessToken = unserialize($person['twitter_access_token']);
             $twitter = new TwitterOAuth(TW_CONSUMER, TW_SECRET, $twitterAccessToken['oauth_token'], $twitterAccessToken['oauth_token_secret']);
             $twitter->format = 'json';
             $twitterProfile = $twitter->get('users/show', array('user_id' => $person['twitter_id']));
         } catch (ErrorException $e) {
             Debug::l('Error loading Twitter profile for ' . ($personIsUser ? 'current' : 'other') . ' user. ' . $e);
         }
         if (isset($twitterProfile)) {
             $profiles[] = '<a href="http://twitter.com/' . $twitterProfile->screen_name . '" target="_blank" class="profile"><img src="' . $twitterProfile->profile_image_url . '" /> @' . $twitterProfile->screen_name . ' on Twitter</a>';
         }
     }
     return $profiles;
 }
示例#10
0
 public function __construct()
 {
     session_start();
     header('Content-type: text/json');
     // Get the website user
     $userId = SessionManager::getInstance()->getUserId();
     $json['result'] = 'true';
     // Make sure a user is logged in
     if (!isset($userId)) {
         $json['result'] = 'false';
         $json['title'] = (string) Content::c()->errors->session->title;
         $json['message'] = (string) Content::c()->errors->session->no_session;
         echo json_encode($json);
         exit;
     }
     // Validate input
     if (empty($_POST['introducee1Name']) || empty($_POST['introducee1FacebookId']) && empty($_POST['introducee1LinkedInId']) && empty($_POST['introducee1TwitterId']) || empty($_POST['introducee2Name']) || empty($_POST['introducee2FacebookId']) && empty($_POST['introducee2LinkedInId']) && empty($_POST['introducee2TwitterId'])) {
         $json['result'] = 'false';
         $json['title'] = (string) Content::c()->errors->input->title;
         $json['message'] = (string) Content::c()->errors->input->introduction_not_created;
         echo json_encode($json);
         exit;
     }
     // Make sure the introducees are unique
     if (!empty($_POST['introducee1FacebookId']) && !empty($_POST['introducee2FacebookId']) && $_POST['introducee1FacebookId'] == $_POST['introducee2FacebookId'] || !empty($_POST['introducee1LinkedInId']) && !empty($_POST['introducee2LinkedInId']) && $_POST['introducee1LinkedInId'] == $_POST['introducee2LinkedInId'] || !empty($_POST['introducee1TwitterId']) && !empty($_POST['introducee2TwitterId']) && $_POST['introducee1TwitterId'] == $_POST['introducee2TwitterId']) {
         $json['result'] = 'false';
         $json['title'] = (string) Content::c()->errors->input->title;
         $json['message'] = (string) Content::c()->errors->input->introduce_to_self;
         echo json_encode($json);
         exit;
     }
     // Connect to the database
     $db = Database::getInstance();
     $introducee1 = new Person(array('name' => $_POST['introducee1Name'], 'facebookId' => !empty($_POST['introducee1FacebookId']) ? $_POST['introducee1FacebookId'] : '', 'linkedInId' => !empty($_POST['introducee1LinkedInId']) ? $_POST['introducee1LinkedInId'] : null, 'twitterId' => !empty($_POST['introducee1TwitterId']) ? $_POST['introducee1TwitterId'] : null));
     $introducee2 = new Person(array('name' => $_POST['introducee2Name'], 'facebookId' => !empty($_POST['introducee2FacebookId']) ? $_POST['introducee2FacebookId'] : '', 'linkedInId' => !empty($_POST['introducee2LinkedInId']) ? $_POST['introducee2LinkedInId'] : null, 'twitterId' => !empty($_POST['introducee2TwitterId']) ? $_POST['introducee2TwitterId'] : null));
     // See if the introducees are already in our database, that would be nice!
     if (!empty($_POST['introducee1FacebookId'])) {
         $introducee1->getDataFromFacebookId($_POST['introducee1FacebookId']);
     } elseif (!empty($_POST['introducee1LinkedInId'])) {
         $introducee1->getDataFromLinkedInId($_POST['introducee1LinkedInId']);
     } elseif (!empty($_POST['introducee1TwitterId'])) {
         $introducee1->getDataFromTwitterId($_POST['introducee1TwitterId']);
     }
     if (!empty($_POST['introducee2FacebookId'])) {
         $introducee2->getDataFromFacebookId($_POST['introducee2FacebookId']);
     } elseif (!empty($_POST['introducee2LinkedInId'])) {
         $introducee2->getDataFromLinkedInId($_POST['introducee2LinkedInId']);
     } elseif (!empty($_POST['introducee2TwitterId'])) {
         $introducee2->getDataFromTwitterId($_POST['introducee2TwitterId']);
     }
     // Make sure the introducees are still unique
     if ($introducee1->getFacebookId() != null && $introducee1->getFacebookId() == $introducee2->getFacebookId() || $introducee1->getLinkedInId() != null && $introducee1->getLinkedInId() == $introducee2->getLinkedInId() || $introducee1->getTwitterId() != null && $introducee1->getTwitterId() == $introducee2->getTwitterId()) {
         $json['result'] = 'false';
         $json['title'] = (string) Content::c()->errors->input->title;
         $json['message'] = (string) Content::c()->errors->input->introduce_to_self;
         echo json_encode($json);
         exit;
     }
     // If the introducees aren't in the database yet, add them
     $introducee1->addToDatabase();
     $introducee2->addToDatabase();
     // If the introducees are on LinkedIn, add their public profile URL and picture to the DB
     if ($introducee1->getLinkedInId() != null || $introducee2->getLinkedInId() != null) {
         // Connect to LinkedIn API
         $sth = $db->prepare('SELECT id, access_token FROM linkedin WHERE person_id = :person_id');
         $sth->execute(array(':person_id' => $userId));
         $userDetails = $sth->fetch(PDO::FETCH_ASSOC);
         if (!empty($userDetails['access_token'])) {
             $linkedInAccessToken = $userDetails['access_token'];
             // Create LinkedIn object
             $API_CONFIG = array('appKey' => LI_API_KEY, 'appSecret' => LI_SECRET, 'callbackUrl' => '');
             $OBJ_linkedin = new LinkedIn($API_CONFIG);
             $OBJ_linkedin->setTokenAccess(unserialize($linkedInAccessToken));
             // Which introducees are on LinkedIn?
             $profilesToRequest = array();
             if ($introducee1->getLinkedInId() != null) {
                 $profilesToRequest[] = 'id=' . $introducee1->getLinkedInId();
             }
             if ($introducee2->getLinkedInId() != null) {
                 $profilesToRequest[] = 'id=' . $introducee2->getLinkedInId();
             }
             try {
                 $linkedInProfiles = $OBJ_linkedin->profileNew('::(' . implode(',', $profilesToRequest) . '):(id,public-profile-url,picture-url)');
             } catch (ErrorException $e) {
             }
             if ($linkedInProfiles['success'] === TRUE) {
                 $linkedInProfiles['linkedin'] = new SimpleXMLElement($linkedInProfiles['linkedin']);
                 if ($linkedInProfiles['linkedin']->getName() == 'people') {
                     foreach ($linkedInProfiles['linkedin']->person as $person) {
                         $id = (string) $person->id;
                         $url = (string) $person->{'public-profile-url'};
                         $pic = (string) $person->{'picture-url'};
                         if ($id && ($url || $pic)) {
                             $update = $db->prepare('REPLACE INTO temp_linkedin SET linkedin_id = :linkedin_id, time=NOW(), profile_url = :profile_url, picture_url = :picture_url');
                             $update->execute(array(':linkedin_id' => $id, ':profile_url' => $url, ':picture_url' => $pic));
                         }
                     }
                 }
             }
         }
     }
     // If the introducees are on Twitter, add their screen name and picture to the DB
     if ($introducee1->getTwitterId() != null || $introducee2->getTwitterId() != null) {
         // Which introducees are on Twitter?
         $profilesToRequest = array();
         if ($introducee1->getTwitterId() != null) {
             $profilesToRequest[] = $introducee1->getTwitterId();
         }
         if ($introducee2->getTwitterId() != null) {
             $profilesToRequest[] = $introducee2->getTwitterId();
         }
         // Connect to Twitter API
         $sth = $db->prepare('SELECT id, access_token FROM twitter WHERE person_id = :person_id');
         $sth->execute(array(':person_id' => $userId));
         $userDetails = $sth->fetch(PDO::FETCH_ASSOC);
         if (!empty($userDetails['access_token'])) {
             $twitterAccessToken = unserialize($userDetails['access_token']);
             try {
                 $twitter = new TwitterOAuth(TW_CONSUMER, TW_SECRET, $twitterAccessToken['oauth_token'], $twitterAccessToken['oauth_token_secret']);
                 $twitter->format = 'json';
                 $twitterProfiles = $twitter->get('users/lookup', array('user_id' => implode(',', $profilesToRequest)));
                 foreach ($twitterProfiles as $friend) {
                     $id = (string) $friend->id;
                     $screenName = (string) $friend->screen_name;
                     $pic = (string) $friend->profile_image_url;
                     $protected = (string) $friend->protected;
                     if ($id && ($screenName || $pic || $protected)) {
                         $update = $db->prepare('REPLACE INTO temp_twitter SET twitter_id = :twitter_id, time=NOW(), screen_name = :screen_name, picture_url = :picture_url, protected = :protected');
                         $update->execute(array(':twitter_id' => $id, ':screen_name' => $screenName, ':picture_url' => $pic, ':protected' => $protected));
                     }
                 }
             } catch (ErrorException $e) {
                 // Could not post to Twitter. Bad access token?
                 Debug::l('Error posting to Twitter ' . $e);
             }
         }
     }
     $linkPassword = BaseConvert::generatePassword();
     // Add the introduction to the database
     $insert = $db->prepare('INSERT INTO introduction (introducer_id, introducee1_id, introducee2_id, time, link_password) VALUES (:introducer_id, :introducee1_id, :introducee2_id, NOW(), :link_password)');
     $insert->execute(array(':introducer_id' => $userId, ':introducee1_id' => $introducee1->getId(), ':introducee2_id' => $introducee2->getId(), ':link_password' => $linkPassword));
     $introId = $db->lastInsertId();
     // Add the links for each introducee
     $linkPassword1 = BaseConvert::generatePassword();
     $linkPassword2 = BaseConvert::generatePassword();
     $insert = $db->prepare('INSERT INTO link (introduction_id, person_id, link_password) VALUES (:introduction_id, :person_id, :link_password)');
     $insert->execute(array(':introduction_id' => $introId, ':person_id' => $introducee1->getId(), ':link_password' => $linkPassword1));
     $insert->execute(array(':introduction_id' => $introId, ':person_id' => $introducee2->getId(), ':link_password' => $linkPassword2));
     // If there is a message, add it to the database
     if (!empty($_POST["message"])) {
         $message = htmlentities(trim($_POST['message']), ENT_QUOTES, 'UTF-8');
         if (!empty($message)) {
             $insert = $db->prepare('INSERT INTO message (body, time, introduction_id, writer_id) VALUES (:body, NOW(), :introduction_id, :writer_id)');
             $insert->execute(array(':body' => $message, ':introduction_id' => $introId, ':writer_id' => $userId));
         }
     }
     // Return the success message, which will tell the Javascript to redirect the user to the send-introduction page
     $json['result'] = 'true';
     $json['link'] = APP_URL . '/' . Content::l() . '/send-introduction/';
     $json['time'] = Debug::getInstance()->getTimeElapsed();
     echo json_encode($json);
 }
 protected function exitWithMessage($message)
 {
     Debug::l($message);
     echo $message;
     exit;
 }
 public function __construct()
 {
     session_start();
     $db = Database::getInstance();
     if (empty($_SESSION['mergeOtherAccount']) || empty($_SESSION['mergeNetwork'])) {
         Debug::l('Error merging account: missing session vars');
         header('Location: ' . APP_URL . '/' . Content::l() . '/');
         exit;
     }
     $mergeOtherAccount = $_SESSION['mergeOtherAccount'];
     $mergeNetwork = $_SESSION['mergeNetwork'];
     // Get the website user
     $userId = SessionManager::getInstance()->getUserId();
     // Require logged in user
     if (empty($userId)) {
         Debug::l('Error merging account: No logged in user');
         header('Location: ' . APP_URL . '/' . Content::l() . '/');
         exit;
     }
     // Get user details
     $userDetailsQ = $db->prepare('SELECT p.email, f.id as facebook_id, f.access_token as facebook_access_token, l.id as linkedin_id, l.access_token as linkedin_access_token, t.id as twitter_id, t.access_token as twitter_access_token FROM person p LEFT JOIN facebook f ON p.id = f.person_id LEFT JOIN linkedin l ON p.id = l.person_id LEFT JOIN twitter t ON p.id = t.person_id WHERE p.id = :id');
     $userDetailsQ->execute(array(':id' => $userId));
     $userDetails = $userDetailsQ->fetch(PDO::FETCH_ASSOC);
     // Get merging account details
     $mergeId = $_SESSION['mergeOtherAccount'];
     $userDetailsQ->execute(array(':id' => $mergeId));
     $mergeDetails = $userDetailsQ->fetch(PDO::FETCH_ASSOC);
     // Start the merge
     $update = $db->prepare('UPDATE link SET person_id = :new_id WHERE person_id = :old_id');
     $update->execute(array(':new_id' => $userId, ':old_id' => $mergeId));
     $update = $db->prepare('UPDATE message SET writer_id = :new_id WHERE writer_id = :old_id');
     $update->execute(array(':new_id' => $userId, ':old_id' => $mergeId));
     $update = $db->prepare('UPDATE introduction SET introducer_id = :new_id WHERE introducer_id = :old_id');
     $update->execute(array(':new_id' => $userId, ':old_id' => $mergeId));
     $update = $db->prepare('UPDATE introduction SET introducee1_id = :new_id WHERE introducee1_id = :old_id');
     $update->execute(array(':new_id' => $userId, ':old_id' => $mergeId));
     $update = $db->prepare('UPDATE introduction SET introducee2_id = :new_id WHERE introducee2_id = :old_id');
     $update->execute(array(':new_id' => $userId, ':old_id' => $mergeId));
     if (empty($userDetails['email']) && !empty($mergeDetails['email'])) {
         $update = $db->prepare('UPDATE person SET email = :email WHERE id = :id');
         $update->execute(array(':id' => $userId, ':email' => $mergeDetails['email']));
     }
     if (empty($userDetails['facebook_access_token']) && !empty($mergeDetails['facebook_access_token']) || empty($userDetails['facebook_id']) && !empty($mergeDetails['facebook_id'])) {
         // Copy the Facebook profile from the merge account, cascading down to the temp tables
         $delete = $db->prepare('DELETE FROM facebook WHERE person_id = :new_id');
         $delete->execute(array(':new_id' => $userId));
         $update = $db->prepare('UPDATE facebook SET person_id = :new_id WHERE person_id = :old_id');
         $update->execute(array(':new_id' => $userId, ':old_id' => $mergeId));
     }
     if (empty($userDetails['linkedin_access_token']) && !empty($mergeDetails['linkedin_access_token']) || empty($userDetails['linkedin_id']) && !empty($mergeDetails['linkedin_id'])) {
         // Copy the LinkedIn profile from the merge account, cascading down to the temp tables
         $delete = $db->prepare('DELETE FROM linkedin WHERE person_id = :new_id');
         $delete->execute(array(':new_id' => $userId));
         $update = $db->prepare('UPDATE linkedin SET person_id = :new_id WHERE person_id = :old_id');
         $update->execute(array(':new_id' => $userId, ':old_id' => $mergeId));
     }
     if (empty($userDetails['twitter_access_token']) && !empty($mergeDetails['twitter_access_token']) || empty($userDetails['twitter_id']) && !empty($mergeDetails['twitter_id'])) {
         // Copy the Twitter profile from the merge account, cascading down to the temp tables
         $delete = $db->prepare('DELETE FROM twitter WHERE person_id = :new_id');
         $delete->execute(array(':new_id' => $userId));
         $update = $db->prepare('UPDATE twitter SET person_id = :new_id WHERE person_id = :old_id');
         $update->execute(array(':new_id' => $userId, ':old_id' => $mergeId));
     }
     $delete = $db->prepare('DELETE FROM person WHERE id = :old_id');
     $delete->execute(array(':old_id' => $mergeId));
     unset($_SESSION['mergeOtherAccount']);
     unset($_SESSION['mergeNetwork']);
     // Redirect to home page
     $_SESSION['connectedWithNewNetwork'] = $mergeNetwork;
     header('Location: ' . APP_URL . '/' . Content::l() . '/');
 }
 private function validateIntroductionParams()
 {
     if (empty($_GET['base62IntroductionId']) && empty($_GET['base62LinkId'])) {
         Debug::l('No introduction id or link id');
         header('Location: ' . APP_URL . '/' . Content::l() . '/');
         exit;
     }
     if (!empty($_GET['base62IntroductionId'])) {
         // The page has been passed an introduction ID
         if (preg_match('/^[0-9a-zA-Z]+$/', $_GET['base62IntroductionId']) == 0) {
             Debug::l('Invalid introduction id. Not base 62 compatible.');
             header('Location: ' . APP_URL . '/' . Content::l() . '/');
             exit;
         }
         // Convert the ID from base 62 to base 10
         $password = substr($_GET['base62IntroductionId'], 0, 3);
         $this->id = BaseConvert::base62ToBase10(substr($_GET['base62IntroductionId'], 3));
         // Make sure this introduction ID exists and the password is correct
         $introDetailsQ = $this->db->prepare('SELECT link_password FROM introduction WHERE id = :id');
         $introDetailsQ->execute(array(':id' => $this->id));
         $introDetails = $introDetailsQ->fetch(PDO::FETCH_ASSOC);
         if (empty($introDetails['link_password']) || $introDetails['link_password'] != $password) {
             Debug::l("That introduction id '{$this->id}' does not exist or the password '{$password}' is incorrect.");
             header('Location: ' . APP_URL . '/' . Content::l() . '/');
             exit;
         }
     } else {
         // The page has been passed a base 62 encoded link ID
         if (preg_match('/^[0-9a-zA-Z]+$/', $_GET['base62LinkId']) == 0) {
             Debug::l('Invalid link id. Not base 62 compatible.');
             header('Location: ' . APP_URL . '/' . Content::l() . '/');
             exit;
         }
         // Convert the ID from base 62 to base 10
         $password = substr($_GET['base62LinkId'], 0, 3);
         $linkId = BaseConvert::base62ToBase10(substr($_GET['base62LinkId'], 3));
         // Make sure this link ID exists
         $introDetailsQ = $this->db->prepare('SELECT introduction_id, person_id, link_password FROM link WHERE id = :id');
         $introDetailsQ->execute(array(':id' => $linkId));
         $introDetails = $introDetailsQ->fetch(PDO::FETCH_ASSOC);
         if (empty($introDetails['link_password']) || $introDetails['link_password'] != $password) {
             Debug::l("That link id '{$linkId}' does not exist or the password '{$password}' is incorrect.");
             header('Location: ' . APP_URL . '/' . Content::l() . '/');
             exit;
         }
         $this->id = $introDetails['introduction_id'];
         $this->targetUser = $introDetails['person_id'];
     }
 }
示例#14
0
 private function printAccessTokenError($e)
 {
     Debug::l('Error loading ' . $this->network . ' friends ' . $e);
     $json['result'] = 'false';
     $json['redirect'] = 'true';
     $json['title'] = (string) Content::c()->errors->auth->title;
     $json['message'] = str_replace('SOCIAL_NETWORK_NAME', $this->network, Content::c()->errors->auth->invalid_access_token);
     echo json_encode($json);
     exit;
 }
示例#15
0
 private function finishPublishToFacebook()
 {
     // See if we can get a picture of the other introducee
     if ($this->other->getLinkedInId() != null) {
         $picture = $this->other->getLinkedInPicture();
     }
     if (!isset($picture) && $this->other->getTwitterId() != null) {
         $picture = $this->other->getTwitterPicture();
     }
     if (!isset($picture) && $this->other->getFacebookId() != null) {
         // Shorten the picture URL with BITLY so we can publish it on Facebook
         $results = bitly_v3_shorten('https://graph.facebook.com/' . $this->other->getFacebookId() . '/picture?type=normal', 'j.mp');
         if (!empty($results['url'])) {
             $picture = $results['url'];
         }
     }
     try {
         $params = array('description' => ' ', 'caption' => str_replace('INTRODUCEE_NAME', $this->other->getName(), str_replace('INTRODUCER_NAME', $this->userName, Content::c()->introduce->notification)), 'link' => $this->introductionUrl, 'name' => $this->other->getName(), 'access_token' => $this->userDetails['facebook_access_token']);
         if (!empty($picture)) {
             $params['picture'] = $picture;
         }
         $statusUpdate = SessionManager::getInstance()->getFacebook()->api('/' . $this->introducee->getFacebookId() . '/feed', 'POST', $params);
     } catch (FacebookApiException $e) {
         // Could not post to Facebook.
         Debug::l('Error posting to Facebook ' . $e);
         return false;
     }
     return true;
 }