public function process_request($request)
 {
     if ($request == 'facebook-login') {
         $app_id = qa_opt('facebook_app_id');
         $app_secret = qa_opt('facebook_app_secret');
         $tourl = qa_get('to');
         if (!strlen($tourl)) {
             $tourl = qa_path_absolute('');
         }
         if (strlen($app_id) && strlen($app_secret)) {
             require_once $this->directory . 'facebook.php';
             $facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true));
             $fb_userid = $facebook->getUser();
             if ($fb_userid) {
                 try {
                     $user = $facebook->api('/me?fields=email,name,verified,location,website,about,picture.width(250)');
                     if (is_array($user)) {
                         qa_log_in_external_user('facebook', $fb_userid, array('email' => @$user['email'], 'handle' => @$user['name'], 'confirmed' => @$user['verified'], 'name' => @$user['name'], 'location' => @$user['location']['name'], 'website' => @$user['website'], 'about' => @$user['bio'], 'avatar' => strlen(@$user['picture']['data']['url']) ? qa_retrieve_url($user['picture']['data']['url']) : null));
                     }
                 } catch (FacebookApiException $e) {
                 }
             } else {
                 qa_redirect_raw($facebook->getLoginUrl(array('redirect_uri' => $tourl)));
             }
         }
         qa_redirect_raw($tourl);
     }
 }
 function check_login()
 {
     if (!isset($_COOKIE["qa-login_fname"]) && !isset($_SESSION["qa-login_fname"])) {
         return false;
     } else {
         if (isset($_COOKIE["bdops-login_fname"])) {
             $fname = $_COOKIE["qa-login_fname"];
             $lname = $_COOKIE["qa-login_lname"];
             $email = $_COOKIE["qa-login_email"];
             $username = $_COOKIE["qa-login_user"];
         } else {
             $fname = $_SESSION["qa-login_fname"];
             $lname = $_SESSION["qa-login_lname"];
             $email = $_SESSION["qa-login_email"];
             $username = $_SESSION["qa-login_user"];
         }
         $source = 'ldap';
         $identifier = $email;
         $fields['email'] = $email;
         $fields['confirmed'] = true;
         $fields['handle'] = $username;
         $fields['name'] = $fname . " " . $lname;
         qa_log_in_external_user($source, $identifier, $fields);
     }
 }
 /**
  * 
  * @param NKUser $userData
  */
 private function join_or_add(NKUser $userData)
 {
     $email_users = qa_db_user_find_by_email($userData->email());
     if (count($email_users) === 1) {
         $this->join_user_data($email_users[0], $userData);
     }
     qa_log_in_external_user(Q2ANKConnect::LOGIN_SOURCE, $userData->id(), array('email' => $userData->email(), 'avatar' => $userData->thumbnailUrl(), 'name' => $userData->name(), 'confirmed' => true, 'handle' => $this->generateUserHandle($userData)));
 }
 function check_login()
 {
     // Based on sample code: http://developers.facebook.com/docs/guides/web
     $testfacebook = false;
     foreach ($_COOKIE as $key => $value) {
         if (substr($key, 0, 5) == 'fbsr_') {
             $testfacebook = true;
         }
     }
     if (!$testfacebook) {
         // to save making a database query for qa_opt() if there's no point
         return;
     }
     $app_id = qa_opt('facebook_app_id');
     $app_secret = qa_opt('facebook_app_secret');
     if (!(strlen($app_id) && strlen($app_secret))) {
         return;
     }
     if (!function_exists('json_decode')) {
         // work around fact that PHP might not have JSON extension installed
         require_once $this->directory . 'JSON.php';
         function json_decode($json)
         {
             $decoder = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
             return $decoder->decode($json);
         }
     }
     require_once $this->directory . 'facebook.php';
     $facebook = new Facebook(array('appId' => qa_opt('facebook_app_id'), 'secret' => qa_opt('facebook_app_secret'), 'cookie' => true));
     $fb_userid = $facebook->getUser();
     if ($fb_userid) {
         try {
             $user = $facebook->api('/me?fields=email,name,verified,location,website,about,picture');
             if (is_array($user)) {
                 qa_log_in_external_user('facebook', $fb_userid, array('email' => @$user['email'], 'handle' => @$user['name'], 'confirmed' => @$user['verified'], 'name' => @$user['name'], 'location' => @$user['location']['name'], 'website' => @$user['website'], 'about' => @$user['bio'], 'avatar' => strlen(@$user['picture']) ? qa_retrieve_url($user['picture']) : null));
             }
         } catch (FacebookApiException $e) {
             $facebookuserid = null;
         }
     }
 }
 function check_login()
 {
     // Based on sample code: http://developers.facebook.com/docs/guides/web
     $testfacebook = false;
     foreach ($_COOKIE as $key => $value) {
         if (substr($key, 0, 4) == 'fbs_') {
             $testfacebook = true;
         }
     }
     if (!$testfacebook) {
         // to save making a database query for qa_opt() if there's no point
         return;
     }
     $app_id = qa_opt('facebook_app_id');
     $app_secret = qa_opt('facebook_app_secret');
     if (!(strlen($app_id) && strlen($app_secret))) {
         return;
     }
     if (isset($_COOKIE['fbs_' . $app_id])) {
         $args = array();
         parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
         ksort($args);
         $payload = '';
         foreach ($args as $key => $value) {
             if ($key != 'sig') {
                 $payload .= $key . '=' . $value;
             }
         }
         if (md5($payload . qa_opt('facebook_app_secret')) == $args['sig']) {
             $rawuser = qa_retrieve_url('https://graph.facebook.com/me?access_token=' . $args['access_token'] . '&fields=email,name,verified,location,website,about,picture');
             if (strlen($rawuser)) {
                 require_once $this->directory . 'JSON.php';
                 $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
                 $user = $json->decode($rawuser);
                 if (is_array($user)) {
                     qa_log_in_external_user('facebook', $args['uid'], array('email' => @$user['email'], 'handle' => @$user['name'], 'confirmed' => @$user['verified'], 'name' => @$user['name'], 'location' => @$user['location']['name'], 'website' => @$user['website'], 'about' => @$user['about'], 'avatar' => strlen(@$user['picture']) ? qa_retrieve_url($user['picture']) : null));
                 }
             }
         }
     }
 }
 function process_request($request)
 {
     if ($request == 'facebook-login') {
         $app_id = qa_opt('facebook_app_id');
         $app_secret = qa_opt('facebook_app_secret');
         $tourl = qa_get('to');
         if (!strlen($tourl)) {
             $tourl = qa_path_absolute('');
         }
         if (strlen($app_id) && strlen($app_secret)) {
             if (!function_exists('json_decode')) {
                 // work around fact that PHP might not have JSON extension installed
                 require_once $this->directory . 'JSON.php';
                 function json_decode($json)
                 {
                     $decoder = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
                     return $decoder->decode($json);
                 }
             }
             require_once $this->directory . 'facebook.php';
             $facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true));
             $fb_userid = $facebook->getUser();
             if ($fb_userid) {
                 try {
                     $user = $facebook->api('/me?fields=email,name,verified,location,website,about,picture');
                     if (is_array($user)) {
                         qa_log_in_external_user('facebook', $fb_userid, array('email' => @$user['email'], 'handle' => @$user['name'], 'confirmed' => @$user['verified'], 'name' => @$user['name'], 'location' => @$user['location']['name'], 'website' => @$user['website'], 'about' => @$user['bio'], 'avatar' => strlen(@$user['picture']['data']['url']) ? qa_retrieve_url($user['picture']['data']['url']) : null));
                     }
                 } catch (FacebookApiException $e) {
                 }
             } else {
                 qa_redirect_raw($facebook->getLoginUrl(array('redirect_uri' => $tourl)));
             }
         }
         qa_redirect_raw($tourl);
     }
 }
