public static function acsses_token($code, $lr_settings){
		$redirect = JURI::root();
		$scope = urlencode('https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email');
		$params = array(
						
                'client_id=' . $lr_settings['gapikey'],
                'client_secret=' . $lr_settings['gapisecret'],
                'grant_type=authorization_code',
                'code=' . $code,
                'redirect_uri=' . ($redirect.'?provider=google'),
                'scope=' . $scope

            );
		$params = implode('&', $params);
		$url = 'https://accounts.google.com/o/oauth2/token';
        $request = json_decode(plgSystemSocialLoginTools::open_http($url, true, $params));
		
		if(empty($request)){
			echo 'Error - empty user data';
			exit;
		}		
		$url = 'https://www.googleapis.com/oauth2/v1/userinfo?access_token='.$request->access_token;
		$request = json_decode(plgSystemSocialLoginTools::open_http($url));

		if(empty($request)){
			echo 'Error - empty user data';
			exit;
		}
		else if(!empty($request->error)){
			echo 'Error - '. $request->error;
			exit;
		}
		return $request;
	}
Exemple #2
0
 public function sociallogin_getapi($ApiSecrete)
 {
     $IsAuthenticated = false;
     $lr_settings = plgSystemSocialLoginTools::sociallogin_getsettings();
     if (isset($_REQUEST['token'])) {
         $ValidateUrl = "https://hub.loginradius.com/userprofile.ashx?token=" . $_REQUEST['token'] . "&apisecrete=" . $ApiSecrete . "";
         if ($lr_settings['useapi'] == 1) {
             $curl_handle = curl_init();
             curl_setopt($curl_handle, CURLOPT_URL, $ValidateUrl);
             curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 5);
             curl_setopt($curl_handle, CURLOPT_TIMEOUT, 5);
             curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
             if (ini_get('open_basedir') == '' && (ini_get('safe_mode') == 'Off' or !ini_get('safe_mode'))) {
                 curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, 1);
                 curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
             } else {
                 curl_setopt($curl_handle, CURLOPT_HEADER, 1);
                 $url = curl_getinfo($curl_handle, CURLINFO_EFFECTIVE_URL);
                 curl_close($curl_handle);
                 $curl_handle = curl_init();
                 $url = str_replace('?', '/?', $url);
                 curl_setopt($curl_handle, CURLOPT_URL, $url);
                 curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
             }
             $JsonResponse = curl_exec($curl_handle);
             $httpCode = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE);
             if (in_array($httpCode, array(400, 401, 403, 404, 500, 503, 0)) && $httpCode != 200) {
                 return JTEXT::_('COM_LOGINRADIUS_SERVICE_AND_TIMEOUT_ERROR');
             } else {
                 if (curl_errno($curl_handle) == 28) {
                     return JTEXT::_('COM_LOGINRADIUS_SERVICE_AND_TIMEOUT_ERROR');
                 }
             }
             $UserProfile = json_decode($JsonResponse);
             curl_close($curl_handle);
             if (isset($UserProfile->ID) && $UserProfile->ID != '') {
                 $this->IsAuthenticated = true;
                 return $UserProfile;
             }
         } else {
             $JsonResponse = @file_get_contents($ValidateUrl);
             if (strpos(@$http_response_header[0], "400") !== false || strpos(@$http_response_header[0], "401") !== false || strpos(@$http_response_header[0], "403") !== false || strpos(@$http_response_header[0], "404") !== false || strpos(@$http_response_header[0], "500") !== false || strpos(@$http_response_header[0], "503") !== false) {
                 return JTEXT::_('COM_LOGINRADIUS_SERVICE_AND_TIMEOUT_ERROR');
             } else {
                 $UserProfile = json_decode($JsonResponse);
                 if (isset($UserProfile->ID) && $UserProfile->ID != '') {
                     $this->IsAuthenticated = true;
                     return $UserProfile;
                 }
             }
         }
     }
 }
