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;
     }
 }
 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);
 }
Exemplo n.º 3
0
    private function previousIntroductions()
    {
        $output = '';
        $introductionsQ = $this->db->prepare('SELECT i.id, i.introducer_id, introducer.name as introducer_name, i.introducee1_id, in1.name as introducee1_name, i.introducee2_id, in2.name as introducee2_name, i.time, i.link_password
			FROM introduction i
			LEFT JOIN person introducer ON introducer.id = i.introducer_id
			LEFT JOIN person in1 ON in1.id = i.introducee1_id
			LEFT JOIN person in2 ON in2.id = i.introducee2_id
			WHERE (i.introducer_id = :id OR i.introducee1_id = :id OR i.introducee2_id = :id)
			ORDER BY time DESC');
        $introductionsQ->execute(array(':id' => $this->userId));
        $introductions = $introductionsQ->fetchAll(PDO::FETCH_ASSOC);
        if (!empty($introductions)) {
            $you = (string) Content::c()->home->you;
            $youCapital = (string) Content::c()->home->you_capital;
            $story = (string) Content::c()->home->story;
            $output .= '<div id="previousIntroductions"><h2>' . Content::c()->home->history . '</h2>';
            foreach ($introductions as $introd) {
                $url = APP_URL . '/' . Content::l() . '/A' . $introd['link_password'] . BaseConvert::base10ToBase62($introd['id']);
                if ($this->userId == $introd['introducer_id']) {
                    $output .= '<p><a href="' . $url . '">' . str_replace('INTRODUCEE1_NAME', '<strong>' . $introd['introducee1_name'] . '</strong>', str_replace('INTRODUCEE2_NAME', '<strong>' . $introd['introducee2_name'] . '</strong>', str_replace('INTRODUCER_NAME', $youCapital, $story))) . '</a></p>';
                } elseif ($this->userId == $introd['introducee1_id']) {
                    $output .= '<p><a href="' . $url . '">' . str_replace('INTRODUCEE1_NAME', $you, str_replace('INTRODUCEE2_NAME', '<strong>' . $introd['introducee2_name'] . '</strong>', str_replace('INTRODUCER_NAME', '<strong>' . $introd['introducer_name'] . '</strong>', $story))) . '</a></p>';
                } else {
                    $output .= '<p><a href="' . $url . '">' . str_replace('INTRODUCEE1_NAME', $you, str_replace('INTRODUCEE2_NAME', '<strong>' . $introd['introducee1_name'] . '</strong>', str_replace('INTRODUCER_NAME', '<strong>' . $introd['introducer_name'] . '</strong>', $story))) . '</a></p>';
                }
                $output .= $this->formatTime(strtotime($introd['time']));
            }
            $output .= '</div>';
        }
        return $output;
    }
Exemplo n.º 4
0
 private function showConnectedProfiles()
 {
     $output = '<div class="clearfix networks">';
     $facebookLoginUrl = SessionManager::getInstance()->getFacebook()->getLoginUrl(array('redirect_uri' => APP_URL . '/' . Content::l() . '/login/facebookcallback/' . Content::l() . '/settings/', 'scope' => 'publish_stream'));
     $linkedInLoginUrl = APP_URL . '/' . Content::l() . '/login/linkedin/' . Content::l() . '/settings/';
     $twitterLoginUrl = APP_URL . '/' . Content::l() . '/login/twitter/' . Content::l() . '/settings/';
     // Facebook
     $output .= '<div class="clearfix">';
     if ($this->userDetails['facebook_access_token']) {
         $output .= '<a href="' . $facebookLoginUrl . '" id="loginFacebook" class="ir loggedIn">Facebook</a>' . '<a href="/' . Content::l() . '/ajax/disconnect/?network=Facebook" class="disconnect">' . str_replace('SOCIAL_NETWORK_NAME', 'Facebook', Content::c()->settings->disconnect) . '</a>';
     } else {
         $output .= '<a href="' . $facebookLoginUrl . '" id="loginFacebook" class="ir">Facebook</a>' . '<a href="' . $facebookLoginUrl . '" class="connect">' . str_replace('SOCIAL_NETWORK_NAME', 'Facebook', Content::c()->settings->connect) . '</a>';
     }
     // LinkedIn
     $output .= '</div><div class="clearfix">';
     if ($this->userDetails['linkedin_access_token']) {
         $output .= '<a href="' . $linkedInLoginUrl . '" id="loginLinkedIn" class="ir loggedIn">LinkedIn</a>' . '<a href="/' . Content::l() . '/ajax/disconnect/?network=LinkedIn" class="disconnect">' . str_replace('SOCIAL_NETWORK_NAME', 'LinkedIn', Content::c()->settings->disconnect) . '</a>';
     } else {
         $output .= '<a href="' . $linkedInLoginUrl . '" id="loginLinkedIn" class="ir">LinkedIn</a>' . '<a href="' . $linkedInLoginUrl . '" class="connect">' . str_replace('SOCIAL_NETWORK_NAME', 'LinkedIn', Content::c()->settings->connect) . '</a>';
     }
     // Twitter
     $output .= '</div><div class="clearfix">';
     if ($this->userDetails['twitter_access_token']) {
         $output .= '<a href="' . $twitterLoginUrl . '" id="loginTwitter" class="ir loggedIn">Twitter</a>' . '<a href="/' . Content::l() . '/ajax/disconnect/?network=Twitter" class="disconnect">' . str_replace('SOCIAL_NETWORK_NAME', 'Twitter', Content::c()->settings->disconnect) . '</a>';
     } else {
         $output .= '<a href="' . $twitterLoginUrl . '" id="loginTwitter" class="ir">Twitter</a>' . '<a href="' . $twitterLoginUrl . '" class="connect">' . str_replace('SOCIAL_NETWORK_NAME', 'Twitter', Content::c()->settings->connect) . '</a>';
     }
     $output .= '</div></div>';
     return $output;
 }
Exemplo n.º 5
0
 public function __construct()
 {
     session_start();
     // Log the user out
     new Logout();
     // Redirect to the home page
     header('Location: ' . APP_URL . '/' . Content::l() . '/');
 }
Exemplo n.º 6
0
 public function __construct()
 {
     session_start();
     // 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);
     // Send a request for a LinkedIn access token
     $response = $linkedIn->retrieveTokenRequest();
     if ($response['success'] === TRUE) {
         // Split up the response and stick the LinkedIn portion in the user session
         $_SESSION['oauth']['linkedin']['request'] = $response['linkedin'];
         // Redirect the user to the LinkedIn authentication/authorisation page to initiate validation.
         header('Location: ' . LINKEDIN::_URL_AUTH . $_SESSION['oauth']['linkedin']['request']['oauth_token']);
     } else {
         $this->exitWithMessage('Unable to retrieve access token for LinkedIn');
     }
 }
 protected final function insertOrUpdateUser()
 {
     // Is there an existing user with this profile?
     if (!empty($this->userDetails)) {
         // Is this profile used by a different user?
         if (!empty($_SESSION['loggedInPersonId']) && $_SESSION['loggedInPersonId'] != $this->userDetails['person_id']) {
             Debug::l('That ' . $this->network . ' profile is already linked to a different user account');
             $_SESSION['mergeNetwork'] = $this->network;
             $_SESSION['mergeOtherAccount'] = $this->userDetails['person_id'];
             $this->updateAccessToken();
             header('Location: ' . APP_URL . '/' . Content::l() . '/merge-accounts/');
             exit;
         } else {
             Debug::l('Returning user has logged in with ' . $this->network . ' again');
             $this->updateAccessToken();
             // Update the person's name if it has been loaded
             if (!empty($this->name)) {
                 $updateNameQ = $this->db->prepare('UPDATE person SET name = :name WHERE id = :id');
                 $updateNameQ->execute(array(':name' => $this->name, ':id' => $this->userDetails['person_id']));
             }
             // Save the user's id to the session
             $_SESSION['loggedInPersonId'] = $this->userDetails['person_id'];
         }
     } else {
         // This profile hasn't been added to the database before
         // Save the network name to the session so we can display a thankyou message
         $_SESSION['connectedWithNewNetwork'] = $this->network;
         // Is a user already logged in?
         if (!empty($_SESSION['loggedInPersonId'])) {
             Debug::l('Returning user connected ' . $this->network . ' to their account for the first time');
             $this->insertProfile();
         } else {
             Debug::l('New user has logged in with ' . $this->network);
             if (empty($this->name)) {
                 $this->loadName();
             }
             $this->insertPerson();
             $this->insertProfile();
         }
     }
 }
 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);
 }