示例#7
0
 function check_login()
 {
     $action = null;
     $key = null;
     if (!empty($_GET['hauth_start'])) {
         $key = trim(strip_tags($_GET['hauth_start']));
         $action = 'process';
     } else {
         if (!empty($_GET['hauth_done'])) {
             $key = trim(strip_tags($_GET['hauth_done']));
             $action = 'process';
         } else {
             if (!empty($_GET['login'])) {
                 $key = trim(strip_tags($_GET['login']));
                 $action = 'login';
             } else {
                 if (isset($_GET['fb_source']) && $_GET['fb_source'] == 'appcenter' && isset($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'], 'www.facebook.com') !== false && isset($_GET['fb_appcenter']) && $_GET['fb_appcenter'] == '1' && isset($_GET['code'])) {
                     // allow AppCenter users to login directly
                     $key = 'facebook';
                     $action = 'login';
                 }
             }
         }
     }
     if ($key == null || strcasecmp($key, $this->provider) != 0) {
         return false;
     }
     if ($action == 'login') {
         // handle the login
         // after login come back to the same page
         $loginCallback = qa_path('', array(), qa_opt('site_url'));
         require_once $this->directory . 'Hybrid/Auth.php';
         require_once $this->directory . 'qa-open-utils.php';
         // prepare the configuration of HybridAuth
         $config = $this->getConfig($loginCallback);
         $topath = qa_get('to');
         if (!isset($topath)) {
             $topath = '';
             // redirect to front page
         }
         try {
             // try to login
             $hybridauth = new Hybrid_Auth($config);
             $adapter = $hybridauth->authenticate($this->provider);
             // if ok, create/refresh the user account
             $user = $adapter->getUserProfile();
             $duplicates = 0;
             if (!empty($user)) {
                 $duplicates = qa_log_in_external_user($key, $user->identifier, array('email' => @$user->email, 'handle' => @$user->displayName, 'confirmed' => !empty($user->emailVerified), 'name' => @$user->displayName, 'location' => @$user->region, 'website' => @$user->webSiteURL, 'about' => @$user->description, 'avatar' => strlen(@$user->photoURL) ? qa_retrieve_url($user->photoURL) : null));
             }
             if ($duplicates > 0) {
                 qa_redirect('logins', array('confirm' => '1', 'to' => $topath));
             } else {
                 qa_redirect_raw(qa_opt('site_url') . $topath);
             }
         } catch (Exception $e) {
             // not really interested in the error message - for now
             // however, in case we have errors 6 or 7, then we have to call logout to clean everything up
             if ($e->getCode() == 6 || $e->getCode() == 7) {
                 $adapter->logout();
             }
             $qry = 'provider=' . $this->provider . '&code=' . $e->getCode();
             if (strstr($topath, '?') === false) {
                 $topath .= '?' . $qry;
             } else {
                 $topath .= '&' . $qry;
             }
             // redirect
             qa_redirect_raw(qa_opt('site_url') . $topath);
         }
     }
     if ($action == 'process') {
         require_once "Hybrid/Auth.php";
         require_once "Hybrid/Endpoint.php";
         Hybrid_Endpoint::process();
     }
     return false;
 }