Esempio n. 1
0
 public function save($data)
 {
     $jinput = JFactory::getApplication()->input;
     $user_id = $jinput->get('id', 0, 'int');
     $user_data = $jinput->get('u', array(), 'array');
     $fields = $jinput->get('rsm_fields', array(), 'post');
     $ourtable = $this->getTable();
     RSMembership::createUserData((int) $user_id, $fields);
     $user = JFactory::getUser($user_id);
     $user->bind($user_data);
     $user->save();
     $this->_id = $user->get('id');
     return true;
 }
Esempio n. 2
0
File: user.php Progetto: JozefAB/qk
 function save()
 {
     $user = JFactory::getUser();
     $fields = JFactory::getApplication()->input->get('rsm_fields', array(), 'array');
     RSMembership::createUserData($user->get('id'), $fields);
 }
Esempio n. 3
0
 function _execute()
 {
     $mainframe =& JFactory::getApplication();
     $option = 'com_rsmembership';
     $task = JRequest::getVar('task', '');
     if ($task == 'subscribe') {
         $this->_bindId();
         $this->_bindExtras();
     } else {
         // get the already bound items
         if ($task == 'validatesubscribe') {
             $this->_bindData(false);
         }
         $this->_setId();
         $this->_setExtras();
         $this->_setData();
         if ($task == 'payment') {
             // empty session
             $this->_emptySession();
             $extras = $this->getExtras();
             $membership = $this->getMembership();
             $paymentplugin = JRequest::getCmd('payment', 'none');
             // calculate the total price
             $total = 0;
             $total += $membership->price;
             foreach ($extras as $extra) {
                 $total += $extra->price;
             }
             $user =& JFactory::getUser();
             if (!$user->get('guest')) {
                 $user_id = $user->get('id');
                 RSMembership::createUserData($user_id, @$this->_data->fields);
             } else {
                 if (RSMembershipHelper::getConfig('create_user_instantly')) {
                     $user_id = RSMembership::createUser($this->_data->email, $this->_data);
                 } else {
                     $user_id = 0;
                 }
             }
             $row =& JTable::getInstance('RSMembership_Transactions', 'Table');
             $row->user_id = $user_id;
             $row->user_email = $this->_data->email;
             $data = new stdClass();
             $data->name = $this->_data->name;
             $data->username = isset($this->_data->username) ? $this->_data->username : '';
             if (isset($this->_data->password)) {
                 $data->password = $this->_data->password;
             }
             $data->fields = $this->_data->fields;
             $row->user_data = serialize($data);
             $row->type = 'new';
             $params = array();
             $params[] = 'membership_id=' . $membership->id;
             if (is_array($this->_extras) && !empty($this->_extras)) {
                 $params[] = 'extras=' . implode(',', $this->_extras);
             }
             $row->params = implode(';', $params);
             // params, membership, extras etc
             $date = JFactory::getDate();
             $row->date = $date->toUnix();
             $row->ip = $_SERVER['REMOTE_ADDR'];
             $row->price = $total;
             $row->coupon = $this->getCoupon();
             $row->currency = RSMembershipHelper::getConfig('currency');
             $row->hash = '';
             $row->gateway = $paymentplugin == 'none' ? 'No Gateway' : RSMembership::getPlugin($paymentplugin);
             $row->status = 'pending';
             $this->_html = '';
             // trigger the payment plugin
             $paymentpluginClass = $paymentplugin;
             if (preg_match('#rsmembershipwire([0-9]+)#', $paymentplugin, $match)) {
                 $paymentpluginClass = 'rsmembershipwire';
             }
             $className = 'plgSystem' . $paymentpluginClass;
             $delay = false;
             if (class_exists($className)) {
                 $dispatcher =& JDispatcher::getInstance();
                 $plugin = new $className($dispatcher, array());
                 $args = array('plugin' => $paymentplugin, 'data' => &$this->_data, 'extras' => $extras, 'membership' => $membership, 'transaction' => &$row);
                 if (method_exists($plugin, 'onMembershipPayment')) {
                     $this->_html = call_user_func_array(array($plugin, 'onMembershipPayment'), $args);
                 }
                 if (method_exists($plugin, 'hasDelayTransactionStoring')) {
                     $delay = $plugin->hasDelayTransactionStoring();
                     if (method_exists($plugin, 'delayTransactionStoring')) {
                         $plugin->delayTransactionStoring($row->getProperties());
                     }
                 }
             }
             // plugin can delay the transaction storing
             if (!$delay) {
                 // store the transaction
                 $row->store();
                 // store the transaction id
                 $this->transaction_id = $row->id;
                 // finalize the transaction (send emails)
                 RSMembership::finalize($this->transaction_id);
                 // approve the transaction
                 if ($row->status == 'completed' || $row->price == 0 && $membership->activation != 0) {
                     RSMembership::approve($this->transaction_id, true);
                 }
                 if ($row->price == 0) {
                     $mainframe->redirect(JRoute::_('index.php?option=com_rsmembership&task=thankyou', false));
                 }
             }
         }
     }
 }
