/** * Returns yes/no * @param object * @param mixed Boolean * @return array */ function _sendMail(&$user, $details, $useractivation) { $mainframe = JFactory::getApplication(); $db = JFactory::getDBO(); $name = $user->get('name'); if (empty($name)) { $name = $user->get('email'); } $email = $user->get('email'); $username = $user->get('username'); $activation = $user->get('activation'); $password = $details['password2']; // using the original generated pword for the email $usersConfig = JComponentHelper::getParams('com_users'); // $useractivation = $usersConfig->get( 'useractivation' ); $sitename = $mainframe->getCfg('sitename'); $mailfrom = $mainframe->getCfg('mailfrom'); $fromname = $mainframe->getCfg('fromname'); $siteURL = JURI::base(); $subject = JText::sprintf('J2STORE_ACCOUNT_DETAILS', $name, $sitename); $subject = html_entity_decode($subject, ENT_QUOTES); if ($useractivation == 1) { $message = JText::sprintf('J2STORE_SEND_MSG_ACTIVATE', $name, $sitename, $siteURL . "index.php?option=com_user&task=activate&activation=" . $activation, $siteURL, $email, $password); } else { $message = JText::sprintf('J2STORE_SEND_MSG', $name, $sitename, $siteURL, $email, $password); } $message = html_entity_decode($message, ENT_QUOTES); // Send email to user if (!$mailfrom || !$fromname) { $fromname = $rows[0]->name; $mailfrom = $rows[0]->email; } $success = J2StoreHelperUser::_doMail($mailfrom, $fromname, $email, $subject, $message); return $success; }
function register_validate() { $app = JFactory::getApplication(); $user = JFactory::getUser(); $model = $this->getModel('checkout'); $redirect_url = JRoute::_('index.php?option=com_j2store&view=checkout'); $data = $app->input->getArray($_POST); $address_model = $this->getModel('address'); $store_address = J2StoreHelperCart::getStoreAddress(); require_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/user.php'; $userHelper = new J2StoreHelperUser(); $json = array(); // Validate if customer is already logged out. if ($user->id) { $json['redirect'] = $redirect_url; } // Validate cart has products and has stock. if (!J2StoreHelperCart::hasProducts()) { $json['redirect'] = $redirect_url; } if (!$json) { $selectableBase = J2StoreFactory::getSelectableBase(); $json = $selectableBase->validate($data, 'register', 'address'); //validate the password fields if (JString::strlen($app->input->post->get('password')) < 4) { $json['error']['password'] = JText::_('J2STORE_PASSWORD_REQUIRED'); } if ($app->input->post->get('confirm') != $app->input->post->get('password')) { $json['error']['confirm'] = JText::_('J2STORE_PASSWORDS_DOESTNOT_MATCH'); } //check email if ($userHelper->emailExists($app->input->post->getString('email'))) { $json['error']['email'] = JText::_('J2STORE_EMAIL_EXISTS'); } } if (!$json) { $post = $app->input->getArray($_POST); //now create the user // create the details array with new user info $details = array('email' => $app->input->getString('email'), 'name' => $app->input->getString('first_name') . ' ' . $app->input->getString('last_name'), 'username' => $app->input->getString('email'), 'password' => $app->input->getString('password'), 'password2' => $app->input->getString('confirm')); $msg = ''; $user = $userHelper->createNewUser($details, $msg); $this->session->set('account', 'register', 'j2store'); //now login the user if ($userHelper->login(array('username' => $user->username, 'password' => $details['password']))) { //$billing_address_id = $userHelper->addCustomer($post); $billing_address_id = $address_model->addAddress('billing'); //check if we have a country and zone id's. If not use the store address $country_id = $app->input->post->getInt('country_id', ''); if (empty($country_id)) { $country_id = $store_address->country_id; } $zone_id = $app->input->post->getInt('zone_id', ''); if (empty($zone_id)) { $zone_id = $store_address->zone_id; } $postcode = $app->input->post->getString('zip'); if (empty($postcode)) { $postcode = $store_address->store_zip; } $this->session->set('billing_address_id', $billing_address_id, 'j2store'); $this->session->set('billing_country_id', $country_id, 'j2store'); $this->session->set('billing_zone_id', $zone_id, 'j2store'); $shipping_address = $app->input->post->get('shipping_address'); if (!empty($shipping_address)) { $this->session->set('shipping_address_id', $billing_address_id, 'j2store'); $this->session->set('shipping_country_id', $country_id, 'j2store'); $this->session->set('shipping_zone_id', $zone_id, 'j2store'); $this->session->set('shipping_postcode', $postcode, 'j2store'); } } else { $json['redirect'] = $redirect_url; } $this->session->clear('guest', 'j2store'); $this->session->clear('shipping_method', 'j2store'); $this->session->clear('shipping_methods', 'j2store'); $this->session->clear('payment_method', 'j2store'); $this->session->clear('payment_methods', 'j2store'); } echo json_encode($json); $app->close(); }