Esempio n. 1
0
 public function connect()
 {
     // Get return page
     $return = base64_decode(JRequest::getVar('return', '', 'GET', 'BASE64'));
     if (empty($return)) {
         $return = 'index.php?option=com_users&view=profile';
     }
     $facebook = ItpcHelper::getFB();
     $fbUserId = $facebook->getUser();
     $me = null;
     // Session based API call.
     if ($fbUserId) {
         try {
             $me = $facebook->api('/me');
         } catch (FacebookApiException $e) {
             $itpSecurity = new ItpSecurity($e);
             $itpSecurity->AlertMe();
             $me = null;
         }
     }
     if ($me) {
         try {
             // Get model
             $model = $this->getModel("Facebook", "ITPConnectModel");
             $data = $model->getItem($fbUserId);
             if (!$data) {
                 // Create new user or Connect existing user with the facebook profile
                 $userId = $model->store($fbUserId, $me);
                 $data = $model->getItem($fbUserId);
             }
             $user = JUser::getInstance($data->users_id);
             $credentials['username'] = $user->get("username");
             $credentials['password'] = $user->get("password");
             $options = array();
             $options['remember'] = JRequest::getBool('remember', true);
             $options['return'] = $return;
             $app =& JFactory::getApplication();
             /* @var $app JApplication */
             //preform the login action
             $error = $app->login($credentials, $options);
             if (JError::isError($error)) {
                 throw new ItpException($error->getMessages(), 500);
             }
         } catch (Exception $e) {
             $itpSecurity = new ItpSecurity($e);
             $itpSecurity->AlertMe();
             return $this->setRedirect(JRoute::_("index.php"));
         }
     }
     $this->setRedirect(JRoute::_($return));
 }
Esempio n. 2
0
 public function connect()
 {
     $facebook = ItpcHelper::getFB();
     $session = $facebook->getSession();
     $me = null;
     // Session based API call.
     if ($session) {
         try {
             $uid = $facebook->getUser();
             $me = $facebook->api('/me');
         } catch (FacebookApiException $e) {
             $itpSecurity = new ItpSecurity($e);
             $itpSecurity->AlertMe();
             $me = null;
         }
     }
     if ($me) {
         try {
             // Get model
             $model = $this->getModel("Facebook", "ITPConnectModel");
             $data = $model->getItem($uid);
             if (!$data) {
                 // Create new user or Connect existing user with the facebook.json profile
                 $userId = $model->store($uid, $me);
                 $data = $model->getItem($uid);
             }
             $user = JUser::getInstance($data->users_id);
             $credentials['username'] = $user->get("username");
             $credentials['password'] = $user->get("password");
             $options = array();
             $options['remember'] = JRequest::getBool('remember', true);
             $options['return'] = "";
             $app =& JFactory::getApplication();
             /* @var $app JApplication */
             //preform the login action
             $error = $app->login($credentials, $options);
             if (!JError::isError($error)) {
                 ItpResponse::sendJsonMsg("All is OK", 1);
             } else {
                 throw new ItpException($error->getMessages(), 500);
             }
         } catch (Exception $e) {
             $itpSecurity = new ItpSecurity($e);
             $itpSecurity->AlertMe();
             ItpResponse::sendJsonMsg("Error on login", 0);
         }
     }
 }
Esempio n. 3
0
 /**
  * Set the indicator for logout.
  * I will use the indicator for excetuting the a Facebook function 
  * that will destroy the session.
  *
  * @access public
  * @param array holds the user data
  * @return boolean True on success
  */
 public function onUserLogout($user)
 {
     $itpConnectParams = JComponentHelper::getParams('com_itpconnect');
     if (!$itpConnectParams->get("facebookOn", 0)) {
         return true;
     }
     if (!JComponentHelper::isEnabled('com_itpconnect', true)) {
         return true;
     }
     $app = JFactory::getApplication();
     /* @var $app JApplication */
     if ($app->isAdmin()) {
         return true;
     }
     $facebook = ItpcHelper::getFB();
     $facebook->destroySession();
     return true;
 }
Esempio n. 4
0
 /**
  * This method should handle any authentication and report back to the subject
  *
  * @access	public
  * @param	array	$credentials	Array holding the user credentials
  * @param	array	$options		Array of extra options
  * @param	object	$response		Authentication response object
  * @return	boolean
  * @since	1.5
  */
 public function onUserAuthenticate($credentials, $options, &$response)
 {
     $success = false;
     $itpConnectParams = JComponentHelper::getParams('com_itpconnect');
     if (!$itpConnectParams->get("facebookOn")) {
         return $success;
     }
     if (!JComponentHelper::isEnabled('com_itpconnect', true)) {
         return $success;
     }
     $app =& JFactory::getApplication();
     /* @var $app JApplication */
     if ($app->isAdmin()) {
         return $success;
     }
     $response->type = 'ItpConnect';
     $fbUserId = ItpcHelper::getFB()->getUser();
     if (!$fbUserId) {
         $response->status = JAUTHENTICATE_STATUS_FAILURE;
         $response->error_message = 'Could not authenticate';
     } else {
         $userId = ItpcHelper::getJUserId($fbUserId);
         $user = JUser::getInstance($userId);
         // Bring this in line with the rest of the system
         if (!$user) {
             $response->status = JAUTHENTICATE_STATUS_FAILURE;
             $response->error_message = 'Could not authenticate';
         } else {
             $response->email = $user->email;
             $response->fullname = $user->name;
             if (JFactory::getApplication()->isAdmin()) {
                 $response->language = $user->getParam('admin_language');
             } else {
                 $response->language = $user->getParam('language');
             }
             $response->status = JAUTHENTICATE_STATUS_SUCCESS;
             $response->error_message = '';
             $success = true;
         }
     }
     return $success;
 }
Esempio n. 5
0
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 */
// no direct access
defined('_JEXEC') or die('Restricted access');
if (!class_exists('ItpcHelper')) {
    // Register Component helpers
    JLoader::register("ItpcHelper", JPATH_ROOT . DS . "administrator" . DS . "components" . DS . "com_itpconnect" . DS . "helpers" . DS . "itpchelper.php");
}
$params->def('greeting', 1);
$type = ItpcHelper::getType();
$return = ItpcHelper::getReturnURL($params, $type);
$user = JFactory::getUser();
$itpConnectParams = JComponentHelper::getParams('com_itpconnect');
if ($itpConnectParams->get("facebookOn", 0)) {
    $facebook = ItpcHelper::getFB();
    // Get User ID
    $fbUserId = $facebook->getUser();
    $me = null;
    if ($fbUserId) {
        try {
            // Proceed knowing you have a logged in user who's authenticated.
            $me = $facebook->api('/me');
        } catch (FacebookApiException $e) {
            error_log($e);
            $user = null;
        }
    }
}
require JModuleHelper::getLayoutPath('mod_itpconnect', $params->get('layout', 'default'));