Exemplo n.º 9
0
 public function __construct()
 {
     session_start();
     // Create TwitterOAuth object with app key/secret
     $twitter = new TwitterOAuth(TW_CONSUMER, TW_SECRET);
     $callback = APP_URL . '/' . Content::l() . '/login/twittercallback/' . (!empty($_GET['nextPage']) ? $_GET['nextPage'] : '');
     // Get temporary credentials
     $requestToken = $twitter->getRequestToken($callback);
     // Save temporary credentials to session
     $_SESSION['twitterOAuthToken'] = $token = $requestToken['oauth_token'];
     $_SESSION['twitterOAuthTokenSecret'] = $requestToken['oauth_token_secret'];
     // If last connection failed don't display authorization link
     if ($twitter->http_code == 200) {
         // Build authorize URL and redirect user to Twitter
         $url = $twitter->getAuthorizeURL($token);
         header('Location: ' . $url);
         exit;
     } else {
         $this->exitWithMessage('Could not connect to Twitter. Refresh the page or try again later.');
     }
 }
Exemplo n.º 10
0
 public function __construct()
 {
     session_start();
     $this->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;
     }
     $this->mergeNetwork = $_SESSION['mergeNetwork'];
     $mergeOtherAccount = $_SESSION['mergeOtherAccount'];
     // Get the website user
     $userId = SessionManager::getInstance()->getUserId();
     if (!isset($userId)) {
         // No user logged in
         Debug::l('No user logged in');
         header('Location: ' . APP_URL . '/' . Content::l() . '/');
         exit;
     }
     // Load user data
     $userDetailsQ = $this->db->prepare('SELECT 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);
     $profiles = $this->loadProfiles($userDetails, true);
     // Load data for other account
     $userDetailsQ->execute(array(':id' => $mergeOtherAccount));
     $otherAccount = $userDetailsQ->fetch(PDO::FETCH_ASSOC);
     array_merge($profiles, $this->loadProfiles($otherAccount, false));
     $top = new Top('', 'mergeAccountsPage');
     echo $top->getOutput();
     echo '<h1>' . str_replace('SOCIAL_NETWORK_NAME', $this->mergeNetwork, Content::c()->merge_accounts->notice) . '</h1>' . '<p class="question">' . (count($profiles) == 2 ? Content::c()->merge_accounts->question_two_profiles : Content::c()->merge_accounts->question_more_profiles) . '</p>';
     foreach ($profiles as $profile) {
         echo $profile;
     }
     echo '<form action="/' . Content::l() . '/logout/" method="post" class="no">' . '<input type="submit" class="button" value="' . Content::c()->merge_accounts->n . '" />' . '</form>' . '<form action="/' . Content::l() . '/ajax/merge-accounts/" method="post" class="yes">' . '<input type="submit" class="button" value="' . Content::c()->merge_accounts->y . '" />' . '</form>' . '<p class="note">' . Content::c()->merge_accounts->note . '</p>';
     $bottom = new Bottom('');
     echo $bottom->getOutput();
 }