Esempio n. 4
0
 function save()
 {
     $user = JFactory::getUser();
     $fields = JRequest::getVar('rsm_fields', array(), 'post');
     RSMembership::createUserData($user->get('id'), $fields);
 }
Esempio n. 5
0
 public function saveTransaction($paymentPlugin)
 {
     // Empty the session, no point in keeping it.
     $this->clearData();
     // Empty the HTML variable.
     $this->html = '';
     // Get some data.
     $extras = $this->getExtras();
     $membership = $this->getMembership();
     $total = $this->getTotal();
     $user = JFactory::getUser();
     $app = JFactory::getApplication();
     // Asign the user.
     $userId = 0;
     if ($user->guest) {
         // Create the user instantly if this option is enabled.
         if (RSMembershipHelper::getConfig('create_user_instantly')) {
             $userId = RSMembership::createUser($this->data->email, $this->data);
         }
     } else {
         // Grab logged in user's ID.
         $userId = $user->id;
         // Update user's custom fields.
         RSMembership::createUserData($userId, $this->data->fields);
     }
     // Create user data object.
     $newData = (object) array('name' => $this->data->name, 'username' => isset($this->data->username) ? $this->data->username : '', 'fields' => $this->data->fields, 'membership_fields' => $this->data->membership_fields);
     if (!empty($this->data->password)) {
         $newData->password = $this->data->password;
     }
     // Create transaction params array.
     $params = array('membership_id=' . $membership->id);
     if ($this->extras) {
         $params[] = 'extras=' . implode(',', $this->extras);
     }
     $params = implode(';', $params);
     // Create the JTable object.
     $row = JTable::getInstance('Transaction', 'RSMembershipTable');
     $row->bind(array('user_id' => $userId, 'user_email' => $this->data->email, 'user_data' => serialize($newData), 'type' => 'new', 'params' => $params, 'date' => JFactory::getDate()->toSql(), 'ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '', 'price' => $total, 'coupon' => $this->data->coupon, 'currency' => RSMembershipHelper::getConfig('currency'), 'gateway' => $paymentPlugin == 'none' ? 'No Gateway' : RSMembership::getPlugin($paymentPlugin), 'status' => 'pending'));
     // Trigger the payment plugin
     $delay = false;
     $args = array('plugin' => $paymentPlugin, 'data' => &$this->data, 'extras' => $extras, 'membership' => $membership, 'transaction' => &$row, 'html' => &$this->html);
     $returns = $app->triggerEvent('onMembershipPayment', $args);
     // PHP 5.4 fix...
     if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
         foreach ($returns as $value) {
             if ($value) {
                 $this->html = $value;
             }
         }
     }
     $properties = $row->getProperties();
     $returns = $app->triggerEvent('delayTransactionStoring', array(array('plugin' => $paymentPlugin, 'properties' => &$properties, 'delay' => &$delay)));
     // PHP 5.4 fix...
     if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
         foreach ($returns as $value) {
             if ($value) {
                 $delay = true;
             }
         }
     }
     // Plugin can delay the transaction storing
     if (!$delay) {
         // Store the transaction
         $row->store();
         // Finalize the transaction (send emails)
         RSMembership::finalize($row->id);
         // Approve the transaction
         if ($row->status == 'completed' || !$this->showPaymentOptions() && $membership->activation != MEMBERSHIP_ACTIVATION_MANUAL || $membership->activation == MEMBERSHIP_ACTIVATION_INSTANT) {
             RSMembership::approve($row->id, true);
         }
     }
     return $row;
 }
