Пример #1
0
 /**
  * Remove an user from ITPConnect users table
  * Method is called before user data is deleted from the database
  *
  * @param   array       holds the user data
  */
 public function onUserBeforeDelete($user)
 {
     $app = JFactory::getApplication();
     /* @var $app JApplication */
     if (!$app->isAdmin()) {
         return;
     }
     $userId = JArrayHelper::getValue($user, "id", null);
     try {
         if (!$userId) {
             throw new ItpException("Invalid user ID.", 500);
         }
         // Initialize some variables
         $db = JFactory::getDBO();
         $query = "\n                DELETE FROM\n                    `#__itpc_users` \n                WHERE\n                    `users_id`=" . (int) $userId . "\n                LIMIT\n                    1";
         $db->setQuery($query);
         $db->query();
         if ($db->getErrorNum() != 0) {
             throw new ItpException($db->getErrorMsg(), 500);
         }
     } catch (Exception $e) {
         $itpSecurity = new ItpSecurity($e);
         $itpSecurity->AlertMe();
         JError::raiseError(500, JText::_('ITP_ERROR_SYSTEM'));
         jexit();
     }
 }
Пример #2
0
 public function display()
 {
     $document =& JFactory::getDocument();
     /* @var $document JDocument */
     $viewType = $document->getType();
     // Get layout value
     $viewLayout = JRequest::getVar('layout', 'default');
     // Get view value
     $viewName = JRequest::getVar('view', 'Twitter');
     // Get view
     $view = $this->getView($viewName, $viewType, "View");
     // Get model
     $model = $this->getModel($viewName, "Model");
     if (!JError::isError($model)) {
         // Set model to view
         $view->setModel($model, true);
     }
     // Set layout into view
     $view->setLayout($viewLayout);
     try {
         // Display view
         $view->display();
     } catch (Exception $e) {
         $itpSecurity = new ItpSecurity($e);
         $itpSecurity->AlertMe();
         JError::raiseError(500, JText::_('ITP_ERROR_SYSTEM'));
         jexit(JText::_('ITP_ERROR_SYSTEM'));
     }
 }
Пример #3
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));
 }
Пример #4
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);
         }
     }
 }
Пример #5
0
 /**
  * Removes items
  *
  */
 public function delete()
 {
     $msg = "";
     // Check for request forgeries.
     JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $cids = JRequest::getVar('cid', array(), 'post', 'array');
     JArrayHelper::toInteger($cids);
     try {
         // Gets the model
         $model = $this->getModel('ItpcUsers', "ItpConnectModel");
         $model->delete($cids);
         $msg = JText::_('COM_ITPCONNECT_USERS_DELETED');
     } catch (ItpUserException $e) {
         $msg = "";
         JError::raiseWarning(500, $e->getMessage());
     } catch (Exception $e) {
         $itpSecurity = new ItpSecurity($e);
         $itpSecurity->AlertMe();
         JError::raiseError(500, JText::_('ITP_ERROR_SYSTEM'));
         jexit();
     }
     $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false), $msg);
 }