Exemplo n.º 11
0
 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/');
 }
Exemplo n.º 12
0
 public function __construct($script = '')
 {
     $this->userId = SessionManager::getInstance()->getUserId();
     $this->output = '</div>' . '<div class="footer"><footer>' . '<a href="/' . Content::l() . '/" class="home">' . Content::c()->home->home . '</a>' . '<a href="/' . Content::l() . '/about/" class="about">' . Content::c()->about->about . '</a>' . '<a href="http://introduceme.uservoice.com/forums/99481-general" class="feedback">' . Content::c()->feedback . '</a>' . (!empty($this->userId) ? '<a href="/' . Content::l() . '/settings/" class="settings">' . Content::c()->settings->title . '</a>' . '<a href="/' . Content::l() . '/logout/" class="logout">' . Content::c()->logout . '</a>' : '') . '</footer></div>' . '<script src="/js/plugins.js"></script>' . '<script src="/js/introduceme.js"></script>' . $script . '<script>' . 'var _gaq = [["_setAccount", "UA-20937143-1"],["_trackPageview"]];' . '(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;g.src="//www.google-analytics.com/ga.js";s.parentNode.insertBefore(g,s);}(document,"script"));' . '</script>' . '</body>' . '</html>';
 }
Exemplo n.º 13
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);
 }
