public static function finishAuth() { Social_Client::init(); $network_name = trim(strip_tags(Social_Client::$request["sa_login_finish"])); $network = Social_Auth::prepare($network_name); if (!$network) { Social_Logger::error("Invalid parameter given on sa_login_finish"); $network->adapter->disconnectUser(); header("HTTP/1.0 404 Not Found"); die("Invalid parameter given on sa_login_finish. Try login again"); } try { Social_Logger::info("Login finish: {$network_name}"); $network->adapter->finishLogin(); $user_profile = $network->adapter->getUserProfile(); if ($network_name == 'facebook') { $user_profile->photoURL = $user_profile->photoURL . '&ts=' . getTimeStamp(); } $user_profile->network_name = $network_name; $userid = socialLogin($user_profile); Social_Auth::session()->set("SA_USER", $user_profile); } catch (Exception $e) { $network->adapter->disconnectUser(); } Social_Logger::info("Returned to callback"); $network->goToCallbackPage(); die; }
public static function finishAuth() { Social_Client::init(); $network_name = trim(strip_tags(Social_Client::$request["sa_login_finish"])); $network = Social_Auth::prepare($network_name); if (!$network) { Social_Logger::error("Invalid parameter given on sa_login_finish"); $network->adapter->disconnectUser(); header("HTTP/1.0 404 Not Found"); die("Invalid parameter given on sa_login_finish. Try login again"); } try { Social_Logger::info("Login finish: {$network_name}"); $network->adapter->finishLogin(); $user_profile = $network->adapter->getUserProfile(); if ($network_name == 'facebook') { $user_profile->photoURL = $user_profile->photoURL . '&ts=' . getTimeStamp(); } $sql = "select " . DB_USERTABLE . "." . DB_USERTABLE_USERID . " from " . DB_USERTABLE . " where " . DB_USERTABLE . "." . DB_USERTABLE_USERNAME . " = '" . mysqli_real_escape_string($GLOBALS['dbh'], $network_name) . "_" . mysqli_real_escape_string($GLOBALS['dbh'], $user_profile->identifier) . "'"; $result = mysqli_query($GLOBALS['dbh'], $sql); if ($row = mysqli_fetch_assoc($result)) { $sql = "update " . DB_USERTABLE . " set " . DB_USERTABLE . "." . DB_USERTABLE_NAME . "='" . mysqli_real_escape_string($GLOBALS['dbh'], $user_profile->firstName) . "'," . DB_AVATARFIELD . "='" . mysqli_real_escape_string($GLOBALS['dbh'], $user_profile->photoURL) . "'," . DB_USERTABLE . "." . DB_LINKFIELD . "='" . mysqli_real_escape_string($GLOBALS['dbh'], $user_profile->profileURL) . "' where " . DB_USERTABLE . "." . DB_USERTABLE_USERNAME . "='" . mysqli_real_escape_string($GLOBALS['dbh'], $network_name) . "_" . mysqli_real_escape_string($GLOBALS['dbh'], $user_profile->identifier) . "'"; mysqli_query($GLOBALS['dbh'], $sql); if (!empty($row[DB_USERTABLE_USERID])) { $userid = $row[DB_USERTABLE_USERID]; } } else { $sql = "insert into " . DB_USERTABLE . " (" . DB_USERTABLE . "." . DB_USERTABLE_USERNAME . "," . DB_USERTABLE . "." . DB_USERTABLE_NAME . "," . DB_AVATARFIELD . "," . DB_USERTABLE . "." . DB_LINKFIELD . "," . DB_USERTABLE . "." . DB_GROUPFIELD . ") values ( '" . mysqli_real_escape_string($GLOBALS['dbh'], $network_name) . "_" . mysqli_real_escape_string($GLOBALS['dbh'], $user_profile->identifier) . "','" . mysqli_real_escape_string($GLOBALS['dbh'], $user_profile->firstName) . "','" . mysqli_real_escape_string($GLOBALS['dbh'], $user_profile->photoURL) . "','" . mysqli_real_escape_string($GLOBALS['dbh'], $user_profile->profileURL) . "','" . mysqli_real_escape_string($GLOBALS['dbh'], ucfirst($network_name)) . "')"; mysqli_query($GLOBALS['dbh'], $sql); $userid = mysqli_insert_id($GLOBALS['dbh']); } $_SESSION['cometchat']['userid'] = $userid; $_SESSION['cometchat']['ccauth'] = '1'; Social_Auth::session()->set("SA_USER", $user_profile); } catch (Exception $e) { $network->adapter->disconnectUser(); } Social_Logger::info("Returned to callback"); $network->goToCallbackPage(); die; }
public static function redirect($url) { Social_Logger::info("###Social_Auth::redirect( {$url} )"); header("Location: {$url}"); die; }
public function __call($name, $arguments) { Social_Logger::info("###Social_Adapter::{$name}(), Network: {$this->network_name}"); if (!$this->isUserConnected()) { throw new Social_Exception("User not logged in to network: {$this->network_name}"); } if (!method_exists($this->adapter, $name)) { throw new Social_Exception("_call undefined function Social_Network_{$this->network_name}::{$name}()"); } if (count($arguments)) { return $this->adapter->{$name}($arguments[0]); } else { return $this->adapter->{$name}(); } }
public function connectUser() { Social_Logger::info("###{$this->network_name}::connectUser()"); Social_Auth::session()->set("sa_session.{$this->network_name}.logged_in", 1); }
/** * Make http request */ function request($url, $method, $postfields = NULL, $auth_header = null) { Social_Logger::info("Enter OAuth1Client::request( {$method}, {$url} )"); Social_Logger::debug("OAuth1Client::request(). dump post fields: ", serialize($postfields)); $this->http_info = array(); $ci = curl_init(); /* Curl settings */ curl_setopt($ci, CURLOPT_USERAGENT, $this->curl_useragent); curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->curl_connect_time_out); curl_setopt($ci, CURLOPT_TIMEOUT, $this->curl_time_out); curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->curl_ssl_verifypeer); curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader')); curl_setopt($ci, CURLOPT_HEADER, FALSE); if ($this->curl_proxy) { curl_setopt($ci, CURLOPT_PROXY, $this->curl_proxy); } switch ($method) { case 'POST': curl_setopt($ci, CURLOPT_POST, TRUE); if (!empty($postfields)) { curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields); } if (!empty($auth_header) && $this->curl_auth_header) { curl_setopt($ci, CURLOPT_HTTPHEADER, array('Content-Type: application/atom+xml', $auth_header)); } break; case 'DELETE': curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE'); if (!empty($postfields)) { $url = "{$url}?{$postfields}"; } } curl_setopt($ci, CURLOPT_URL, $url); $response = curl_exec($ci); Social_Logger::debug("OAuth1Client::request(). dump request info: ", serialize(curl_getinfo($ci))); Social_Logger::debug("OAuth1Client::request(). dump request result: ", serialize($response)); $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE); $this->http_info = array_merge($this->http_info, curl_getinfo($ci)); curl_close($ci); return $response; }
private function request($url, $params = false, $type = "GET") { Social_Logger::info("Enter OAuth2Client::request( {$url} )"); Social_Logger::debug("OAuth2Client::request(). dump request params: ", serialize($params)); if ($type == "GET") { $url = $url . (strpos($url, '?') ? '&' : '?') . http_build_query($params); } $this->http_info = array(); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, $this->curl_time_out); curl_setopt($ch, CURLOPT_USERAGENT, $this->curl_useragent); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->curl_connect_time_out); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->curl_ssl_verifypeer); curl_setopt($ch, CURLOPT_HTTPHEADER, $this->curl_header); if ($this->curl_proxy) { curl_setopt($ch, CURLOPT_PROXY, $this->curl_proxy); } if ($type == "POST") { curl_setopt($ch, CURLOPT_POST, 1); if ($params) { curl_setopt($ch, CURLOPT_POSTFIELDS, $params); } } $response = curl_exec($ch); Social_Logger::debug("OAuth2Client::request(). dump request info: ", serialize(curl_getinfo($ch))); Social_Logger::debug("OAuth2Client::request(). dump request result: ", serialize($response)); $this->http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $this->http_info = array_merge($this->http_info, curl_getinfo($ch)); curl_close($ch); return $response; }