Exemple #3
0
 public function sociallogin_getapi($ApiSecrete)
 {
     $IsAuthenticated = false;
     $lr_settings = plgSystemSocialLoginTools::sociallogin_getsettings();
     if (isset($_REQUEST['token'])) {
         $ValidateUrl = "https://hub.loginradius.com/userprofile.ashx?token=" . $_REQUEST['token'] . "&apisecrete=" . $ApiSecrete . "";
         if ($lr_settings['useapi'] == 1) {
             $curl_handle = curl_init();
             curl_setopt($curl_handle, CURLOPT_URL, $ValidateUrl);
             curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 3);
             curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
             if (ini_get('open_basedir') == '' && (ini_get('safe_mode') == 'Off' or !ini_get('safe_mode'))) {
                 curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, 1);
                 curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
                 $JsonResponse = curl_exec($curl_handle);
             } else {
                 curl_setopt($curl_handle, CURLOPT_HEADER, 1);
                 $url = curl_getinfo($curl_handle, CURLINFO_EFFECTIVE_URL);
                 curl_close($curl_handle);
                 $ch = curl_init();
                 $url = str_replace('?', '/?', $url);
                 curl_setopt($ch, CURLOPT_URL, $url);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                 $JsonResponse = curl_exec($ch);
                 curl_close($ch);
             }
             $UserProfile = json_decode($JsonResponse);
         } else {
             $JsonResponse = file_get_contents($ValidateUrl);
             $UserProfile = json_decode($JsonResponse);
         }
         if (isset($UserProfile->ID) && $UserProfile->ID != '') {
             $this->IsAuthenticated = true;
             return $UserProfile;
         }
     }
 }
 public static function add_newid_image($lrdata)
 {
     $profile_Image = $lrdata['thumbnail'];
     if (empty($profile_Image)) {
         $profile_Image = JURI::root() . 'media' . DS . 'com_socialloginandsocialshare' . DS . 'images' . DS . 'noimage.png';
     }
     $userImage = $lrdata['id'] . '.jpg';
     $find = strpos($userImage, 'http');
     if ($find !== false) {
         $userImage = substr($userImage, 8);
         $userImage = plgSystemSocialLoginTools::remove_unescapedChar($userImage);
     }
     $sociallogin_savepath = JPATH_ROOT . DS . 'images' . DS . 'sociallogin' . DS;
     plgSystemSocialLoginTools::insert_user_picture($sociallogin_savepath, $profile_Image, $userImage);
     return $userImage;
 }
   function _sendMail(&$user, $usermessgae) {

	 // Compile the notification mail values.
     $lr_settings = plgSystemSocialLoginTools::sociallogin_getsettings ();
	 $config = JFactory::getConfig();
	 $data = $user->getProperties();
	 $data['fromname'] = $config->get('fromname');
	 $data['mailfrom'] = $config->get('mailfrom');
	 $data['sitename'] = $config->get('sitename');
	 $data['siteurl'] = JUri::base();
	 $uri = JURI::getInstance();
	 $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
	 $data['activate'] = $base.JRoute::_('index.php?option=com_users&task=registration.activate&token='.$data['activation'], false);
	 $emailSubject	= JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
	 if($usermessgae == 1) {
	   $emailBody = JText::sprintf('COM_SOCIALLOGIN_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY', $data['name'], $data['sitename'],	$data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation'], $data['siteurl'], $data['username'], $data['password_clear']);
	 }
	 else if ($usermessgae == 2) {
	   $emailBody = JText::sprintf('COM_SOCIALLOGIN_SEND_MSG', $data['name'], $data['sitename'], $data['siteurl'].'index.php', $data['username'],$data['password_clear']);
	 }
	 else if ($usermessgae == 3) {
	   $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY', $data['name'], $data['sitename'], $data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation'], $data['siteurl'], $data['username'], $data['password_clear']);
	 }
	 
	 // Send the registration email.
	 $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody);

	// Check for an error.
	if ($return !== true) {
	  $this->setError(JText::_('COM_USERS_REGISTRATION_SEND_MAIL_FAILED'));
	  // Send a system message to administrators receiving system mails
	  $db = JFactory::getDBO();
	  $q = "SELECT id FROM #__users WHERE block = 0 AND sendEmail = 1";
	  $db->setQuery($q);
	  $sendEmail = $db->loadColumn();
	  if (count($sendEmail) > 0) {
	    $jdate = new JDate();
	  
	    // Build the query to add the messages
	    $q = "INSERT INTO `#__messages` (`user_id_from`, `user_id_to`, `date_time`, `subject`, `message`)	VALUES ";
	    $messages = array();
	    foreach ($sendEmail as $userid) {
	    $messages[] = "(".$userid.", ".$userid.", '".$jdate->toSql()."', '".JText::_('COM_USERS_MAIL_SEND_FAILURE_SUBJECT')."', '".JText::sprintf('COM_USERS_MAIL_SEND_FAILURE_BODY', $return, $data['username'])."')";
	    }
	    $q .= implode(',', $messages);
	    $db->setQuery($q);
	    $db->execute();
	  }
	  return false;
    }
    elseif ($usermessgae == 2) {
      $db = JFactory::getDBO();
	
	  // get all admin users
      $query = 'SELECT name, email, sendEmail' . ' FROM #__users' . ' WHERE sendEmail=1';
	  $db->setQuery( $query );
	  $rows = $db->loadObjectList();
	  // Send mail to all superadministrators id
	  foreach ( $rows as $row ) {
	     JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, JText::sprintf('COM_SOCIALLOGIN_SEND_MSG_ADMIN', $row->name, $data['sitename'], $data['siteurl'], $data['email'], $data['username'], $data['password_clear']));
	    }
      }
	  return false;
    }