Exemplo n.º 14
0
 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 displayLoginOptions()
 {
     $output = '';
     $ui = new ViewIntroduction();
     if (isset($this->targetUser)) {
         // Get the details of the introducer
         $introducerDetailsQ = $this->db->prepare('SELECT p.name FROM person p, introduction i WHERE p.id=i.introducer_id AND i.id = :id');
         $introducerDetailsQ->execute(array(':id' => $this->id));
         $introducerDetails = $introducerDetailsQ->fetch(PDO::FETCH_ASSOC);
         $introducerName = $introducerDetails['name'];
         // Get the details of the target user
         $targetUserDetailsQ = $this->db->prepare('SELECT p.name, f.id as facebook_id, l.id as linkedin_id, t.id as twitter_id 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');
         $targetUserDetailsQ->execute(array(':id' => $this->targetUser));
         $targetUserDetails = $targetUserDetailsQ->fetch(PDO::FETCH_ASSOC);
         $targetUserName = $targetUserDetails['name'];
         $acceptedLoginServices = array();
         if (!empty($targetUserDetails['facebook_id'])) {
             $acceptedLoginServices[] = 'Facebook';
         }
         if (!empty($targetUserDetails['linkedin_id'])) {
             $acceptedLoginServices[] = 'LinkedIn';
         }
         if (!empty($targetUserDetails['twitter_id'])) {
             $acceptedLoginServices[] = 'Twitter';
         }
         // Get the details of the other introducee
         $otherIntroduceeDetailsQ = $this->db->prepare('SELECT p.name, f.id as facebook_id, l.id as linkedin_id, t.id as twitter_id FROM introduction i, 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 i.id = :introd_id AND ((i.introducee2_id = :id AND p.id = i.introducee1_id) OR (i.introducee1_id = :id AND p.id = i.introducee2_id))');
         $otherIntroduceeDetailsQ->execute(array(':introd_id' => $this->id, ':id' => $this->targetUser));
         $otherIntroduceeDetails = $otherIntroduceeDetailsQ->fetch(PDO::FETCH_ASSOC);
         $otherIntroduceeName = $otherIntroduceeDetails['name'];
         $picture = '';
         if (!empty($otherIntroduceeDetails['facebook_id'])) {
             $picture = '<img src="https://graph.facebook.com/' . $otherIntroduceeDetails['facebook_id'] . '/picture?type=normal" alt="' . $otherIntroduceeName . '" />';
         }
         if (empty($picture) && !empty($otherIntroduceeDetails['linkedin_id'])) {
             $linkedInPicQ = $this->db->prepare('SELECT picture_url FROM temp_linkedin WHERE linkedin_id = :linkedin_id');
             $linkedInPicQ->execute(array(':linkedin_id' => $otherIntroduceeDetails['linkedin_id']));
             $linkedInPic = $linkedInPicQ->fetch(PDO::FETCH_ASSOC);
             if (!empty($linkedInPic['picture_url'])) {
                 $picture = '<img src="' . $linkedInPic['picture_url'] . '" alt="' . $otherIntroduceeName . '" />';
             }
         }
         if (empty($picture) && !empty($otherIntroduceeDetails['twitter_id'])) {
             $twitterPicQ = $this->db->prepare('SELECT picture_url FROM temp_twitter WHERE twitter_id = :twitter_id');
             $twitterPicQ->execute(array(':twitter_id' => $otherIntroduceeDetails['twitter_id']));
             $twitterPic = $twitterPicQ->fetch(PDO::FETCH_ASSOC);
             if (!empty($twitterPic["picture_url"])) {
                 $picture = '<img src="' . $twitterPic['picture_url'] . '" alt="' . $otherIntroduceeName . '" />';
             }
         }
         $title = str_replace('OTHER_NAME', $otherIntroduceeName, str_replace('INTRODUCEE_NAME', $targetUserName, str_replace('INTRODUCER_NAME', $introducerName, Content::c()->view->login->title_targeted)));
     } else {
         // No target user. Generic login page with all login options.
         $title = Content::c()->view->login->title;
         $picture = '';
         $acceptedLoginServices = array('Facebook', 'LinkedIn', 'Twitter');
     }
     $output .= $ui->top();
     $pleaseLogin = str_replace('SOCIAL_NETWORK_NAME', Words::arrayToList($acceptedLoginServices, Content::c()->or), Content::c()->view->login->login);
     $output .= '<div class="login clearfix">' . $picture . '<h1>' . $title . '</h1>' . '<p class="pleaseLogin">' . $pleaseLogin . '</p>' . '<div class="loginIcons">';
     if (!empty($_GET['base62LinkId'])) {
         $nextPage = 'B' . $_GET['base62LinkId'];
     } else {
         $nextPage = 'A' . $_GET['base62IntroductionId'];
     }
     if (in_array('Facebook', $acceptedLoginServices)) {
         $facebookLoginUrl = SessionManager::getInstance()->getFacebook()->getLoginUrl(array('redirect_uri' => APP_URL . '/' . Content::l() . '/login/facebookcallback/' . $nextPage));
         $output .= '<a id="loginFacebook" class="ir" href="' . $facebookLoginUrl . '">Facebook</a>';
     }
     if (in_array('LinkedIn', $acceptedLoginServices)) {
         $output .= '<a id="loginLinkedIn" class="ir" href="/' . Content::l() . '/login/linkedin/' . $nextPage . '">LinkedIn</a>';
     }
     if (in_array('Twitter', $acceptedLoginServices)) {
         $output .= '<a id="loginTwitter" class="ir" href="/' . Content::l() . '/login/twitter/' . $nextPage . '">Twitter</a>';
     }
     $output .= '</div>';
     if (!empty($this->targetUser)) {
         $output .= '<div class="faqsContainer">' . '<p id="btnFaqs"><a href="#">' . Content::c()->view->login->help . '</a></p>' . '<div id="faqs"><h2>' . Content::c()->view->login->faqs->what->title . '</h2>' . '<p>' . Content::c()->view->login->faqs->what->body . '</p>';
         if (count($acceptedLoginServices) == 1) {
             $output .= '<h2>' . str_replace('SOCIAL_NETWORK_NAME', $acceptedLoginServices[0], Content::c()->view->login->faqs->why->title) . '</h2>' . '<p>' . str_replace('SOCIAL_NETWORK_NAME', $acceptedLoginServices[0], str_replace('TARGET_NAME', $targetUserName, str_replace('INTRODUCER_NAME', $introducerName, str_replace('INTRODUCEE_NAME', $otherIntroduceeName, Content::c()->view->login->faqs->why->body)))) . '</p>';
         }
         $output .= '<h2>' . Content::c()->view->login->faqs->spam->title . '</h2>' . '<p>' . str_replace('INTRODUCER_NAME', $introducerName, str_replace('INTRODUCEE_NAME', $otherIntroduceeName, Content::c()->view->login->faqs->spam->body)) . '</p>';
         $output .= '</div></div>';
     }
     $output .= '</div>';
     $script = '<script>' . '$(document).ready(function() {' . '_gaq.push(["_trackPageview", "/view-introduction/not-logged-in"]);' . '});' . '</script>';
     $bottom = new Bottom($script);
     $output .= $bottom->getOutput();
     return $output;
 }