Esempio n. 6
0
 public static function createUser($email, $data)
 {
     if (empty($email)) {
         return false;
     }
     $email = strtolower(trim($email));
     $lang = JFactory::getLanguage();
     $lang->load('com_user', JPATH_SITE, null, true);
     $lang->load('com_user', JPATH_ADMINISTRATOR, null, true);
     $lang->load('com_users', JPATH_ADMINISTRATOR, null, true);
     $lang->load('com_rsmembership', JPATH_SITE);
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     if ($user_id = RSMembership::checkUser($email)) {
         $user = JFactory::getUser($user_id);
         $password = JText::_('COM_RSMEMBERSHIP_HIDDEN_PASSWORD_TEXT');
         RSMembership::sendUserEmail($user, $password, $data->fields, false);
         return $user_id;
     }
     jimport('joomla.user.helper');
     // Get required system objects
     $user = clone JFactory::getUser(0);
     if (!RSMembershipHelper::getConfig('full_email_username')) {
         @(list($username, $domain) = explode('@', $email));
     } else {
         $username = $email;
     }
     if (RSMembershipHelper::getConfig('choose_username') && !empty($data->username)) {
         $username = $data->username;
     }
     $query->clear();
     $query->select($db->qn('id'))->from($db->qn('#__users'))->where($db->qn('username') . ' LIKE ' . $db->q($username));
     $db->setQuery($query, 0, 1);
     if (preg_match("#[<>\"'%;()&]#i", $username) || strlen(utf8_decode($username)) < 2) {
         $username = JFilterOutput::stringURLSafe($data->name);
         if (strlen($username) < 2) {
             $username = str_pad($username, 2, mt_rand(0, 9));
         }
     }
     while ($db->loadResult()) {
         $username .= mt_rand(0, 9);
         $query->clear();
         $query->select($db->qn('id'))->from($db->qn('#__users'))->where($db->qn('username') . ' LIKE ' . $db->q($username));
         $db->setQuery($query, 0, 1);
     }
     // Bind the post array to the user object
     $post = array();
     $post['name'] = $data->name;
     if (trim($post['name']) == '') {
         $post['name'] = $email;
     }
     $post['email'] = $email;
     $post['username'] = $username;
     $post['password'] = JUserHelper::genRandomPassword(8);
     $original = $post['password'];
     $post['password2'] = $post['password'];
     if (!$user->bind($post, 'usertype')) {
         JError::raiseError(500, $user->getError());
     }
     // Set some initial user values
     $user->set('id', 0);
     $usersConfig = JComponentHelper::getParams('com_users');
     $user->set('groups', array($usersConfig->get('new_usertype', 2)));
     $date = JFactory::getDate();
     $user->set('registerDate', $date->toSql());
     // If user activation is turned on, we need to set the activation information
     $useractivation = $usersConfig->get('useractivation');
     if ($useractivation == 1 || $useractivation == 2) {
         $user->set('activation', JApplication::getHash($post['password']));
         $user->set('block', '1');
     }
     $user->set('lastvisitDate', '0000-00-00 00:00:00');
     // If there was an error with registration, set the message
     if (!$user->save()) {
         return false;
         JError::raiseWarning('', JText::_($user->getError()));
     }
     // Send registration confirmation mail
     $password = $original;
     // Disallow control chars in the email
     $password = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $password);
     if (RSMembershipHelper::getConfig('choose_password') && !empty($data->password)) {
         $query->clear();
         $query->update($db->qn('#__users'))->set($db->qn('password') . ' = ' . $db->q($data->password))->where($db->qn('id') . ' = ' . $db->q($user->get('id')));
         $db->setQuery($query);
         $db->execute();
         $password = JText::_('COM_RSMEMBERSHIP_HIDDEN_PASSWORD_TEXT');
     }
     RSMembership::sendUserEmail($user, $password, $data->fields);
     RSMembership::createUserData($user->get('id'), $data->fields);
     return $user->get('id');
 }
Esempio n. 7
0
 function save()
 {
     $post = JRequest::get('post');
     $fields = JRequest::getVar('rsm_fields', array(), 'post');
     RSMembership::createUserData((int) $post['u']['id'], $fields);
     $user = JFactory::getUser($post['u']['id']);
     $user->bind($post['u']);
     $user->save();
     $this->_id = $user->get('id');
     return true;
 }
