Esempio n. 1
0
 public function validateSubscribe()
 {
     $app = JFactory::getApplication();
     $model = $this->getModel('subscribe');
     // Get needed data.
     $membership_id = $app->input->get('cid', 0, 'int');
     $extras = $app->input->get('rsmembership_extra', array(), 'array');
     $coupon = $app->input->get('coupon', '', 'string');
     $data = array('username' => $app->input->get('username', '', 'string'), 'email' => $app->input->get('email', '', 'string'), 'name' => $app->input->get('name', '', 'string'), 'password' => $app->input->get('password', '', 'raw'), 'password2' => $app->input->get('password2', '', 'raw'), 'fields' => $app->input->get('rsm_fields', array(), 'array'), 'membership_fields' => $app->input->get('rsm_membership_fields', array(), 'array'));
     // Try to bind the membership
     if (!$model->bindMembership($membership_id)) {
         $app->enqueueMessage($model->getError(), 'error');
         return $app->redirect(JRoute::_('index.php?option=com_rsmembership', false));
     }
     // Try to bind extras
     if ($extras) {
         $model->bindExtras($extras);
     }
     // Check if the user can subscribe to this membership
     if ($data['email'] && ($userId = RSMembership::checkUser($data['email']))) {
         $user = JFactory::getUser($userId);
         if (!$model->canSubscribe($user)) {
             $app->enqueueMessage($model->getError(), 'error');
             return $app->redirect(JRoute::_('index.php?option=com_rsmembership', false));
         }
     }
     // Store data in the session here, we're going to need it later on.
     $model->storeData(array('id' => $membership_id, 'extras' => $extras, 'data' => $data, 'coupon' => $coupon));
     // Validate Captcha, bind data and check coupon code.
     if (!$model->validateCaptcha() || !$model->bindData($data) || !$model->bindCoupon($coupon)) {
         // Show some errors.
         $app->enqueueMessage(JText::_('COM_RSMEMBERSHIP_PLEASE_TYPE_FIELDS'), 'error');
         $app->enqueueMessage($model->getError(), 'error');
         // Redirect back.
         $app->redirect(JRoute::_('index.php?option=com_rsmembership&task=back&cid=' . $membership_id, false));
     }
     // Mark data as correct (to prevent people from accessing the next pages with invalid data).
     $model->markCorrectData($membership_id);
     // If one page checkout is enabled, just redirect to the payment gateway.
     if (RSMembershipHelper::getConfig('one_page_checkout')) {
         $app->input->set('payment', $app->input->get('payment', 'none', 'cmd'));
         return $this->paymentRedirect();
     } else {
         // Show the preview page.
         $view = $this->getView('subscribe', 'html');
         $view->setLayout('preview');
         $view->setModel($model, true);
         $view->display();
     }
 }
Esempio n. 2
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');
 }