Exemplo n.º 16
0
 public function __construct($content = '', $page = '')
 {
     $this->output = "<!doctype html>\n" . '<!--[if lt IE 7]><html class="no-js ie6" lang="' . Content::l() . '"><![endif]-->' . '<!--[if IE 7]><html class="no-js ie7" lang="' . Content::l() . '"><![endif]-->' . '<!--[if IE 8]><html class="no-js ie8" lang="' . Content::l() . '"><![endif]-->' . '<!--[if gt IE 8]><!--><html class="no-js" lang="' . Content::l() . '"><!--<![endif]-->' . '<head>' . '<meta charset="utf-8" />' . '<title>' . Content::c()->title . '</title>' . '<meta name="description" content="' . Content::c()->tagline . '" />' . '<meta name="author" content="Keegan Street" />' . '<meta property="og:image" content="' . APP_URL . '/images/facebook-share-image.png" />' . '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />' . '<link rel="stylesheet" href="/css/style.css" /><!-- Style source: /css/style.scss -->' . $content . '<script src="/js/modernizr.js"></script>' . '<script>' . 'var introduceme = (function (module) {' . 'module.mobile = Modernizr.mq("only all and (max-width: 640px)");' . 'module.content = module.content || {};' . 'module.content.errorAjaxTitle = "' . htmlentities(Content::c()->errors->ajax->title, ENT_QUOTES, 'UTF-8') . '";' . 'module.content.errorAjaxRefresh = "' . htmlentities(Content::c()->errors->ajax->refresh, ENT_QUOTES, 'UTF-8') . '";' . 'return module;' . '}(introduceme || {}));' . '</script>' . '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>' . '<script>window.jQuery || document.write("<script src=\'/js/jquery-1.6.min.js\'>\\x3C/script>")</script>' . '</head>' . '<body class="lang-' . Content::l() . ' ' . $page . '">' . '<div id="fb-root"></div>' . '<div class="header"><header>' . '<a href="/' . Content::l() . '/" class="home"><h1 class="ir">Introd.uce.me</h1></a>' . '<h2 class="ir">' . Content::c()->tagline . '</h2>' . '</header></div>' . '<div id="main" class="clearfix">';
 }