Esempio n. 8
0
 function createUser($email, $data)
 {
     if (empty($email)) {
         return false;
     }
     $email = strtolower($email);
     $lang =& JFactory::getLanguage();
     $lang->load('com_user', JPATH_SITE, null, true);
     $lang->load('com_user', JPATH_ADMINISTRATOR, null, true);
     $lang->load('com_users', JPATH_ADMINISTRATOR, null, true);
     $lang->load('com_rsmembership', JPATH_SITE);
     $db = JFactory::getDBO();
     $db->setQuery("SELECT `id` FROM #__users WHERE `email` LIKE '" . $db->getEscaped($email) . "' LIMIT 1");
     if ($user_id = $db->loadResult()) {
         $user =& JFactory::getUser($user_id);
         $password = JText::_('RSM_HIDDEN_PASSWORD_TEXT');
         RSMembership::sendUserEmail($user, $password, $data->fields, false);
         return $user_id;
     }
     jimport('joomla.user.helper');
     // Get required system objects
     $user = clone JFactory::getUser(0);
     @(list($username, $domain) = explode('@', $email));
     if (RSMembershipHelper::getConfig('choose_username') && !empty($data->username)) {
         $username = $data->username;
     }
     $db->setQuery("SELECT `id` FROM #__users WHERE `username` LIKE '" . $db->getEscaped($username) . "' LIMIT 1");
     if (preg_match("#[<>\"'%;()&]#i", $username) || strlen(utf8_decode($username)) < 2) {
         $username = JFilterOutput::stringURLSafe($data->name);
         if (strlen($username) < 2) {
             $username = str_pad($username, 2, mt_rand(0, 9));
         }
     }
     while ($db->loadResult()) {
         $username .= mt_rand(0, 9);
         $db->setQuery("SELECT `id` FROM #__users WHERE `username` LIKE '" . $db->getEscaped($username) . "' LIMIT 1");
     }
     // Bind the post array to the user object
     $post = array();
     $post['name'] = $data->name;
     if (trim($post['name']) == '') {
         $post['name'] = $email;
     }
     $post['email'] = $email;
     $post['username'] = $username;
     $post['password'] = JUserHelper::genRandomPassword(8);
     $original = $post['password'];
     $post['password2'] = $post['password'];
     if (!$user->bind($post, 'usertype')) {
         JError::raiseError(500, $user->getError());
     }
     // Set some initial user values
     $user->set('id', 0);
     if (RSMembershipHelper::isJ16()) {
         $usersConfig = JComponentHelper::getParams('com_users');
         $user->set('groups', array($usersConfig->get('new_usertype', 2)));
     } else {
         $authorize =& JFactory::getACL();
         // Initialize new usertype setting
         $usersConfig =& JComponentHelper::getParams('com_users');
         $newUsertype = $usersConfig->get('new_usertype');
         if (!$newUsertype) {
             $newUsertype = 'Registered';
         }
         $user->set('usertype', '');
         $user->set('gid', $authorize->get_group_id('', $newUsertype, 'ARO'));
     }
     $date =& JFactory::getDate();
     $user->set('registerDate', $date->toMySQL());
     // If user activation is turned on, we need to set the activation information
     $useractivation = $usersConfig->get('useractivation');
     if ($useractivation == '1') {
         $user->set('activation', JUtility::getHash($post['password']));
         $user->set('block', '1');
     }
     $user->set('lastvisitDate', '0000-00-00 00:00:00');
     // If there was an error with registration, set the message
     if (!$user->save()) {
         return false;
         JError::raiseWarning('', JText::_($user->getError()));
     }
     // Hack for community builder - approve the user so that he can login
     if (file_exists(JPATH_SITE . DS . 'components' . DS . 'com_comprofiler' . DS . 'comprofiler.php')) {
         $db->setQuery("INSERT INTO #__comprofiler SET approved = 1 , user_id = " . $user->get('id') . " , id = " . $user->get('id') . " , confirmed = 1");
         $db->query();
     }
     // Send registration confirmation mail
     $password = $original;
     // Disallow control chars in the email
     $password = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $password);
     if (RSMembershipHelper::getConfig('choose_password') && !empty($data->password)) {
         $db->setQuery("UPDATE #__users SET `password`='" . $db->getEscaped($data->password) . "' WHERE `id`='" . $user->get('id') . "'");
         $db->query();
         $password = JText::_('RSM_HIDDEN_PASSWORD_TEXT');
     }
     RSMembership::sendUserEmail($user, $password, $data->fields);
     RSMembership::createUserData($user->get('id'), $data->fields);
     return $user->get('id');
 }