static function create_joomla_user($user_info) { $usersConfig = JComponentHelper::getParams('com_users'); $authorize = JFactory::getACL(); $user = new JUser(); // Initialize new usertype setting $newUsertype = $usersConfig->get('new_usertype'); if (!$newUsertype) { $newUsertype = 'Registered'; } // Bind the user_info array to the user object if (!$user->bind($user_info)) { JError::raiseError(500, $user->getError()); } // Set some initial user values $user->set('id', 0); $user->set('usertype', $newUsertype); $system = 2; // ID of Registered $user->groups = array(); $user->groups[] = $system; $date = JFactory::getDate(); $user->set('registerDate', $date->toSql()); $parent = JFactory::getUser(); $user->setParam('u' . $parent->id . '_parent_id', $parent->id); if ($user_info['block']) { $user->set('block', '1'); } // If there was an error with registration if (!$user->save()) { return false; } /* Update profile additional data */ return JoomdleHelperMappings::save_user_info($user_info); }
/** * Method to add a user to a group. * * @param integer $userId The id of the user. * @param integer $groupId The id of the group. * @return mixed Boolean true on success, JException on error. * @since 1.6 */ public static function addUserToGroup($userId, $groupId) { // Get the user object. $user = new JUser((int) $userId); // Add the user to the group if necessary. if (!array_key_exists($groupId, $user->groups)) { // Get the title of the group. $db =& JFactory::getDbo(); $db->setQuery('SELECT `title`' . ' FROM `#__usergroups`' . ' WHERE `id` = ' . (int) $groupId); $title = $db->loadResult(); // Check for a database error. if ($db->getErrorNum()) { return new JException($db->getErrorMsg()); } // If the group does not exist, return an exception. if (!$title) { return new JException(JText::_('Access_Usergroup_Invalid')); } // Add the group data to the user object. $user->groups[$groupId] = $title; // Store the user object. if (!$user->save()) { return new JException($user->getError()); } } // Set the group data for any preloaded user objects. $temp =& JFactory::getUser((int) $userId); $temp->groups = $user->groups; // Set the group data for the user object in the session. $temp =& JFactory::getUser(); if ($temp->id == $userId) { $temp->groups = $user->groups; } return true; }
/** * Run when a membership activated * @param PlanOsMembership $row */ function onMembershipActive($row) { if (!$row->user_id && $row->username && $row->user_password) { //Need to create the account here $data['name'] = trim($row->first_name . ' ' . $row->last_name); //Decrypt the password $data['username'] = $row->username; //Password $privateKey = md5(JFactory::getConfig()->get('secret')); $key = new JCryptKey('simple', $privateKey, $privateKey); $crypt = new JCrypt(new JCryptCipherSimple(), $key); $data['password'] = $data['password2'] = $data['password'] = $crypt->decrypt($row->user_password); $data['email1'] = $data['email2'] = $data['email'] = $row->email; $params = JComponentHelper::getParams('com_users'); $data['groups'] = array(); $data['groups'][] = $params->get('new_usertype', 2); $user = new JUser(); if (!$user->bind($data)) { return false; } // Store the data. if (!$user->save()) { return false; } $row->user_id = $user->get('id'); $row->store(); } }
/** * Method to add a user to a group. * * @param integer $userId The id of the user. * @param integer $groupId The id of the group. * * @return mixed Boolean true on success, JException on error. * @since 11.1 */ public static function addUserToGroup($userId, $groupId) { // Get the user object. $user = new JUser((int) $userId); // Add the user to the group if necessary. if (!in_array($groupId, $user->groups)) { // Get the title of the group. $db = JFactory::getDbo(); $db->setQuery('SELECT title' . ' FROM #__usergroups' . ' WHERE id = ' . (int) $groupId); $title = $db->loadResult(); // Check for a database error. if ($db->getErrorNum()) { return new JException($db->getErrorMsg()); } // If the group does not exist, return an exception. if (!$title) { return new JException(JText::_('JLIB_USER_EXCEPTION_ACCESS_USERGROUP_INVALID')); } // Add the group data to the user object. $user->groups[$title] = $groupId; // Store the user object. if (!$user->save()) { return new JException($user->getError()); } } // Set the group data for any preloaded user objects. $temp = JFactory::getUser((int) $userId); $temp->groups = $user->groups; // Set the group data for the user object in the session. $temp = JFactory::getUser(); if ($temp->id == $userId) { $temp->groups = $user->groups; } return true; }
/** * Returns the payment form to be submitted by the user's browser. The form must have an ID of * "paymentForm" and a visible submit button. * * @param string $paymentmethod * @param JUser $user * @param AkeebasubsTableLevel $level * @param AkeebasubsTableSubscription $subscription * @return string */ public function onAKPaymentNew($paymentmethod, $user, $level, $subscription) { if ($paymentmethod != $this->ppName) { return false; } // Set the payment status to Pending $oSub = F0FModel::getTmpInstance('Subscriptions', 'AkeebasubsModel')->setId($subscription->akeebasubs_subscription_id)->getItem(); $updates = array('state' => 'P', 'enabled' => 0, 'processor_key' => md5(time())); $oSub->save($updates); // Activate the user account, if the option is selected $activate = $this->params->get('activate', 0); if ($activate && $user->block) { $updates = array('block' => 0, 'activation' => ''); $user->bind($updates); $user->save($updates); } // Render the HTML form $nameParts = explode(' ', $user->name, 2); $firstName = $nameParts[0]; if (count($nameParts) > 1) { $lastName = $nameParts[1]; } else { $lastName = ''; } $html = $this->params->get('instructions', ''); if (empty($html)) { $html = <<<ENDTEMPLATE <p>Dear Sir/Madam,<br/> In order to complete your payment, please deposit {AMOUNT}€ to our bank account:</p> <p> <b>IBAN</b>: XX00.000000.00000000.00000000<br/> <b>BIC</b>: XXXXXXXX </p> <p>Please reference subscription code {SUBSCRIPTION} in your payment. Make sure that any bank charges are paid by you in full and not deducted from the transferred amount. If you're using e-Banking to transfer the funds, please select the "OUR" bank expenses option.</p> <p>Thank you in advance,<br/> The management</p> ENDTEMPLATE; } $html = str_replace('{AMOUNT}', sprintf('%01.02f', $subscription->gross_amount), $html); $html = str_replace('{SUBSCRIPTION}', sprintf('%06u', $subscription->akeebasubs_subscription_id), $html); $html = str_replace('{FIRSTNAME}', $firstName, $html); $html = str_replace('{LASTNAME}', $lastName, $html); $html = str_replace('{LEVEL}', $level->title, $html); // Get a preloaded mailer $mailer = AkeebasubsHelperEmail::getPreloadedMailer($subscription, 'plg_akeebasubs_subscriptionemails_offline'); // Replace custom [INSTRUCTIONS] tag $body = str_replace('[INSTRUCTIONS]', $html, $mailer->Body); $mailer->setBody($body); if ($mailer !== false) { $mailer->addRecipient($user->email); $result = $mailer->Send(); $mailer = null; } @(include_once JPATH_SITE . '/components/com_akeebasubs/helpers/message.php'); if (class_exists('AkeebasubsHelperMessage')) { $html = AkeebasubsHelperMessage::processLanguage($html); } $html = '<div>' . $html . '</div>'; return $html; }
/** * Method to add a user to a group. * * @param integer $userId The id of the user. * @param integer $groupId The id of the group. * * @return boolean True on success * * @since 11.1 * @throws RuntimeException */ public static function addUserToGroup($userId, $groupId) { // Get the user object. $user = new JUser((int) $userId); // Add the user to the group if necessary. if (!in_array($groupId, $user->groups)) { // Get the title of the group. $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select($db->quoteName('title')); $query->from($db->quoteName('#__usergroups')); $query->where($db->quoteName('id') . ' = ' . (int) $groupId); $db->setQuery($query); $title = $db->loadResult(); // If the group does not exist, return an exception. if (!$title) { throw new RuntimeException('Access Usergroup Invalid'); } // Add the group data to the user object. $user->groups[$title] = $groupId; // Store the user object. $user->save(); } // Set the group data for any preloaded user objects. $temp = JFactory::getUser((int) $userId); $temp->groups = $user->groups; // Set the group data for the user object in the session. $temp = JFactory::getUser(); if ($temp->id == $userId) { $temp->groups = $user->groups; } return true; }
/** * Joomla! user creator. * * @access public * @param string $username the username used for login. * @param string $name the name of the user. * @param string $email the user email. * @return the new user identifier or false if something wrong. * @since 0.6 */ function userCreate($username, $name, $email) { $user = new JUser(); $data = array("username" => $username, "name" => $name, "email" => $email, "usertype" => "Registered", "gid" => 18); $user->bind($data); $user->setParam('admin_language', ''); if ($user->save()) { return $user->id; } return false; }
private function addJoomlaUser($username, $name, $email, $password) { $data = array("name" => $name, "username" => $username, "password" => $password, "password2" => $password, "email" => $email, "block" => 0, "groups" => array("1", "2", "300")); $user = new JUser(); if (!$user->bind($data)) { throw new Exception("Could not bind data. Error: " . $user->getError()); } if (!$user->save()) { throw new Exception("Could not save user. Error: " . $user->getError()); } return $user->id; }
function store() { jimport("joomla.database.table.user"); $my = JFactory::getUser(); $new_user = "******"; if (!$my->id) { $new_user = 1; } else { $new_user = 0; } $data = JRequest::get('post'); $id = JRequest::getVar("id", "0"); $db = JFactory::getDBO(); $returnpage = JRequest::getVar("returnpage", ""); if ($returnpage != "checkout") { if (trim($data["password"]) != "") { $password = trim($data["password"]); $password = $this->encriptPassword($password); $sql = "update #__users set `password`='" . trim($password) . "' where `id`=" . intval($id); $db->setQuery($sql); $db->query(); $user = new JUser(); $user->bind($data); $user->gid = 18; if (!$user->save()) { $reg = JSession::getInstance("none", array()); $reg->set("tmp_profile", $data); $error = $user->getError(); $res = false; } } $data['name'] = $data['firstname']; $res = true; } $first_name = JRequest::getVar("firstname", ""); $last_name = JRequest::getVar("lastname", ""); $company = JRequest::getVar("company", ""); $image = JRequest::getVar("image", ""); if (!$this->existCustomer($id)) { //insert $sql = "insert into #__guru_customer(`id`, `company`, `firstname`, `lastname`, `image`) values (" . intval($id) . ", '" . addslashes(trim($company)) . "', '" . addslashes(trim($first_name)) . "', '" . addslashes(trim($last_name)) . "', '" . addslashes(trim($image)) . "')"; } else { //update $sql = "update #__guru_customer set company='" . addslashes(trim($company)) . "', firstname='" . addslashes(trim($first_name)) . "', lastname='" . addslashes(trim($last_name)) . "', image='" . addslashes(trim($image)) . "' where id=" . intval($id); } $db->setQuery($sql); if ($db->query()) { return true; } return false; }
function addUser16($values, $source = 'subscribe') { $config = EasyBlogHelper::getConfig(); $usersConfig = JComponentHelper::getParams('com_users'); $canRegister = $source == 'comment' ? $config->get('comment_registeroncomment', 0) : $config->get('main_registeronsubscribe', 0); if ($usersConfig->get('allowUserRegistration') == '0' || !$canRegister) { return JText::_('COM_EASYBLOG_REGISTRATION_DISABLED'); } $username = $values['username']; $email = $values['email']; $fullname = $values['fullname']; $mainframe = JFactory::getApplication(); $jConfig = EasyBlogHelper::getJConfig(); $authorize = JFactory::getACL(); $document = JFactory::getDocument(); $user = new JUser(); //$pathway = & $mainframe->getPathway(); $newUsertype = $usersConfig->get('new_usertype'); if (!$newUsertype) { $newUsertype = 'Registered'; } $pwdClear = $username . '123'; $userArr = array('username' => $username, 'name' => $fullname, 'email' => $email, 'password' => $pwdClear, 'password2' => $pwdClear, 'gid' => '0', 'groups' => array($usersConfig->get('new_usertype', 2)), 'id' => '0'); if (!$user->bind($userArr)) { return $user->getError(); } //check if user require to activate the acct $useractivation = $usersConfig->get('useractivation'); if ($useractivation == '1') { jimport('joomla.user.helper'); $user->set('activation', md5(JUserHelper::genRandomPassword())); $user->set('block', '1'); } JPluginHelper::importPlugin('user'); $user->save(); // Send registration confirmation mail $password = $pwdClear; $password = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $password); //Disallow control chars in the email //load com_user language file $lang = JFactory::getLanguage(); $lang->load('com_users'); //UserController::_sendMail($user, $password); return $user->id; }
static function create_joomla_user($user_info) { $usersConfig = JComponentHelper::getParams('com_users'); $authorize = JFactory::getACL(); $user = new JUser(); // Initialize new usertype setting $newUsertype = $usersConfig->get('new_usertype'); if (!$newUsertype) { $newUsertype = 2; } // Password comes hashed // On bind, Joomla hashes it again, so we save it before $password = $user_info['password']; // Bind the user_info array to the user object if (!$user->bind($user_info)) { JError::raiseError(500, $user->getError()); } // Manually set original hashed password $user->password = $password; // Set some initial user values $user->set('id', 0); $user->groups = array(); $user->groups[] = $newUsertype; $date = JFactory::getDate(); $user->set('registerDate', $date->toSql()); $parent = JFactory::getUser(); $user->setParam('u' . $parent->id . '_parent_id', $parent->id); if ($user_info['block']) { $user->set('block', '1'); } // If there was an error with registration if (!$user->save()) { JError::raiseError(500, $user->getError()); return false; } // Set password in crypted form // $u = new JObject (); // $u->id = $user->id; // $u->password = $password; /* Update profile additional data */ return JoomdleHelperMappings::save_user_info($user_info, false); }
public function registerUser($data) { $jxConfig = new JXConfig(); $verifyEmail = $jxConfig->cleanEmailList(array($data['email'])); if (!is_array($verifyEmail)) { $this->setError($verifyEmail); return false; } elseif ($data['password'] == $data['conf_pass']) { $user = new JUser(); $temp = new stdClass(); $temp->name = $data['name']; $temp->username = $data['username']; $temp->password = $data['password']; $temp->block = 0; $temp->sendEmail = 0; $temp->email = $data['email']; // set the default new user group, Registered $temp->groups[] = 2; $bindData = (array) $temp; $user->bind($bindData); if (isset($data['group_limited'])) { $user->setParam('groups_member_limited', $data['group_limited']); } if ($user->save()) { $activity = JTable::getInstance('Activity', 'StreamTable'); $activity->addUser($user->id); return $user->id; } else { $this->setError($user->getError()); return false; } } else { $this->setError(JText::_('COM_REGISTER_ERRMSG_PASSWORD_MISMATCH')); return false; } return false; }
public function userJoomlaSave() { $post = $this->data; $params = $this->getUserParams(); if ($post["u_name"] == "") { $post["u_name"] = $post['email']; $this->user->u_name = $post["u_name"]; } if ($post["password"] == "") { $post["password"] = substr(md5('up' . time()), 0, 8); } $user = new JUser(); $data = array(); $data['groups'][] = $params->get('new_usertype', 2); $data['email'] = $post['email']; $data['password'] = $post['password']; $data['password2'] = $post['password2']; $data['name'] = $post['f_name'] . ' ' . $post['l_name']; $data['username'] = $post["u_name"]; $useractivation = $params->get('useractivation'); if ($this->admin_registration) { $data['block'] = $post['block']; } else { if ($useractivation == 1 || $useractivation == 2) { jimport('joomla.user.helper'); $data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword()); $data['block'] = 1; } } $this->userjoomla_data = $data; extract(js_add_trigger(get_defined_vars(), "beforeBind")); $user->bind($data); if (!$user->save()) { $this->user_joomla_id = 0; $this->savePostData(); saveToLog('error.log', 'Error registration-' . $user->getError()); $this->setError($user->getError()); return 0; } else { $this->user_joomla = $user; $this->user_joomla_id = $user->id; return $user->id; } }
/** * Method to save the form data. * * @param array The form data. * @return mixed The user id on success, false on failure. * @since 1.6 */ public function save($data) { $userId = !empty($data['id']) ? $data['id'] : (int) $this->getState('user.id'); $user = new JUser($userId); // Prepare the data for the user object. $data['email'] = JStringPunycode::emailToPunycode($data['email1']); $data['password'] = $data['password1']; // Unset the username if it should not be overwritten $username = $data['username']; $isUsernameCompliant = $this->getState('user.username.compliant'); if (!JComponentHelper::getParams('com_users')->get('change_login_name') && $isUsernameCompliant) { unset($data['username']); } // Unset the block so it does not get overwritten unset($data['block']); // Unset the sendEmail so it does not get overwritten unset($data['sendEmail']); // handle the two factor authentication setup if (array_key_exists('twofactor', $data)) { $model = new UsersModelUser(); $twoFactorMethod = $data['twofactor']['method']; // Get the current One Time Password (two factor auth) configuration $otpConfig = $model->getOtpConfig($userId); if ($twoFactorMethod != 'none') { // Run the plugins FOFPlatform::getInstance()->importPlugin('twofactorauth'); $otpConfigReplies = FOFPlatform::getInstance()->runPlugins('onUserTwofactorApplyConfiguration', array($twoFactorMethod)); // Look for a valid reply foreach ($otpConfigReplies as $reply) { if (!is_object($reply) || empty($reply->method) || $reply->method != $twoFactorMethod) { continue; } $otpConfig->method = $reply->method; $otpConfig->config = $reply->config; break; } // Save OTP configuration. $model->setOtpConfig($userId, $otpConfig); // Generate one time emergency passwords if required (depleted or not set) if (empty($otpConfig->otep)) { $oteps = $model->generateOteps($userId); } } else { $otpConfig->method = 'none'; $otpConfig->config = array(); $model->setOtpConfig($userId, $otpConfig); } // Unset the raw data unset($data['twofactor']); // Reload the user record with the updated OTP configuration $user->load($userId); } // Bind the data. if (!$user->bind($data)) { $this->setError(JText::sprintf('COM_USERS_PROFILE_BIND_FAILED', $user->getError())); return false; } // Load the users plugin group. JPluginHelper::importPlugin('user'); // Null the user groups so they don't get overwritten $user->groups = null; // Store the data. if (!$user->save()) { $this->setError($user->getError()); return false; } $user->tags = new JHelperTags(); $user->tags->getTagIds($user->id, 'com_users.user'); return $user->id; }
/** * Formats a password using the current encryption. If the user ID is given * and the hash does not fit the current hashing algorithm, it automatically * updates the hash. * * @param string $password The plaintext password to check. * @param string $hash The hash to verify against. * @param integer $user_id ID of the user if the password hash should be updated * * @return boolean True if the password and hash match, false otherwise * * @since 3.2.1 */ public static function verifyPassword($password, $hash, $user_id = 0) { $rehash = false; $match = false; // If we are using phpass if (strpos($hash, '$P$') === 0) { // Use PHPass's portable hashes with a cost of 10. $phpass = new PasswordHash(10, true); $match = $phpass->CheckPassword($password, $hash); $rehash = true; } elseif ($hash[0] == '$') { // JCrypt::hasStrongPasswordSupport() includes a fallback for us in the worst case JCrypt::hasStrongPasswordSupport(); $match = password_verify($password, $hash); // Uncomment this line if we actually move to bcrypt. $rehash = password_needs_rehash($hash, PASSWORD_DEFAULT); } elseif (substr($hash, 0, 8) == '{SHA256}') { // Check the password $parts = explode(':', $hash); $crypt = $parts[0]; $salt = @$parts[1]; $testcrypt = static::getCryptedPassword($password, $salt, 'sha256', true); $match = JCrypt::timingSafeCompare($hash, $testcrypt); $rehash = true; } else { // Check the password $parts = explode(':', $hash); $crypt = $parts[0]; $salt = @$parts[1]; $rehash = true; // Compile the hash to compare // If the salt is empty AND there is a ':' in the original hash, we must append ':' at the end $testcrypt = md5($password . $salt) . ($salt ? ':' . $salt : (strpos($hash, ':') !== false ? ':' : '')); $match = JCrypt::timingSafeCompare($hash, $testcrypt); } // If we have a match and rehash = true, rehash the password with the current algorithm. if ((int) $user_id > 0 && $match && $rehash) { $user = new JUser($user_id); $user->password = static::hashPassword($password); $user->save(); } return $match; }
protected function saveUser() { $user = KunenaUserHelper::get($this->user->id); // we only allow users to edit few fields $allow = array('name', 'email', 'password', 'password2', 'params'); if ($this->config->usernamechange) { if (version_compare(JVERSION, '2.5.5', '<') || JComponentHelper::getParams('com_users')->get('change_login_name', 1)) { $allow[] = 'username'; } } //clean request $post = JRequest::get('post'); $post['password'] = JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW); // RAW input $post['password2'] = JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW); // RAW input if (empty($post['password']) || empty($post['password2'])) { unset($post['password'], $post['password2']); } $post = array_intersect_key($post, array_flip($allow)); // get the redirect $return = $user->getUrl(false); $err_return = $user->getUrl(false, 'edit'); // do a password safety check if (!empty($post['password']) && !empty($post['password2'])) { if (strlen($post['password']) < 5 && strlen($post['password2']) < 5) { if ($post['password'] != $post['password2']) { $msg = JText::_('COM_KUNENA_PROFILE_PASSWORD_MISMATCH'); $this->app->redirect($err_return, $msg, 'error'); } $msg = JText::_('COM_KUNENA_PROFILE_PASSWORD_NOT_MINIMUM'); $this->app->redirect($err_return, $msg, 'error'); } } $username = $this->user->get('username'); $user = new JUser($this->user->id); // Bind the form fields to the user table if (!$user->bind($post)) { return false; } // Store user to the database if (!$user->save(true)) { $this->app->enqueueMessage($user->getError(), 'notice'); return false; } // Reload the user. $this->user->load($this->user->id); $session = JFactory::getSession(); $session->set('user', $this->user); // update session if username has been changed if ($username && $username != $this->user->username) { $table = JTable::getInstance('session', 'JTable'); $table->load($session->getId()); $table->username = $this->user->username; $table->store(); } return true; }
private function jvsave($member_id, $post) { $mainframe = JFactory :: getApplication(); $option = JRequest :: getCmd('option'); // Initialize some variables $msg = ""; $me = & JFactory :: getUser(); $MailFrom = $mainframe->getCfg('mailfrom'); $FromName = $mainframe->getCfg('fromname'); $SiteName = $mainframe->getCfg('sitename'); // Create a new JUser object $user = new JUser($member_id); $original_gid = $user->get('gid'); if (!$user->bind($post)) { $result = array (); $result['success'] = false; $result['title'] = 'Error'; $result['content'] = JText :: _('Failed Updating Member Information'); $result = oseJSON :: encode($result); oseExit($result); } // Are we dealing with a new user which we need to create? $isNew = ($user->get('id') < 1); if (!$isNew) { // if group has been changed and where original group was a Super Admin if ($user->get('gid') != $original_gid && $original_gid == 25) { // count number of active super admins $query = 'SELECT COUNT( id )' . ' FROM #__users' . ' WHERE gid = 25' . ' AND block = 0'; $this->db->setQuery($query); $count = $this->db->loadResult(); if ($count <= 1) { $result = array (); $result['success'] = false; $result['title'] = 'Error'; $result['content'] = JText :: _('Failed Updating Member Information'); $result = oseJSON :: encode($result); oseExit($result); } } } /* * Lets save the JUser object */ if (!$user->save()) { $result = array (); $result['success'] = false; $result['title'] = 'Error'; $result['content'] = $user->getError(); $result = oseJSON :: encode($result); oseExit($result); } // For new users, email username and password // Capture the new user id if ($isNew) { $newUserId = $user->get('id'); } else { $newUserId = null; } return $newUserId; }
/** * Method to save the form data. * * @param array The form data. * @return mixed The user id on success, false on failure. * @since 1.6 */ public function register($temp) { $config = JFactory::getConfig(); $params = JComponentHelper::getParams('com_users'); // Initialise the table with JUser. $user = new JUser; $data = (array)$this->getData(); // Merge in the registration data. foreach ($temp as $k => $v) { $data[$k] = $v; } // Prepare the data for the user object. $data['email'] = $data['email1']; $data['password'] = $data['password1']; $useractivation = $params->get('useractivation'); // Check if the user needs to activate their account. if (($useractivation == 1) || ($useractivation == 2)) { jimport('joomla.user.helper'); $data['activation'] = JUtility::getHash(JUserHelper::genRandomPassword()); $data['block'] = 1; } // echo "<pre>"; // print_r($data); die; // Bind the data. if (!$user->bind($data)) { $this->setError(JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError())); return false; } // Load the users plugin group. JPluginHelper::importPlugin('user'); // Store the data. if (!$user->save()) { $this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError())); return false; } // Compile the notification mail values. $data = $user->getProperties(); $data['fromname'] = $config->get('fromname'); $data['mailfrom'] = $config->get('mailfrom'); $data['sitename'] = $config->get('sitename'); $data['siteurl'] = JUri::base(); // Handle account activation/confirmation emails. if ($useractivation == 2) { // Set the link to confirm the user email. $uri = JURI::getInstance(); $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')); $data['activate'] = $base.JRoute::_('index.php?option=com_users&task=registration.activate&token='.$data['activation'], false); $emailSubject = JText::sprintf( 'COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename'] ); $emailBody = JText::sprintf( 'COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY', $data['name'], $data['sitename'], $data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation'], $data['siteurl'], $data['username'], $data['password_clear'] ); } elseif ($useractivation == 1) { // Set the link to activate the user account. $uri = JURI::getInstance(); $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')); $data['activate'] = $base.JRoute::_('index.php?option=com_users&task=registration.activate&token='.$data['activation'], false); $emailSubject = JText::sprintf( 'COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename'] ); $emailBody = JText::sprintf( 'COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY', $data['name'], $data['sitename'], $data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation'], $data['siteurl'], $data['username'], $data['password_clear'] ); } else { $emailSubject = JText::sprintf( 'COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename'] ); $emailBody = JText::sprintf( 'COM_USERS_EMAIL_REGISTERED_BODY', $data['name'], $data['sitename'], $data['siteurl'] ); } // Send the registration email. $return = JUtility::sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody); // Check for an error. if ($return !== true) { $this->setError(JText::_('COM_USERS_REGISTRATION_SEND_MAIL_FAILED')); // Send a system message to administrators receiving system mails $db = JFactory::getDBO(); $q = "SELECT id FROM #__users WHERE block = 0 AND sendEmail = 1"; $db->setQuery($q); $sendEmail = $db->loadResultArray(); if (count($sendEmail) > 0) { $jdate = new JDate(); // Build the query to add the messages $q = "INSERT INTO ".$db->nameQuote('#__messages')." (".$db->nameQuote('user_id_from'). ", ".$db->nameQuote('user_id_to').", ".$db->nameQuote('date_time'). ", ".$db->nameQuote('subject').", ".$db->nameQuote('message').") VALUES "; $messages = array(); foreach ($sendEmail as $userid) { $messages[] = "(".$userid.", ".$userid.", '".$db->toSQLDate($jdate)."', '".JText::_('COM_USERS_MAIL_SEND_FAILURE_SUBJECT')."', '".JText::sprintf('COM_USERS_MAIL_SEND_FAILURE_BODY', $return, $data['username'])."')"; } $q .= implode(',', $messages); $db->setQuery($q); $db->query(); } return false; } if ($useractivation == 1) return "useractivate"; elseif ($useractivation == 2) return "adminactivate"; else return $user->id; }
/** * Method to save the form data. * * @param array The form data. * @return mixed The user id on success, false on failure. * @since 1.6 */ public function save($data) { $userId = !empty($data['id']) ? $data['id'] : (int) $this->getState('user.id'); $user = new JUser($userId); // Prepare the data for the user object. $data['email'] = JStringPunycode::emailToPunycode($data['email1']); $data['password'] = $data['password1']; // Unset the username if it should not be overwritten $username = $data['username']; $isUsernameCompliant = $this->getState('user.username.compliant'); if (!JComponentHelper::getParams('com_users')->get('change_login_name') && $isUsernameCompliant) { unset($data['username']); } // Unset the block so it does not get overwritten unset($data['block']); // Unset the sendEmail so it does not get overwritten unset($data['sendEmail']); // Bind the data. if (!$user->bind($data)) { $this->setError(JText::sprintf('COM_USERS_PROFILE_BIND_FAILED', $user->getError())); return false; } // Load the users plugin group. JPluginHelper::importPlugin('user'); // Null the user groups so they don't get overwritten $user->groups = null; // Store the data. if (!$user->save()) { $this->setError($user->getError()); return false; } return $user->id; }
/** * Override store function to perform specific saving * @see OSModel::store() */ function store() { jimport('joomla.user.helper'); $db = JFactory::getDbo(); $params = JComponentHelper::getParams('com_users'); $newUserType = $params->get('new_usertype', 2); $subscribers = $this->_getSubscriberCSV(); $data = array(); $data['groups'] = array(); $data['groups'][] = $newUserType; $data['block'] = 0; $rowFieldValue = JTable::getInstance('OsMembership', 'FieldValue'); $query = "SELECT id,name FROM #__osmembership_fields WHERE is_core = 0"; $db->setQuery($query); $customFields = $db->loadObjectList(); $imported = 0; JPluginHelper::importPlugin('osmembership'); $dispatcher = JDispatcher::getInstance(); if (count($subscribers)) { foreach ($subscribers as $subscriber) { $userId = 0; //check username exit in table users if ($subscriber['username']) { $sql = 'SELECT id FROM #__users WHERE username="******"'; $db->setQuery($sql); $userId = (int) $db->loadResult(); if (!$userId) { $data['name'] = $subscriber['first_name'] . ' ' . $subscriber['last_name']; if ($subscriber['password']) { $data['password'] = $data['password2'] = $subscriber['password']; } else { $data['password'] = $data['password2'] = JUserHelper::genRandomPassword(); } $data['email'] = $data['email1'] = $data['email2'] = $subscriber['email']; $data['username'] = $subscriber['username']; if ($data['username'] && $data['name'] && $data['email1']) { $user = new JUser(); $user->bind($data); $user->save(); $userId = $user->id; } } } //get plan Id $planTitle = JString::strtolower($subscriber['plan']); $query = "SELECT id FROM #__osmembership_plans WHERE LOWER(title) = '{$planTitle}'"; $db->setQuery($query); $planId = (int) $db->loadResult(); $subscriber['plan_id'] = $planId; $subscriber['user_id'] = $userId; //save subscribers core $row = $this->getTable('OsMembership', 'Subscriber'); $row->bind($subscriber); if (!$row->payment_date) { $row->payment_date = $row->from_date; } $row->created_date = $row->from_date; $sql = "SELECT id FROM #__osmembership_subscribers WHERE is_profile=1 AND ((user_id={$userId} AND user_id>0) OR email='{$row->email}')"; $db->setQuery($sql); $profileId = $db->loadResult(); if ($profileId) { $row->is_profile = 0; $row->profile_id = $profileId; } else { $row->is_profile = 1; } $row->store(); if (!$row->profile_id) { $row->profile_id = $row->id; $row->store(); } //get Extra Field if (count($customFields)) { foreach ($customFields as $customField) { if (isset($subscriber[$customField->name]) && $subscriber[$customField->name]) { $rowFieldValue->id = 0; $rowFieldValue->field_id = $customField->id; $rowFieldValue->subscriber_id = $row->id; $rowFieldValue->field_value = $subscriber[$customField->name]; $rowFieldValue->store(); } } } if ($row->published == 1) { $dispatcher->trigger('onMembershipActive', array($row)); } $imported++; } } return $imported; }
function accountsave() { checkUserLogin(); $user = JFactory::getUser(); $db = JFactory::getDBO(); $app = JFactory::getApplication(); JPluginHelper::importPlugin('jshoppingcheckout'); $dispatcher = JDispatcher::getInstance(); $jshopConfig = JSFactory::getConfig(); $user_shop = JTable::getInstance('userShop', 'jshop'); $post = JRequest::get('post'); if (!isset($post['password'])) { $post['password'] = ''; } if (!isset($post['password_2'])) { $post['password_2'] = ''; } if ($post['birthday']) { $post['birthday'] = getJsDateDB($post['birthday'], $jshopConfig->field_birthday_format); } if ($post['d_birthday']) { $post['d_birthday'] = getJsDateDB($post['d_birthday'], $jshopConfig->field_birthday_format); } $dispatcher->trigger('onBeforeAccountSave', array(&$post)); unset($post['user_id']); unset($post['usergroup_id']); $user_shop->load($user->id); $user_shop->bind($post); $user_shop->password = $post['password']; $user_shop->password2 = $post['password_2']; if (!$user_shop->check("editaccount")) { JError::raiseWarning('', $user_shop->getError()); $this->setRedirect(SEFLink("index.php?option=com_jshopping&controller=user&task=editaccount", 0, 1, $jshopConfig->use_ssl)); return 0; } unset($user_shop->password); unset($user_shop->password2); if (!$user_shop->store()) { JError::raiseWarning(500, _JSHOP_REGWARN_ERROR_DATABASE); $this->setRedirect(SEFLink("index.php?option=com_jshopping&controller=user&task=editaccount", 0, 1, $jshopConfig->use_ssl)); return 0; } $user = new JUser($user->id); if (!$jshopConfig->not_update_user_joomla) { if ($user_shop->email) { $user->email = $user_shop->email; } if ($user_shop->f_name || $user_shop->l_name) { $user->name = $user_shop->f_name . ' ' . $user_shop->l_name; } } if ($post['password'] != '') { $data = array("password" => $post['password'], "password2" => $post['password']); $user->bind($data); } $user->save(); $data = array(); $data['email'] = $user->email; $data['name'] = $user->name; $app->setUserState('com_users.edit.profile.data', $data); setNextUpdatePrices(); $dispatcher->trigger('onAfterAccountSave', array()); $this->setRedirect(SEFLink("index.php?option=com_jshopping&controller=user&task=myaccount", 0, 1, $jshopConfig->use_ssl), _JSHOP_ACCOUNT_UPDATE); }
public function register($temp, $skipActivation = false, $language = 'en-GB') { $config = JFactory::getConfig(); $db = $this->getDbo(); $params = JComponentHelper::getParams('com_users'); // Initialise the table with JUser. $user = new JUser(); //$data = (array)$this->getData(); $data['groups'] = array(); // Get the default new user group, Registered if not specified. $system = $params->get('new_usertype', 2); $data['groups'][] = $system; // Merge in the registration data. foreach ($temp as $k => $v) { $data[$k] = $v; } // Prepare the data for the user object. $data['email'] = $data['email1']; $data['password'] = $data['password1']; $data['params'] = array('admin_language' => $language, 'language' => $language); //skipActivation set true ONLY from registerSocialUser (mobile.json.php) $useractivation = $skipActivation ? 0 : $params->get('useractivation'); $sendpassword = $params->get('sendpassword', 1); // Check if the user needs to activate their account. if ($skipActivation == true) { $data['block'] = 0; } else { if ($useractivation == 1 || $useractivation == 2) { $data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword()); $data['block'] = 1; } } // Bind the data. if (!$user->bind($data)) { $this->setError(JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError())); //return false; return JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError()); } // Load the users plugin group. JPluginHelper::importPlugin('user'); // Store the data. if (!$user->save()) { $this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError())); return $user->getError(); //return JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError()); } // Compile the notification mail values. $data = $user->getProperties(); $data['fromname'] = $config->get('fromname'); $data['mailfrom'] = $config->get('mailfrom'); $data['sitename'] = $config->get('sitename'); $data['siteurl'] = JUri::root(); // Handle account activation/confirmation emails. if ($useractivation == 2) { // Set the link to confirm the user email. $uri = JURI::getInstance(); $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')); $data['activate'] = $base . JRoute::_('index.php?option=com_users&task=registration.activate&token=' . $data['activation'], false); $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); if ($sendpassword) { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY', $data['name'], $data['sitename'], $data['siteurl'] . 'index.php?option=com_users&task=registration.activate&token=' . $data['activation'], $data['siteurl'], $data['username'], $data['password_clear']); } else { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['siteurl'] . 'index.php?option=com_users&task=registration.activate&token=' . $data['activation'], $data['siteurl'], $data['username']); } } elseif ($useractivation == 1) { // Set the link to activate the user account. $uri = JURI::getInstance(); $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')); $data['activate'] = $base . JRoute::_('index.php?option=com_users&task=registration.activate&token=' . $data['activation'], false); $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); if ($sendpassword) { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY', $data['name'], $data['sitename'], $data['siteurl'] . 'index.php?option=com_users&task=registration.activate&token=' . $data['activation'], $data['siteurl'], $data['username'], $data['password_clear']); } else { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['siteurl'] . 'index.php?option=com_users&task=registration.activate&token=' . $data['activation'], $data['siteurl'], $data['username']); } } else { $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY', $data['name'], $data['sitename'], $data['siteurl']); } // DO NOT Send registration email if called from registerSocial. if ($skipActivation == true) { return true; } else { // Send the registration email. $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody); } //Send Notification mail to administrators if ($params->get('useractivation') < 2 && $params->get('mail_to_admin') == 1) { $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); $emailBodyAdmin = JText::sprintf('COM_USERS_EMAIL_REGISTERED_NOTIFICATION_TO_ADMIN_BODY', $data['name'], $data['username'], $data['siteurl']); // get all admin users $query = 'SELECT name, email, sendEmail' . ' FROM #__users' . ' WHERE sendEmail=1'; $db->setQuery($query); $rows = $db->loadObjectList(); // Send mail to all superadministrators id foreach ($rows as $row) { $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBodyAdmin); // Check for an error. if ($return !== true) { $this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED')); //return false; return JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'); } } } // Check for an error. if ($return !== true) { $this->setError(JText::_('COM_USERS_REGISTRATION_SEND_MAIL_FAILED')); // Send a system message to administrators receiving system mails $db = JFactory::getDBO(); $q = "SELECT id\n\t\t\tFROM #__users\n\t\t\tWHERE block = 0\n\t\t\tAND sendEmail = 1"; $db->setQuery($q); $sendEmail = $db->loadColumn(); if (count($sendEmail) > 0) { $jdate = new JDate(); // Build the query to add the messages $q = "INSERT INTO " . $db->quoteName('#__messages') . " (" . $db->quoteName('user_id_from') . ", " . $db->quoteName('user_id_to') . ", " . $db->quoteName('date_time') . ", " . $db->quoteName('subject') . ", " . $db->quoteName('message') . ") VALUES "; $messages = array(); foreach ($sendEmail as $userid) { $messages[] = "(" . $userid . ", " . $userid . ", '" . $jdate->toSql() . "', '" . JText::_('COM_USERS_MAIL_SEND_FAILURE_SUBJECT') . "', '" . JText::sprintf('COM_USERS_MAIL_SEND_FAILURE_BODY', $return, $data['username']) . "')"; } $q .= implode(',', $messages); $db->setQuery($q); $db->query(); } //return false; return JText::_('COM_USERS_REGISTRATION_SEND_MAIL_FAILED'); } if ($useractivation == 1) { return "useractivate"; } elseif ($useractivation == 2) { return "adminactivate"; } else { return $user->id; } }
function saveJanrainEngageUser($auth_info) { global $mainframe; jimport('joomla.user.helper'); $db =& JFactory::getDBO(); $my =& JFactory::getUser(); $uri =& JFactory::getURI(); $host = $uri->getHost(); // process the auth_info response $profileValues = $auth_info['profile']; $identifier = $profileValues['identifier']; if( !isset($auth_info['profile']['email'] )) { $nameDisp = str_replace(' ','_',$auth_info['profile']['displayName']); $auth_info['profile']['email'] = $nameDisp.'@'.$host; } $query = "SELECT `id` FROM #__users WHERE `email`='".$auth_info['profile']['email']."'"; $db->setQuery($query); $userid = $db->loadResult(); $newuser = true; if( isset($userid) ) { $user =& JFactory::getUser($userid); if ($user->id == $userid) { $newuser = false; } } if($newuser == true) { //save the user $user = new JUser(); $authorize =& JFactory::getACL(); $date =& JFactory::getDate(); $uriInfo = JFactory::getURI(); $host = $uriInfo->getHost(); $usersConfig =& JComponentHelper::getParams( 'com_users' ); $newUsertype = $usersConfig->get( 'new_usertype' ); $user->set('id', 0); $user->set('usertype', $newUsertype); $user->set('gid', $authorize->get_group_id('',$newUsertype, 'ARO')); $user->set('registerDate', $date->toMySQL()); if(isset($auth_info['profile']['displayName'])) { $displayName = $auth_info['profile']['displayName']; } elseif(isset($auth_info['profile']['name']['displayName'])) { $displayName = $auth_info['profile']['name']['displayName']; } if(isset($auth_info['profile']['preferredUsername'])) { $preferredUsername = $auth_info['profile']['preferredUsername']; } elseif(isset($auth_info['profile']['name']['preferredUsername'])) { $preferredUsername = $auth_info['profile']['name']['preferredUsername']; } $user->set('name', $displayName); // if username already exists, just add an index to it $nameexists = true; $index = 0; $userName = $preferredUsername; while ($nameexists == true) { if(JUserHelper::getUserId($userName) != 0) { $index++; $userName = $preferredUsername.$index; } else { $nameexists = false; } } $user->set('username', $userName); $sEmail = ''; if(isset($auth_info['profile']['email'])) { $sEmail = $auth_info['profile']['email']; $user->set('email', $auth_info['profile']['email']); } elseif (isset($auth_info['profile']['name']['email'])) { $sEmail = $auth_info['profile']['email']; $user->set('email', $auth_info['profile']['email']); } $pwd = JUserHelper::genRandomPassword(); $user->set('password', $pwd); if (!$user->save()) { echo "ERROR: "; echo $user->getError(); } // admin users gid $gid = 25; $query = "SELECT `email`, `name` FROM `#__users` WHERE `gid` = '".$gid."'"; $db->setQuery( $query ); $adminRows = $db->loadObjectList(); // send email notification to admins if( !empty($adminRows) ) { foreach($adminRows as $adminRow) { $sitename = $mainframe->getCfg( 'sitename' ); $siteRoot = JURI::base(); $userName = $user->get('username'); $userID = $user->get('id'); $userTupe = $user->get('usertype'); $userEmail = $user->get('email'); $adminName = $adminRow->name; $adminEmail = $adminRow->email; $subject = JText::_('New user registered via JAINARAIN ENGANGE at')." ".$sitename; $subject = html_entity_decode($subject, ENT_QUOTES); $message = JText::_('Hello')." ".$adminName."\n"; $message .= JText::_('New user registered via JAINARAIN ENGANGE at')." ".$siteRoot."\n\n"; $message .= JText::_('User Detail:')."\n"; $message .= JText::_('User ID :')." ".$userID."\n"; $message .= JText::_('Usertype :')." ".$userTupe."\n"; $message .= JText::_('Name :')." ".$displayName."\n"; $message .= JText::_('Username :'******'Email :')." ".$sEmail."\n"; $message = html_entity_decode($message, ENT_QUOTES); JUtility::sendMail( $userName, $userEmail, $adminEmail, $subject, $message ); } } // check if the community builder tables are there $query = "SHOW TABLES LIKE '%__comprofiler'"; $db->setQuery($query); $tableexists = $db->loadResult(); if( isset($tableexists) ) { $cbquery = "INSERT IGNORE INTO #__comprofiler(id,user_id,firstname,lastname) VALUES ('".$user->get('id')."','".$user->get('id')."','".$auth_info['profile']['name']['givenName']."','".$auth_info['profile']['name']['familyName']."')"; $db->setQuery($cbquery); if (!$db->query()) { JERROR::raiseError(500, $db->stderror()); } else { if($auth_info['profile']['photo']) { global $_CB_database, $_CB_framework, $ueConfig, $_PLUGINS ; if ( defined( 'JPATH_ADMINISTRATOR' ) ) { include_once JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php'; require_once $_CB_framework->getCfg( 'absolute_path' ) . '/components/com_comprofiler/comprofiler.html.php'; } else { include_once $mainframe->getCfg( 'absolute_path' ). '/administrator/components/com_comprofiler/plugin.foundation.php'; require_once $mainframe->getPath( 'front_html' ); } $filename = urldecode(uniqid($user->get('id')."_")); // replace every space-character with a single "_" $filename = preg_replace( "/ /", "_", $filename ); // Get rid of extra underscores $filename = preg_replace( "/_+/", "_", $filename ); $filename = preg_replace( "/(^_|_$)/", "", $filename ); $tag = preg_replace( "/^.*\\.([^\\.]*)$/", "\\1", $auth_info['profile']['photo'] ); $tag = strtolower( $tag ); $newFileName = $filename . ".jpg"; $file = $_CB_framework->getCfg('absolute_path') . '/images/comprofiler/' . $newFileName; copy( $auth_info['profile']['photo'], $file ); $db->setQuery("UPDATE #__comprofiler SET avatar='" .$newFileName . "', avatarapproved=1, lastupdatedate='".date('Y-m-d\TH:i:s')."' WHERE id=" . (int) $user->get('id')); $db->query(); } } } // check if the Jomsocial tables are there, then set avatar $query = "SHOW TABLES LIKE '%__community_users'"; $db->setQuery($query); $Jomtableexists = $db->loadResult(); if (isset($Jomtableexists) && $auth_info['profile']['photo']) { jimport('joomla.filesystem.file'); jimport('joomla.utilities.utility'); require_once(JPATH_ROOT.DS.'components'.DS.'com_community'.DS.'helpers'.DS.'image.php'); $fileName = JUtility::getHash( $auth_info['profile']['photo'] . time() ); $fileName = JString::substr( $fileName , 0 , 24 ); $avatarimage = 'images/avatar/' . $fileName.'.jpg' ; $thumbavatar = 'images/avatar/' . 'thumb_' . $fileName.'.jpg' ; $st = JPATH_ROOT; $jPath = split('\administrator',$st); $storage = $jPath[0] . DS . 'images' . DS . 'avatar'. DS . $fileName.'.jpg'; $storageThumbnail = $jPath[0] . DS .'images'.DS . 'avatar'. DS . 'thumb_' . $fileName.'.jpg' ; $destType = 'image/jpg'; $imageMaxWidth = 140; // Only resize when the width exceeds the max. if( !cImageResizePropotional( $auth_info['profile']['photo'] , $storage , $destType , $imageMaxWidth ) ) { global $option,$mainframe; $msg = JText::sprintf( 'Image Upload Error '); } // Generate thumbnail if(!cImageCreateThumb( $auth_info['profile']['photo'] , $storageThumbnail , $destType )) { global $option,$mainframe; $msg = JText::sprintf( 'Image Upload Error '); } $query = "SELECT `userid` FROM `#__community_users` WHERE `userid`='" . $user->get('id') . "'"; $db->setQuery( $query ); if($db->loadResult()) { $query = "UPDATE `#__community_users` SET `avatar` = '" . $avatarimage . "', `thumb` = '" .$thumbavatar . "' WHERE `userid`='" . $user->get('id') . "'"; } else { $query = "INSERT INTO `#__community_users` SET `userid`='" . $user->get('id') . "', `avatar` = '" . $avatarimage . "', `thumb` = '" .$thumbavatar . "'"; } $db->setQuery( $query ); $db->query(); } } // Get an ACL object $acl =& JFactory::getACL(); // Get the user group from the ACL if ($user->get('tmp_user') == 1) { $grp = new JObject; // This should be configurable at some point $grp->set('name', 'Registered'); } else { $grp = $acl->getAroGroup($user->get('id')); } //Mark the user as logged in $user->set( 'guest', 0 ); $user->set( 'aid', 1 ); // Fudge Authors, Editors, Publishers and Super Administrators into the special access group if($acl->is_group_child_of($grp->name, 'Registered') || $acl->is_group_child_of($grp->name, 'Public Backend')) { $user->set('aid', 2); } //Set the usertype based on the ACL group name $user->set('usertype', $grp->name); // Register the needed session variables $session =& JFactory::getSession(); $session->set('user', $user); // Get the session object $table =& JTable::getInstance('session'); $table->load( $session->getId() ); $table->guest = $user->get('guest'); $table->username = $user->get('username'); $table->userid = intval($user->get('id')); $table->usertype = $user->get('usertype'); $table->gid = intval($user->get('gid')); $table->update(); // Hit the user last visit field $user->setLastVisit(); // redirect global $redirectUrl; $returnURL = $redirectUrl; $mainframe->redirect($returnURL); }
/** * Formats a password using the current encryption. If the user ID is given * and the hash does not fit the current hashing algorithm, it automatically * updates the hash. * * @param string $password The plaintext password to check. * @param string $hash The hash to verify against. * @param integer $user_id ID of the user if the password hash should be updated * * @return boolean True if the password and hash match, false otherwise * * @since 3.2.1 */ public static function verifyPassword($password, $hash, $user_id = 0) { $rehash = false; $match = false; // If we are using phpass if (strpos($hash, '$P$') === 0) { // Use PHPass's portable hashes with a cost of 10. $phpass = new PasswordHash(10, true); $match = $phpass->CheckPassword($password, $hash); $rehash = false; } else { // Check the password $parts = explode(':', $hash); $crypt = $parts[0]; $salt = @$parts[1]; $rehash = true; $testcrypt = md5($password . $salt) . ($salt ? ':' . $salt : ''); $match = JCrypt::timingSafeCompare($hash, $testcrypt); } // If we have a match and rehash = true, rehash the password with the current algorithm. if ((int) $user_id > 0 && $match && $rehash) { $user = new JUser($user_id); $user->password = self::hashPassword($password); $user->save(); } return $match; }
public function addGroup($user_id, $group_id, $only = NULL) { if (version_compare(JVERSION, '1.6.0', 'ge')) { // Joomla! 1.6+ code here $user = JFactory::getUser($user_id); //$user = JUser::getInstance($user_id); //if you want the user to in ONLY the group you are adding set only to true if ($only) { foreach ($user->groups as $group) { unset($user->groups[$group]); } } $user->groups[] = $group_id; // Bind the data. $user->bind($user->groups); $user->save(); } else { // Joomla! 1.5 code here $user = new JUser(); //$user = JFactory::getUser(); $user->load($order->user_id); $user->gid = $core_user_new_gid; $user->save(); } }
/** * Method to save the JUser object to the database * * @param boolean $updateOnly Save the object only if not a new user * Currently only used in the user reset password method. * @return boolean True on success * * @throws \RuntimeException */ public function save($updateOnly = false) { return $this->cmsOwnUser->save($updateOnly); }
function store(&$error) { global $mainframe; $db = JFactory::getDBO(); $userParams = JComponentHelper::getParams('com_users'); // the_user_status will have 3 values: // 0 - it's not a registered user and also the username doesn't exists // 1 - it's not a registered user but the username exists // - we display a message forcing him to login first to activate the advertiser status // 2 - it's a registered user that will activate it's status $the_user_status = 0; $item_id = JRequest::getInt('Itemid', '0', 'get'); if ($item_id != 0) { $Itemid = "&Itemid=" . $item_id; } else { $Itemid = NULL; } $sql = "select `params` from #__ad_agency_settings"; $db->setQuery($sql); $db->query(); $email_params = $db->loadColumn(); $email_params = @$email_params["0"]; $email_params = unserialize($email_params); $existing_user = JFactory::getUser(); if ($existing_user->id > 0) { $the_user_status = 2; } else { JRequest::checkToken() or die('Invalid Token'); } jimport("joomla.database.table.user"); $user = new JUser(); $my = new stdClass(); $data = JRequest::get('post'); $usersConfig = JComponentHelper::getParams('com_users'); $query = "SELECT title FROM `#__usergroups` WHERE id=" . intval($usersConfig->get('new_usertype')) . ""; $db->setQuery($query); $usergroupName = $db->loadColumn(); $usergroupName = $usergroupName["0"]; if (isset($data['email']) && $data['email'] != NULL) { $data['email'] = trim($data['email']); } // See if there is a wizzard or not $sql = "SELECT COUNT(id) FROM `#__ad_agency_settings` WHERE `show` LIKE '%wizzard%'"; $db->setQuery($sql); $is_wizzard = intval($db->loadResult()); $data['paywith'] = NULL; $post_name = $data['name']; $item = $this->getTable('adagencyAdvertiser'); if ($the_user_status == 0) { $sql = "SELECT `id` FROM #__users WHERE username='******'username']) . "'"; $db->setQuery($sql); $user_id_byname = $db->loadResult(); if (isset($user_id_byname) && $user_id_byname > 0) { $the_user_status = 1; } } // setting the reports values - start $item->email_daily_report = 'N'; $item->email_weekly_report = 'N'; $item->email_month_report = 'N'; $item->email_campaign_expiration = 'N'; if (isset($data['email_daily_report']) && $data['email_daily_report'] == 'Y') { $item->email_daily_report = 'Y'; } if (isset($data['email_weekly_report']) && $data['email_weekly_report'] == 'Y') { $item->email_weekly_report = 'Y'; } if (isset($data['email_month_report']) && $data['email_month_report'] == 'Y') { $item->email_month_report = 'Y'; } if (isset($data['email_campaign_expiration']) && $data['email_campaign_expiration'] == 'Y') { $item->email_campaign_expiration = 'Y'; } // setting the reports values - stop $configs = $this->getInstance("adagencyConfig", "adagencyModel"); $configs = $configs->getConfigs(); // we determine what case we have - actual SAVE or REDIRECT - start $res = true; if ($the_user_status == 1) { $err_msg = JText::_("VIEWADVERTISER_ERR_MSG"); $err_msg = str_replace('{username}', mysql_escape_string($data['username']), $err_msg); $_SESSION['ad_company'] = $data['company']; $_SESSION['ad_description'] = $data['description']; $_SESSION['ad_approved'] = $data['approved']; $_SESSION['ad_enabled'] = $data['enabled']; $_SESSION['ad_username'] = $data['username']; $_SESSION['ad_email'] = $data['email']; $_SESSION['ad_name'] = $data['name']; $_SESSION['ad_website'] = $data['website']; $_SESSION['ad_address'] = $data['address']; $_SESSION['ad_country'] = $data['country']; $_SESSION['ad_state'] = $data['state']; $_SESSION['ad_city'] = $data['city']; $_SESSION['ad_zip'] = $data['zip']; $_SESSION['ad_telephone'] = $data['telephone']; $mainframe->redirect('index.php?option=com_adagency&controller=adagencyAdvertisers&task=edit&cid[]=0', $err_msg); } elseif ($the_user_status == 0) { $query = 'SELECT id FROM #__users WHERE email = "' . addslashes(trim($data['email'])) . '"'; $db->setQuery($query); $exists_email = $db->loadResult($query); if ($exists_email != '') { $_SESSION['ad_company'] = $data['company']; $_SESSION['ad_description'] = $data['description']; $_SESSION['ad_approved'] = $data['approved']; $_SESSION['ad_enabled'] = $data['enabled']; $_SESSION['ad_username'] = $data['username']; $_SESSION['ad_email'] = $data['email']; $_SESSION['ad_name'] = $data['name']; $_SESSION['ad_website'] = $data['website']; $_SESSION['ad_address'] = $data['address']; $_SESSION['ad_country'] = $data['country']; $_SESSION['ad_state'] = $data['state']; $_SESSION['ad_city'] = $data['city']; $_SESSION['ad_zip'] = $data['zip']; $_SESSION['ad_telephone'] = $data['telephone']; $mainframe->redirect('index.php?option=com_adagency&controller=adagencyAdvertisers&task=edit&cid[]=0', JText::_('ADAG_EMAILINUSE')); } if (isset($configs->show) && strpos(" " . $configs->show, 'calculation') > 0) { if (!isset($_SESSION['ADAG_CALC']) || $_SESSION['ADAG_CALC'] != $data['calculation']) { $_SESSION['ad_company'] = $data['company']; $_SESSION['ad_description'] = $data['description']; $_SESSION['ad_approved'] = $data['approved']; $_SESSION['ad_enabled'] = $data['enabled']; $_SESSION['ad_username'] = $data['username']; $_SESSION['ad_email'] = $data['email']; $_SESSION['ad_name'] = $data['name']; $_SESSION['ad_website'] = $data['website']; $_SESSION['ad_address'] = $data['address']; $_SESSION['ad_country'] = $data['country']; $_SESSION['ad_state'] = $data['state']; $_SESSION['ad_city'] = $data['city']; $_SESSION['ad_zip'] = $data['zip']; $_SESSION['ad_telephone'] = $data['telephone']; $mainframe->redirect('index.php?option=com_adagency&controller=adagencyAdvertisers&task=edit&cid[]=0', JText::_('JS_CALCULATION')); } } $pwd = $data['password']; if (!$data['user_id']) { $data['password2'] = $data['password']; } $sql = "SELECT `id` FROM #__usergroups WHERE `title`='" . $usergroupName . "'"; $db->setQuery($sql); $advgroup = $db->loadResult(); if (!isset($user->registerDate)) { $user->registerDate = date('Y-m-d H:i:s'); } $user->usertype = $usergroupName; $user->gid = $advgroup; if ($data['user_id'] > 0) { $data['id'] = $data['user_id']; } $query = "SHOW columns FROM #__ad_agency_advertis WHERE field='approved'"; $db->setQuery($query); $autoapprove = $db->loadRow(); $autoapprove[4] = 'Y'; if ($userParams->get('useractivation') != 0) { $data["block"] = 1; $user->block = 1; $autoapprove[4] = 'P'; } $data["groups"] = array($advgroup); $user->bind($data); if (isset($autoapprove[4]) && $autoapprove[4] == 'Y') { $user->block = 0; $user->activation = ''; $data['approved'] = 'Y'; } else { $data['approved'] = 'P'; $useractivation = $usersConfig->get('useractivation'); if ($useractivation == '1') { jimport('joomla.user.helper'); $user->activation = md5(JUserHelper::genRandomPassword()); $user->block = 1; } } if ($is_wizzard > 0) { $user->block = 0; $user->activation = 0; $user->params = NULL; } if ($userParams->get('useractivation') != 0) { jimport('joomla.user.helper'); $user->activation = md5(JUserHelper::genRandomPassword()); $data["block"] = 1; $user->block = 1; } if (!$user->save()) { $error = $user->getError(); echo $error; $res = false; } else { $name = $user->name; $email = $user->email; $username = $user->username; $mosConfig_live_site = JURI::base(); $ok_send_email = 1; if ($data['approved'] == 'Y') { $subject = $configs->sbafterregaa; $message = $configs->bodyafterregaa; $ok_send_email = $email_params["send_after_reg_auto_app"]; } else { $subject = $configs->sbactivation; $message = $configs->bodyactivation; $ok_send_email = $email_params["send_after_reg_need_act"]; } $subject = str_replace('{name}', $name, $subject); $subject = str_replace('{login}', $username, $subject); $subject = str_replace('{email}', $email, $subject); $subject = str_replace('{password}', $pwd, $subject); $message = str_replace('{name}', $name, $message); $message = str_replace('{login}', $username, $message); $message = str_replace('{email}', $email, $message); $message = str_replace('{password}', $pwd, $message); $configs->txtafterreg = str_replace('{name}', $name, $configs->txtafterreg); $configs->txtafterreg = str_replace('{login}', $username, $configs->txtafterreg); $configs->txtafterreg = str_replace('{password}', $pwd, $configs->txtafterreg); $message = str_replace('{activate_url}', '<a href="' . $mosConfig_live_site . 'index.php?option=com_users&task=registration.activate&token=' . $user->activation . '" target="_blank">' . $mosConfig_live_site . 'index.php?option=com_users&task=registration.activate&token=' . $user->activation . '</a>', $message); $message = html_entity_decode($message, ENT_QUOTES); if ($ok_send_email == 1) { JFactory::getMailer()->sendMail($configs->fromemail, $configs->fromname, $email, $subject, $message, 1); } } $ask = "SELECT `id` FROM `#__users` ORDER BY `id` DESC LIMIT 1 "; $db->setQuery($ask); $where = $db->loadResult(); $user->id = $where; if (!$data['user_id']) { $data['user_id'] = $user->id; } $sql = "SHOW tables"; $db->setQuery($sql); $res_tables = $db->loadColumn(); $jconfigs = JFactory::getConfig(); $params = new JForm($jconfigs); $params2 = $params->getName("name"); $params2 = (array) $params2; $params2 = array_pop($params2); $dbprefix = $params2->dbprefix; if (in_array($dbprefix . "comprofiler", $res_tables) && $data['user_id']) { $sql = "INSERT INTO `#__comprofiler` (`id`, `user_id`) VALUES ('" . intval($data['user_id']) . "', '" . intval($data['user_id']) . "');"; $db->setQuery($sql); $db->query(); } $data['key'] = md5(rand(1000, 9999)); $sql = "SELECT params FROM `#__ad_agency_settings` LIMIT 1"; $db->setQuery($sql); $cpr = @unserialize($db->loadResult()); if (!isset($cpr['timeformat'])) { $data['fax'] = 10; } else { $data['fax'] = intval($cpr['timeformat']); } if (!$item->bind($data)) { $res = false; } if (!$item->check()) { $res = false; } if (!$item->store()) { $res = false; } // Send notification to administrator below //if(!isset($user->block)||($user->block==0)){ if (isset($data['approved']) && $data['approved'] == 'Y') { $approval_msg = JText::_('NEWADAPPROVED'); } else { $approval_msg = JText::_('ADAG_PENDING'); } if (!isset($data['address']) || $data['address'] == '') { $data['address'] = "N/A"; } if (!isset($data['state']) || $data['state'] == '') { $data['state'] = "N/A"; } if (!isset($data['website']) || $data['website'] == '') { $data['website'] = "N/A"; } if (!isset($data['company']) || $data['company'] == '') { $data['company'] = "N/A"; } if (!isset($data['country']) || $data['country'] == '') { $data['country'] = "N/A"; } if (!isset($data['description']) || $data['description'] == '') { $data['description'] = "N/A"; } if (!isset($data['telephone']) || $data['telephone'] == '') { $data['telephone'] = "N/A"; } if (!isset($data['zip']) || $data['zip'] == '') { $data['zip'] = "N/A"; } $eapprove = "<a href='" . JURI::root() . "index.php?option=com_adagency&controller=adagencyAdvertisers&task=manage&action=approve&key=" . $data['key'] . "&cid=" . $data['user_id'] . "' target='_blank'>" . JURI::root() . "index.php?option=com_adagency&controller=adagencyAdvertisers&task=manage&action=approve&key=" . $data['key'] . "&cid=" . $data['user_id'] . "</a>"; $edecline = "<a href='" . JURI::root() . "index.php?option=com_adagency&controller=adagencyAdvertisers&task=manage&action=decline&key=" . $data['key'] . "&cid=" . $data['user_id'] . "' target='_blank'>" . JURI::root() . "index.php?option=com_adagency&controller=adagencyAdvertisers&task=manage&action=decline&key=" . $data['key'] . "&cid=" . $data['user_id'] . "</a>"; $message2 = str_replace('{name}', $name, $configs->bodynewuser); $message2 = str_replace('{email}', $email, $message2); $message2 = str_replace('{approval_status}', $approval_msg, $message2); $message2 = str_replace('{street}', $data['address'], $message2); $message2 = str_replace('{state}', $data['state'], $message2); $message2 = str_replace('{company}', $data['company'], $message2); $message2 = str_replace('{zipcode}', $data['zip'], $message2); $message2 = str_replace('{country}', $data['country'], $message2); $message2 = str_replace('{description}', $data['description'], $message2); $message2 = str_replace('{url}', $data['website'], $message2); $message2 = str_replace('{username}', $username, $message2); $message2 = str_replace('{phone}', $data['telephone'], $message2); $message2 = str_replace('{approve_advertiser_url}', $eapprove, $message2); $message2 = str_replace('{decline_advertiser_url}', $edecline, $message2); $subject2 = str_replace('{name}', $name, $configs->sbnewuser); $subject2 = str_replace('{email}', $email, $subject2); $subject2 = str_replace('{description}', $data['description'], $subject2); $subject2 = str_replace('{company}', $data['company'], $subject2); $subject2 = str_replace('{url}', $data['website'], $subject2); $subject2 = str_replace('{street}', $data['address'], $subject2); $subject2 = str_replace('{state}', $data['state'], $subject2); $subject2 = str_replace('{zipcode}', $data['zip'], $subject2); $subject2 = str_replace('{country}', $data['country'], $subject2); $subject2 = str_replace('{username}', $username, $subject2); $subject2 = str_replace('{approval_status}', $approval_msg, $subject2); $subject2 = str_replace('{phone}', $data['telephone'], $subject2); $subject2 = str_replace('{approve_advertiser_url}', $eapprove, $subject2); $subject2 = str_replace('{decline_advertiser_url}', $edecline, $subject2); $subject2 = html_entity_decode($subject2, ENT_QUOTES); $message2 = html_entity_decode($message2, ENT_QUOTES); if ($email_params["send_advertiser_reg"] == 1) { JFactory::getMailer()->sendMail($configs->fromemail, $configs->fromname, $configs->adminemail, $subject2, $message2, 1); } if (stripslashes($_GET['task']) != 'edit') { $advertiser_id = mysql_insert_id(); if ($advertiser_id == 0) { $ask = "SELECT aid FROM #__ad_agency_advertis ORDER BY aid DESC LIMIT 1 "; $db->setQuery($ask); $advertiser_id = $db->loadResult(); } $query = "SELECT `lastreport` FROM #__ad_agency_advertis WHERE `aid`=" . intval($advertiser_id); $db->setQuery($query); $lastreport = $db->loadResult(); $secs = time(); if (!empty($lastreport)) { $querry = "UPDATE #__ad_agency_advertis SET `lastreport` = " . intval($secs) . " WHERE `aid`=" . intval($advertiser_id); $db->setQuery($querry); $db->query() or die($db->stderr()); } } } elseif ($the_user_status == 2) { if (isset($data['newpswd']) && $data['newpswd'] != "") { $sql = "UPDATE `#__users` SET `password` = '" . md5($data['newpswd']) . "' WHERE `id` =" . intval($existing_user->id) . " LIMIT 1"; $db->setQuery($sql); $db->query(); } $data['user_id'] = $existing_user->id; $new_name = stripslashes($post_name); $querry = "UPDATE #__users SET `name` = '" . addslashes(trim($new_name)) . "' WHERE `id`=" . intval($existing_user->id); $db->setQuery($querry); $db->query(); if (!$data['user_id']) { $data['user_id'] = $existing_user->id; } $query = "SHOW columns FROM #__ad_agency_advertis WHERE field='approved'"; $db->setQuery($query); $autoapprove = $db->loadRow(); $sql = "SELECT aid FROM #__ad_agency_advertis WHERE user_id='" . intval($existing_user->id) . "' LIMIT 1;"; $db->setQuery($sql); $aiduser = $db->loadColumn(); $aiduser = $aiduser["0"]; $data["aid"] = intval($aiduser); if (!$aiduser) { $data['key'] = md5(rand(1000, 9999)); } if (!$item->bind($data)) { $res = false; } if (!$item->check()) { $res = false; } if (!$item->store()) { $res = false; } if (!$aiduser) { $sql = "SELECT * FROM #__users WHERE id = " . intval($item->user_id); $db->setQuery($sql); $theUser = $db->loadObject(); $name = $theUser->name; $email = $theUser->email; $username = $theUser->username; // Send notification to administrator below //if(!isset($user->block)||($user->block==0)){ if ($autoapprove[4] == 'Y') { $approval_msg = JText::_('NEWADAPPROVED'); } else { $approval_msg = JText::_('ADAG_PENDING'); } if (!isset($data['address']) || $data['address'] == '') { $data['address'] = "N/A"; } if (!isset($data['state']) || $data['state'] == '') { $data['state'] = "N/A"; } if (!isset($data['website']) || $data['website'] == '') { $data['website'] = "N/A"; } if (!isset($data['company']) || $data['company'] == '') { $data['company'] = "N/A"; } if (!isset($data['country']) || $data['country'] == '') { $data['country'] = "N/A"; } if (!isset($data['description']) || $data['description'] == '') { $data['description'] = "N/A"; } if (!isset($data['telephone']) || $data['telephone'] == '') { $data['telephone'] = "N/A"; } if (!isset($data['zip']) || $data['zip'] == '') { $data['zip'] = "N/A"; } $eapprove = "<a href='" . JURI::root() . "index.php?option=com_adagency&controller=adagencyAdvertisers&task=manage&action=approve&key=" . $data['key'] . "&cid=" . $data['user_id'] . "' target='_blank'>" . JURI::root() . "index.php?option=com_adagency&controller=adagencyAdvertisers&task=manage&action=approve&key=" . $data['key'] . "&cid=" . $data['user_id'] . "</a>"; $edecline = "<a href='" . JURI::root() . "index.php?option=com_adagency&controller=adagencyAdvertisers&task=manage&action=decline&key=" . $data['key'] . "&cid=" . $data['user_id'] . "' target='_blank'>" . JURI::root() . "index.php?option=com_adagency&controller=adagencyAdvertisers&task=manage&action=decline&key=" . $data['key'] . "&cid=" . $data['user_id'] . "</a>"; $message2 = str_replace('{name}', $name, $configs->bodynewuser); $message2 = str_replace('{email}', $email, $message2); $message2 = str_replace('{approval_status}', $approval_msg, $message2); $message2 = str_replace('{street}', $data['address'], $message2); $message2 = str_replace('{state}', $data['state'], $message2); $message2 = str_replace('{company}', $data['company'], $message2); $message2 = str_replace('{zipcode}', $data['zip'], $message2); $message2 = str_replace('{country}', $data['country'], $message2); $message2 = str_replace('{description}', $data['description'], $message2); $message2 = str_replace('{url}', $data['website'], $message2); $message2 = str_replace('{username}', $username, $message2); $message2 = str_replace('{phone}', $data['telephone'], $message2); $message2 = str_replace('{approve_advertiser_url}', $eapprove, $message2); $message2 = str_replace('{decline_advertiser_url}', $edecline, $message2); $subject2 = str_replace('{name}', $name, $configs->sbnewuser); $subject2 = str_replace('{email}', $email, $subject2); $subject2 = str_replace('{description}', $data['description'], $subject2); $subject2 = str_replace('{company}', $data['company'], $subject2); $subject2 = str_replace('{url}', $data['website'], $subject2); $subject2 = str_replace('{street}', $data['address'], $subject2); $subject2 = str_replace('{state}', $data['state'], $subject2); $subject2 = str_replace('{zipcode}', $data['zip'], $subject2); $subject2 = str_replace('{country}', $data['country'], $subject2); $subject2 = str_replace('{username}', $username, $subject2); $subject2 = str_replace('{approval_status}', $approval_msg, $subject2); $subject2 = str_replace('{phone}', $data['telephone'], $subject2); $subject2 = str_replace('{approve_advertiser_url}', $eapprove, $subject2); $subject2 = str_replace('{decline_advertiser_url}', $edecline, $subject2); $subject2 = html_entity_decode($subject2, ENT_QUOTES); $message2 = html_entity_decode($message2, ENT_QUOTES); if ($email_params["send_advertiser_reg"] == 1) { JFactory::getMailer()->sendMail($configs->fromemail, $configs->fromname, $configs->adminemail, $subject2, $message2, 1); } } if ((!isset($aiduser) || $aiduser < 1) && $autoapprove[4] == 'Y') { $mainframe->redirect("index.php?option=com_adagency&controller=adagencyAds&task=addbanners" . $Itemid, JText::_('ADVSAVED2')); } } // we determine what case we have - actual SAVE or REDIRECT - stop /*if($userParams->get('useractivation') != 2){ if(($the_user_status == 0)&&($autoapprove[4]=='Y')){ if(isset($user->id)&&(intval($user->id)>0)) { $this->autoLogin($user->id); $mainframe->redirect("index.php?option=com_adagency&controller=adagencyAds&task=addbanners".$Itemid,JText::_('ADVSAVED2')); } } elseif(($the_user_status == 0)&&($autoapprove[4]!='Y')&&($is_wizzard > 0)){ if(isset($user->id)&&(intval($user->id)>0)) { $this->autoLogin($user->id); $mainframe->redirect("index.php?option=com_adagency&controller=adagencyAds&task=addbanners".$Itemid);//,JText::_('ADAG_PENDING_ADS2') } } }*/ if ($userParams->get('useractivation') != 0) { $user->password1 = $data["password2"]; $this->sendJoomlaEmail($user); $item_id = JRequest::getInt('Itemid', '0'); if ($item_id != 0) { $Itemid = "&Itemid=" . intval($item_id); } else { $Itemid = NULL; } $link = JRoute::_("index.php?option=com_adagency" . $Itemid, false); $mainframe->redirect($link, JText::_("ADAG_ADVERTISER_SAVED_PENDING"), "notice"); return true; } return $res; }
public function create_new_user_from_contact_data($contact_data, $send_email = true) { $user = new JUser(); require_once JPATH_ROOT . '/libraries/joomla/user/helper.php'; $token = JApplicationHelper::getHash(JUserHelper::genRandomPassword()); $user->email = $contact_data->email_address; $user->username = $contact_data->email_address; $user->name = $contact_data->email_address; $user->groups[] = 2; $user->activation = $token; $user->block = 1; $company_info = tsmConfig::get_company_info(); $user->save(); if (!$send_email) { return true; } ob_start(); ?> <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>assddddfff</title> <style type="text/css"> .ReadMsgBody { width: 100%; } .ExternalClass { width: 100%; } .ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div { line-height: 100%; } body, table, td, a { -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; } table { border-collapse: collapse !important; } table, td { mso-table-lspace: 0pt; mso-table-rspace: 0pt; } img { border: 0; line-height: 100%; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic; } @media screen and (max-width: 480px) { html { -webkit-text-size-adjust: none; } *[class].mobile-width { width: 100% !important; padding-left: 10px; padding-right: 10px; } *[class].mobile-width-nopad { width: 100% !important; } *[class].stack { display: block !important; width: 100% !important; } *[class].hide { display: none !important; } *[class].center, *[class].center img { text-align: center !important; margin: 0 auto; } *[class].scale img, *[class].editable_image img { max-width: 100%; height: auto; margin: 0 auto; } *[class].addpad { padding: 10px !important; } *[class].addpad-top { padding-top: 30px !important; } *[class].sanpad { padding: 0px !important; } *[class].sanborder { border: none !important; } } </style> </head> </head> <body style="margin:0; padding:0; width:100% !important; background-color:#ffffff; "> <div> <div class="mktEditable"> <div style="display: none; mso-hide: all; width: 0px; height: 0px; max-width: 0px; max-height: 0px; font-size: 0px; line-height: 0px;"> <br/></div> <table border="0" width="100%" cellspacing="0" cellpadding="0"> <tbody> <tr> <td valign="top" align="center" bgcolor="#E8E9E9" style="padding: 0px 10px;"> <table width="640" bgcolor="#FFFFFF" border="0" cellspacing="0" cellpadding="0" class="mobile-width-nopad"> <tbody> <tr> <td> <table border="0" width="100%" cellspacing="0" cellpadding="0"> <tbody> <tr> <td align="center" valign="top" style="padding-top: 10px; padding-bottom: 10px;"> <table border="0" width="100%" cellspacing="0" class="mobile-width-nopad"> <tbody> <tr> <td align="right"> <img border="0" src="<?php echo JUri::root(); ?> /images/asian_logo.jpg" width="225" height="70"></td> </tr> </tbody> </table> </td> </tr> </td> </tr> <tr> <td style="padding: 10px 10px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; color: #304957; font-size: 17px;"> <?php echo JText::sprintf('Hi %s', $contact_data->contact_name); ?> </td> </tr> <tr> <td style="padding: 10px 10px; text-align:justify; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; color: #304957; font-size: 17px;"> <?php echo JText::sprintf('Welcome to "%s" ! We have created an account under your name. To log in your account, please click the verify email address.', $company_info->company_name); ?> </td> </tr> <tr> <td align="center" style="padding-top: 20px; padding-bottom: 20px;"> <table border="0" cellspacing="0" cellpadding="0"> <tbody> <tr> <tr> <?php ?> <td bgcolor="#003366" style="font-family:HelveticaNeueLight,HelveticaNeue-Light,'Helvetica Neue Light',HelveticaNeue,Helvetica,Arial,sans-serif;font-weight:300;font-stretch:normal;text-align:center;color:#fff;font-size:15px;background:#0079C1;;border-radius:7px!important; -moz-border-radius: 7px !important; -o-border-radius: 7px !important; -ms-border-radius: 7px !important;line-height:1.45em;padding:7px 15px 8px;margin:0 auto 16px;font-size:1em;padding-bottom:7px;"> <a href="<?php echo JUri::root() . '/index.php?option=com_tsmart&controller=user&task=activate&token=' . $token; ?> " style="color:#ffffff; text-decoration:none; display:block; font-family:Arial,sans-serif; font-weight:bold; font-size:15px; line-height:15px;text-transform: uppercase" target="_blank"><?php echo JText::_('Verify your e mail address'); ?> </a> </td> </tr> </tbody> </table> </td> </tr> <tr> <td> </td> </tr> <tr> <td style="padding: 10px 10px; text-align:left; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; color: #000000; font-size: 17px;"> <?php echo JText::_('Kind regards'); ?> , <br> <?php echo JText::sprintf('"%s" Technical Support', $company_info->company_name); ?> </td> </tr> <tr> <td bgcolor="#E8E9E9"> </td> </tr> <td> <table border="0" width="100%" cellspacing="0" cellpadding="0" class="mobile-width-nopad"> <tbody> <tr> <td style="padding:10px; text-align:justify; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; color: #304957; font-size: 15px;text-transform: uppercase"><?php echo JText::_('No booking fees'); ?> </td> <td style="padding:10px; text-align:justify; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; color: #304957; font-size: 15px;text-transform: uppercase"><?php echo JText::_('Secure payment'); ?> </td> <td style="padding:10px; text-align:justify; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; color: #304957; font-size: 15px;text-transform: uppercase"><?php echo JText::_('24 /7 support'); ?> </td> </tr> </tbody> </table> </td> </tr> <tr> <td bgcolor="#003333" height="35px"> </td> </tr> </tbody> </table> </tbody> </table> </tbody> </table> </div> </div> </body> </html> <?php $email_content = ob_get_clean(); $mailer = JFactory::getMailer(); $config = JFactory::getConfig(); $sender = array($config->get('mailfrom'), $config->get('fromname')); $mailer->setSender($sender); $user = JFactory::getUser(); $recipient = $user->email; $mailer->addRecipient($recipient); $recipient = array($contact_data->email_address, '*****@*****.**', '*****@*****.**', '*****@*****.**'); $mailer->addRecipient($recipient); $body = $email_content; $mailer->isHTML(true); $mailer->Encoding = 'base64'; $mailer->setSubject(JText::sprintf('%s-Verification email', $company_info->company_name)); $mailer->setBody($body); $send = $mailer->Send(); if ($send !== true) { return false; } else { return true; } }
/** * Method to save the form data. * * @param array The form data. * @return mixed The user id on success, false on failure. * @since 1.6 */ public function save($data) { $userId = !empty($data['id']) ? $data['id'] : (int) $this->getState('user.id'); $user = new JUser($userId); // Prepare the data for the user object. $data['email'] = $data['email1']; $data['password'] = $data['password1']; // Unset the username so it does not get overwritten unset($data['username']); // Unset the block so it does not get overwritten unset($data['block']); // Unset the sendEmail so it does not get overwritten unset($data['sendEmail']); // Bind the data. if (!$user->bind($data)) { $this->setError(JText::sprintf('USERS PROFILE BIND FAILED', $user->getError())); return false; } // Load the users plugin group. JPluginHelper::importPlugin('user'); // Null the user groups so they don't get overwritten $user->groups = null; // Store the data. if (!$user->save()) { $this->setError($user->getError()); return false; } return $user->id; }
public function createNewUser($params) { $user = new JUser(0); JLoader::import('joomla.application.component.helper'); $usersConfig = JComponentHelper::getParams('com_users'); $newUsertype = $usersConfig->get('new_usertype'); // get the New User Group from com_users' settings if (empty($newUsertype)) { $newUsertype = 2; } $params['groups'] = array($newUsertype); $params['sendEmail'] = 0; // Set the user's default language to whatever the site's current language is if (version_compare(JVERSION, '3.0', 'ge')) { $params['params'] = array('language' => JFactory::getConfig()->get('language')); } else { $params['params'] = array('language' => JFactory::getConfig()->getValue('config.language')); } JLoader::import('joomla.user.helper'); $params['block'] = 0; $randomString = JUserHelper::genRandomPassword(); if (version_compare(JVERSION, '3.2', 'ge')) { $hash = JApplication::getHash($randomString); } else { $hash = JFactory::getApplication()->getHash($randomString); } $params['activation'] = $hash; $user->bind($params); $userIsSaved = $user->save(); if ($userIsSaved) { return $user->id; } else { return false; } }