Exemplo n.º 17
0
 public function publishToFacebook()
 {
     $this->facebookLoginUrl = SessionManager::getInstance()->getFacebook()->getLoginUrl(array('redirect_uri' => APP_URL . '/' . Content::l() . '/login/facebookcallback/' . Content::l() . '/send-introduction/', 'scope' => 'publish_stream'));
     $output = '<h1>' . Content::c()->introduce->one_more_thing->title . '</h1><p class="desc">' . str_replace('INTRODUCEE_NAME', $this->introducee->getName(), str_replace('SOCIAL_NETWORK_NAME', 'Facebook', Content::c()->introduce->one_more_thing->body)) . '</p><p><a class="button" href="' . $this->facebookLoginUrl . '">' . Content::c()->introduce->one_more_thing->cta . '</a></p>' . '<script>_gaq.push(["_trackPageview", "/facebook-permissions-request"]);</script>';
     try {
         $fql = array('method' => 'fql.query', 'query' => 'SELECT publish_stream FROM permissions WHERE uid="' . $this->userDetails['facebook_id'] . '"', 'callback' => '');
         $permissions = SessionManager::getInstance()->getFacebook()->api($fql);
         if (!empty($permissions[0]) && !empty($permissions[0]['publish_stream'])) {
             // Publish story to Facebook
             return $this->finishPublishToFacebook();
         } else {
             Debug::l('Facebook publish_stream permissions have not been granted');
             $this->output($output);
             exit;
         }
     } catch (Exception $e) {
         Debug::l('Error retrieving permissions from Facebook ' . $e);
         $this->output($output);
         exit;
     }
 }