function createUser($username) { $new_user = new JUser(); $this->db->setQuery("SELECT email, isAdm FROM #__user WHERE name = " . $this->db->Quote($username)); $r = $this->db->loadRow(); $email = $r[0]; $isAdm = $r[1]; jimport('joomla.application.component.helper'); $config =& JComponentHelper::getParams('com_users'); if ($isAdm) { $usertype = 'Super Administrator'; } else { $usertype = $config->get('new_usertype', 'Registered'); } $acl =& JFactory::getACL(); $new_user->set('id', 0); $new_user->set('name', $username); $new_user->set('username', $username); $new_user->set('email', $email); $new_user->set('gid', $acl->get_group_id('', $usertype)); $new_user->set('usertype', $usertype); $new_user->set('registeredDate', date('Y-m-d H:i:s')); $new_user->set('lastVisitDate', date('Y-m-d H:i:s')); $table =& $new_user->getTable(); $new_user->params = $new_user->_params->toString(); $table->bind($new_user->getProperties()); // $new_user->save(); if ($table->store()) { return $table->get('id'); } }
/** * Returns an associative array of Cms User properties that can be accessed with get(). * * @return array */ public function getProperties() { static $properties = null; if ($properties == null) { $properties = $this->cmsOwnUser->getProperties(); } return $properties; }
/** * * function register() * @param array() $temp */ public static function register($temp) { $config = JFactory::getConfig(); $db = JFactory::getDbo(); $params = JComponentHelper::getParams('com_users'); // Initialise the table with JUser. $user = new JUser(); // 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) { $data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword()); $data['block'] = 1; } $system = $params->get('new_usertype', 2); $data['groups'] = array($system); // Bind the data. if (!$user->bind($data)) { self::ajaxResponse('$error$' . JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError())); } // Load the users plugin group. JPluginHelper::importPlugin('user'); // Store the data. if (!$user->save()) { self::ajaxResponse('$error$' . 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'] = str_replace('modules/mod_bt_login/', '', JURI::root()); // Handle account activation/confirmation emails. if ($useractivation == 2) { // Set the link to confirm the user email. $data['activate'] = $data['siteurl'] . 'index.php?option=com_users&task=registration.activate&token=' . $data['activation']; $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']); } elseif ($useractivation == 1) { // Set the link to activate the user account. $data['activate'] = $data['siteurl'] . 'index.php?option=com_users&task=registration.activate&token=' . $data['activation']; $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 = 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_REGISTERED_BODY', $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) { JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBodyAdmin); // Check for an error. if ($return !== true) { //echo(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED')); } } } // Check for an error. if ($return !== true) { //echo (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\t\tFROM #__users\n\t\t\t\tWHERE block = 0\n\t\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(); } } 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 register($temp) { $config = JFactory::getConfig(); $db = $this->getDbo(); $params = JComponentHelper::getParams('com_cvnusers'); // 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'); $sendpassword = $params->get('sendpassword', 1); // Check if the user needs to activate their account. if ($useractivation == 1 || $useractivation == 2) { $data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword()); $data['block'] = 1; } //Set name from username (register require only username in chessvn) $data['name'] = $data['username']; // 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; } //Save additional data for player (user of chessvn) // Trong đây là add thêm các cột userid lấy từ bảng user, coin là tạo = 10000000; JLog::add(JText::_('khanglq:--- begin go here to Save additional data for player '), JLog::INFO); global $newUserCoin, $defaultAvatar, $chessTypeChess, $ratingTypeStandard, $initELO; // Phan tao folder va copy file $registerDate = JFactory::getDate(); $mediaplayer = '/mediaplayer/' . $registerDate->format('Y/Ym/Ymd/') . $user->id . '_' . $user->username; $path = JPATH_ROOT . '/media/media_chessvn' . $mediaplayer; if (JFolder::create($path)) { if (JFolder::create($path . '/images')) { //tạo thư mục images JLog::add(JText::_('khanglq111:--- Create folders sucess'), JLog::INFO); $src = JPATH_ROOT . '/media/media_chessvn' . $defaultAvatar; $dest = $path . $defaultAvatar; if (JFile::copy($src, $dest, null, true)) { // $defaultAvatar = '/images/no-avatar.jpg'; JLog::add(JText::_('khanglq1421111:--- Copy file ok'), JLog::INFO); } else { JLog::add(JText::_('khanglq1421111:--- Copy file failed'), JLog::INFO); } } } else { JLog::add(JText::_('khanglq1111421:--- Create folder failed'), JLog::INFO); } $query = $db->getQuery(true); $columns = array('userid', 'coin', 'avatar', 'mediaplayer'); $values = array($user->id, $newUserCoin, $db->quote($defaultAvatar), $db->quote($mediaplayer)); $query->insert($db->quoteName('#__player'))->columns($db->quoteName($columns))->values(implode(',', $values)); $db->setQuery($query); $db->execute(); // Save additional data for rating (user for chessvn) $playerId = $db->insertid(); $query = $db->getQuery(true); $columns = array('playerid', 'chesstype', 'ratingtype', 'ratingpoint'); $values = array($playerId, $chessTypeChess, $db->quote($ratingTypeStandard), $initELO); $query->insert($db->quoteName('#__rating'))->columns($db->quoteName($columns))->values(implode(',', $values)); $db->setQuery($query); $db->execute(); JLog::add(JText::_('khanglq1111:--- Additional data saved. $newUserCoin = ' . $newUserCoin), JLog::INFO); //================================================ // 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_cvnusers&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_cvnusers&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_cvnusers&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_cvnusers&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_cvnusers&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_cvnusers&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']); } // Send the registration email. // $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody); $return = true; //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); $return = true; //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; } } } // 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\t\tFROM #__users\n\t\t\t\tWHERE block = 0\n\t\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; } if ($useractivation == 1) { return "useractivate"; } elseif ($useractivation == 2) { return "adminactivate"; } else { return $user->id; } }
function ajaxregister() { $lang = JFactory::getLanguage(); $extension = 'com_users'; $base_dir = JPATH_SITE; $language_tag = $lang->getTag(); $reload = true; $lang->load($extension, $base_dir, $language_tag, $reload); $config = JFactory::getConfig(); $db = JFactory::getDbo(); $params = JComponentHelper::getParams('com_users'); $captchacode=strtolower(JRequest::getVar('captchacode')); $session_captchacode=$_SESSION['awdcpnumber']; if(strcmp($captchacode,$session_captchacode)!=0){ // set message in here : Registration is disable awdwallController::ajaxResponse('$errorcaptcha$'.JText::_('COM_COMAWDWALL_CAPTCHA_ERROR_TEXT')); } $requestData ['name']= JRequest::getVar('name'); $requestData ['username']= JRequest::getVar('username'); $requestData ['password1']= JRequest::getVar('passwd1'); $requestData ['password2']= JRequest::getVar('passwd2'); $requestData ['email1']= JRequest::getVar('email1'); $requestData ['email2']= JRequest::getVar('email2'); if(JComponentHelper::getParams('com_users')->get('allowUserRegistration') == 0){ // set message in here : Registration is disable awdwallController::ajaxResponse('$error$'.JText::_('COM_COMAWDWALL_REGISTRATION_NOTALLOWED_TEXT')); } // Initialise the table with JUser. $user = new JUser; // Merge in the registration data. foreach ($requestData 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)) { $data ['activation'] = JApplication::getHash ( JUserHelper::genRandomPassword () ); $data ['block'] = 1; } $system = $params->get('new_usertype', 2); $data['groups'] = array($system); // Bind the data. if (! $user->bind ( $data )) { awdwallController::ajaxResponse('$error$'.JText::sprintf ( 'COM_USERS_REGISTRATION_BIND_FAILED', $user->getError () )); } // Load the users plugin group. JPluginHelper::importPlugin('user'); // Store the data. if (!$user->save()) { awdwallController::ajaxResponse('$error$'.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. $data['activate'] = $data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation']; $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'] ); } elseif ($useractivation == 1) { // Set the link to activate the user account. $data['activate'] = $data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation']; $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 = 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_REGISTERED_BODY', $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) { echo(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED')); return false; } } } // Check for an error. if ($return !== true) { echo (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->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; } if ($useractivation == 1) $return = "useractivate"; elseif ($useractivation == 2) $return = "adminactivate"; else $return = $user->id; if ($return === 'adminactivate'){ awdwallController::ajaxResponse(JText::_('COM_USERS_REGISTRATION_COMPLETE_VERIFY')); } elseif ($return === 'useractivate') { awdwallController::ajaxResponse(JText::_('COM_USERS_REGISTRATION_COMPLETE_ACTIVATE')); } else { awdwallController::ajaxResponse(JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS')); } exit; }
/** * 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 * * @since 11.1 * @throws exception */ public function save($updateOnly = false) { // Create the user table object $table = $this->getTable(); $this->params = (string) $this->_params; $table->bind($this->getProperties()); // Allow an exception to be thrown. try { // Check and store the object. if (!$table->check()) { $this->setError($table->getError()); return false; } // If user is made a Super Admin group and user is NOT a Super Admin // // @todo ACL - this needs to be acl checked // $my = JFactory::getUser(); //are we creating a new user $isNew = empty($this->id); // If we aren't allowed to create new users return if ($isNew && $updateOnly) { return true; } // Get the old user $oldUser = new JUser($this->id); // // Access Checks // // The only mandatory check is that only Super Admins can operate on other Super Admin accounts. // To add additional business rules, use a user plugin and throw an Exception with onUserBeforeSave. // Check if I am a Super Admin $iAmSuperAdmin = $my->authorise('core.admin'); $iAmRehashingSuperadmin = false; if ($my->id == 0 && !$isNew && $this->id == $oldUser->id && $oldUser->authorise('core.admin') && $oldUser->password != $this->password) { $iAmRehashingSuperadmin = true; } // We are only worried about edits to this account if I am not a Super Admin. if ($iAmSuperAdmin != true && $iAmRehashingSuperadmin != true) { if ($isNew) { // Check if the new user is being put into a Super Admin group. foreach ($this->groups as $groupId) { if (JAccess::checkGroup($groupId, 'core.admin')) { throw new Exception(JText::_('JLIB_USER_ERROR_NOT_SUPERADMIN')); } } } else { // I am not a Super Admin, and this one is, so fail. if (JAccess::check($this->id, 'core.admin')) { throw new Exception(JText::_('JLIB_USER_ERROR_NOT_SUPERADMIN')); } if ($this->groups != null) { // I am not a Super Admin and I'm trying to make one. foreach ($this->groups as $groupId) { if (JAccess::checkGroup($groupId, 'core.admin')) { throw new Exception(JText::_('JLIB_USER_ERROR_NOT_SUPERADMIN')); } } } } } // Fire the onUserBeforeSave event. JPluginHelper::importPlugin('user'); $dispatcher = JDispatcher::getInstance(); $result = $dispatcher->trigger('onUserBeforeSave', array($oldUser->getProperties(), $isNew, $this->getProperties())); if (in_array(false, $result, true)) { // Plugin will have to raise its own error or throw an exception. return false; } // Store the user data in the database if (!($result = $table->store())) { throw new Exception($table->getError()); } // Set the id for the JUser object in case we created a new user. if (empty($this->id)) { $this->id = $table->get('id'); } if ($my->id == $table->id) { $registry = new JRegistry(); $registry->loadString($table->params); $my->setParameters($registry); } // Fire the onUserAfterSave event $dispatcher->trigger('onUserAfterSave', array($this->getProperties(), $isNew, $result, $this->getError())); } catch (Exception $e) { $this->setError($e->getMessage()); return false; } return $result; }
public static function juserRegister($juser) { $result = array(); $oseMscconfig = oseRegistry::call('msc')->getConfig('', 'obj'); $config = JFactory::getConfig(); $params = JComponentHelper::getParams('com_users'); $newUserType = self::getNewUserType($params->get('new_usertype')); $juser['gid'] = $newUserType; $data = (array) self::getJuserData($juser); // Initialise the table with JUser. $user = new JUser; foreach ($juser as $k => $v) { $data[$k] = $v; } // Prepare the data for the user object. $useractivation = $params->get('useractivation'); // Check if the user needs to activate their account. if (($useractivation == 1) || ($useractivation == 2)) { jimport('joomla.user.helper'); $data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword()); $data['block'] = 1; } // Bind the data. if (!$user->bind($data)) { $result['success'] = false; $result['title'] = 'Error'; $result['content'] = JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError()); } // Load the users plugin group. JPluginHelper::importPlugin('user'); if (!$user->save()) { $result['success'] = false; $result['title'] = 'Error'; $result['reload'] = ($oseMscconfig->error_registration == 'refresh') ? true : false; ; $result['content'] = JText::_($user->getError()); } else { // Mark the user_id in order to user in payment form if (($useractivation == 1) || ($useractivation == 2)) { $session = JFactory::getSession(); $oseUser = array(); $oseUser['user_id'] = $user->id; $oseUser['block'] = true; $oseUser['activation'] = true; $session->set('ose_user', $oseUser); } $result['success'] = true; $result['user'] = $user; $result['title'] = 'Done'; $result['content'] = 'Juser saved successfully'; // 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(); if (JOOMLA16 == true) { // 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_OSEMSC_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); $emailBody = JText::sprintf('COM_USERS_OSEMSC_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 if ($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_OSEMSC_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); $emailBody = JText::sprintf('COM_USERS_OSEMSC_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 = ""; $emailBody = ""; } // Send the registration email. if (!empty($emailSubject) && !empty($emailBody)) { if (JOOMLA30 == true) { $mailer = new JMail(); $return = $mailer->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody); } else { $return = JUtility::sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody); } } else { $return = true; } // 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 `#__messages` (`user_id_from`, `user_id_to`, `date_time`, `subject`, `message`) VALUES "; $messages = array(); foreach ($sendEmail as $userid) { $messages[] = "(" . $userid . ", " . $userid . ", '" . $jdate->toMySQL() . "', '" . 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) { $result['user_active'] = "useractivate"; } else if ($useractivation == 2) { $result['user_active'] = "adminactivate"; } else { $result['user_active'] = null; } } else { $mainframe = JFactory::getApplication('SITE'); if ($useractivation == 1) { $password = $data['password_clear']; $db = JFactory::getDBO(); $name = $user->get('name'); $email = $user->get('email'); $username = $user->get('username'); $usersConfig = &JComponentHelper::getParams('com_users'); $sitename = $mainframe->getCfg('sitename'); $useractivation = $usersConfig->get('useractivation'); $mailfrom = $mainframe->getCfg('mailfrom'); $fromname = $mainframe->getCfg('fromname'); $siteURL = JURI::base(); $subject = sprintf(JText::_('ACCOUNT_DETAILS_FOR'), $name, $sitename); $subject = html_entity_decode($subject, ENT_QUOTES); $message = sprintf(JText::_('SEND_MSG_ACTIVATE'), $name, $sitename, $siteURL . "index.php?option=com_user&task=activate&activation=" . $user->get('activation'), $siteURL, $username, $password); $message = html_entity_decode($message, ENT_QUOTES); //get all super administrator $query = 'SELECT name, email, sendEmail' . ' FROM #__users' . ' WHERE LOWER( usertype ) = "super administrator"'; $db->setQuery($query); $rows = $db->loadObjectList(); // Send email to user if (!$mailfrom || !$fromname) { $fromname = $rows[0]->name; $mailfrom = $rows[0]->email; } JUtility::sendMail($mailfrom, $fromname, $email, $subject, $message); // Send notification to all administrators $subject2 = sprintf(JText::_('ACCOUNT_DETAILS_FOR'), $name, $sitename); $subject2 = html_entity_decode($subject2, ENT_QUOTES); // get superadministrators id foreach ($rows as $row) { if ($row->sendEmail) { $message2 = sprintf(JText::_('SEND_MSG_ADMIN'), $row->name, $sitename, $name, $email, $username); $message2 = html_entity_decode($message2, ENT_QUOTES); JUtility::sendMail($mailfrom, $fromname, $row->email, $subject2, $message2); } } } else { $name = $user->get('name'); $email = $user->get('email'); $username = $user->get('username'); $usersConfig = &JComponentHelper::getParams('com_users'); $sitename = $mainframe->getCfg('sitename'); $useractivation = $usersConfig->get('useractivation'); $mailfrom = $mainframe->getCfg('mailfrom'); $fromname = $mainframe->getCfg('fromname'); $siteURL = JURI::base(); $message = sprintf(JText::_('SEND_MSG'), $name, $sitename, $siteURL); } } } return $result; }
/** * Takes the new password and saves it to the database. * It will only save the password if the user has the * correct user id and token stored in her session. * * @since 1.5 * @param string New Password * @param string New Password * @return bool True on success/false on failure */ function completeReset($password1, $password2) { jimport('joomla.user.helper'); $mainframe = JFactory::getApplication(); $option = JRequest::getCmd('option'); // Make sure that we have a pasword if (!$password1) { $this->setError(JText::_('MUST_SUPPLY_PASSWORD')); return false; } // Verify that the passwords match if ($password1 != $password2) { $this->setError(JText::_('PASSWORDS_DO_NOT_MATCH_LOW')); return false; } // Get the necessary variables $db = JFactory::getDBO(); $id = $mainframe->getUserState($this->_namespace . 'id'); $token = $mainframe->getUserState($this->_namespace . 'token'); $salt = JUserHelper::genRandomPassword(32); $crypt = JUserHelper::getCryptedPassword($password1, $salt); $password = $crypt . ':' . $salt; // Get the user object $user = new JUser($id); // Fire the onBeforeStoreUser trigger JPluginHelper::importPlugin('user'); $dispatcher =& JDispatcher::getInstance(); $dispatcher->trigger('onBeforeStoreUser', array($user->getProperties(), false)); // Build the query $query = 'UPDATE #__users' . ' SET password = '******' , activation = ""' . ' WHERE id = ' . (int) $id . ' AND activation = ' . $db->Quote($token) . ' AND block = 0'; $db->setQuery($query); // Save the password if (!($result = $db->query())) { $this->setError(JText::_('DATABASE_ERROR')); return false; } // Update the user object with the new values. $user->password = $password; $user->activation = ''; $user->password_clear = $password1; // Fire the onAfterStoreUser trigger $dispatcher->trigger('onAfterStoreUser', array($user->getProperties(), false, $result, $this->getError())); // Flush the variables from the session $mainframe->setUserState($this->_namespace . 'id', null); $mainframe->setUserState($this->_namespace . 'token', null); return true; }
public static function registerUser($profile) { $params = JComponentHelper::getParams('com_users'); // Initialise the table with JUser. $user = new JUser(); $data = array(); if (!$profile->email) { $profile->email = $profile->id + 200000 . '@sibdiet.net'; } // Prepare the data for the user object. $data['name'] = $profile->fname . ' ' . $profile->lname; $data['username'] = (string) ($profile->id + 200000); $data['email'] = JStringPunycode::emailToPunycode($profile->email); $data['password'] = $profile->mobile; $data['groups'][] = $params->get('new_usertype', 2); // Bind the data. if (!$user->bind($data)) { $user->setError(JText::sprintf('COM_SIBDIET_ERR_REGISTRATION_BIND_FAILED', $user->getError())); return false; } // Load the users plugin group. JPluginHelper::importPlugin('user'); // Store the data. if (!$user->save()) { $user->setError($user->getError()); return false; } $config = JFactory::getConfig(); // 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. $emailSubject = JText::sprintf('COM_SIBDIET_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); $emailBody = JText::sprintf('COM_SIBDIET_EMAIL_REGISTERED_BODY', $data['name'], $data['sitename'], $data['siteurl'], $data['username'], $data['password_clear']); // Send the registration email. $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody, true); // Check for an error. if ($return !== true) { $user->setError(JText::_('COM_SIBDIET_ERR_REGISTRATION_SEND_MAIL_FAILED')); } return $user->id; }
/** * Method to save the form data. * * @param array $temp The form data. * * @return mixed The user id on success, false on failure. * * @since 1.6 */ public function register($temp) { $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'] = JStringPunycode::emailToPunycode($data['email1']); $data['password'] = $data['password1']; $useractivation = $params->get('useractivation'); $sendpassword = $params->get('sendpassword', 1); // Check if the user needs to activate their account. if ($useractivation == 1 || $useractivation == 2) { $data['activation'] = JApplicationHelper::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; } // 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; } $config = JFactory::getConfig(); $db = $this->getDbo(); $query = $db->getQuery(true); // 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['activate'], $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['activate'], $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['activate'], $data['siteurl'],$data['username'], $data['password_clear'] ); */ $serverurl = $_SERVER['HTTP_HOST']; $body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width; maximum-scale=1.0;"> <title>RAS</title> <style type="text/css"> body{ margin:0px; padding:0px;} @media only screen and (max-width:598px){ table[class="mainWd"]{ width:100% !important; } .img{ width:100% !important; } } @media only screen and (max-width:599px){ table{ float:none !important; } table[class="mainWd"]{ width:100% !important; } table[class="table-width"]{ float:left !important} .img{ width:100% !important; } @media only screen and (max-width:480px){ td[class="wd660"]{ width:100% !important; float:left !important; text-align:center !important; } .img1{ display:none !important} td[class="wd360"]{ width:100% !important; float:left !important; text-align:center; margin-bottom:20px; } table[class="full_480"]{ width:220px !important; text-align:center !important; float:none !important; } td[class="mob_hide"]{ display:none !important; } } .img {width:100% !important; } .img {width:100% !important; } </style> </head> <body style="background:#cccccc;-moz-text-size-adjust:none; -webkit-text-size-adjust:none; -ms-text-size-adjust:none; "> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" > <tr><td align="center"> <table width="650" border="0" align="center" cellpadding="0" cellspacing="0" class="mainWd" > <tr><td height="25" align="center" valign="middle" style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#ffffff; background:#2a4c75">Can’t see this email? View it in your browser. </td></tr> <tr> <td align="left" valign="top" class="bg" bgcolor="#ffffff"> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td height="20" align="left" valign="top"> <img src="http://' . $serverurl . '/images/banner123.jpg" alt=" " class="img" border="0" align="left" style="display:block;width:100%"></td> </tr> <tr><td height="20" align="center" valign="top"> </td></tr> <tr><td align="center" valign="top"> <table width="96%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="left" valign="top"><p><span style="font-family:Arial, Helvetica, sans-serif; font-size:16px; line-height:20px; color:#343434; font-weight:normal;">Dear <span style="color:#f77635;text-transform:capitalize;">' . $data['name'] . ',</span><br /><br /> Welcome to RAS Restaurant Association of Singapore. Your registration process is successfully completed.<br /> </span><br /> <span style="font-family:Arial, Helvetica, sans-serif; font-size:16px; line-height:20px; color:#343434; font-weight:normal;">Here are your login details:</span></p> </td></tr> <tr><td height="5" align="center" valign="top"> </td></tr> <tr> <td align="left" valign="top" style="border:1px dashed #1e7fc0; padding:10px;"> <p style="font-family:Arial, Helvetica, sans-serif; font-size:16px; line-height:25px; color:#000000; font-weight:normal; ">Before you do anything else, please click the following button to verify your email: </p> <br><a href="' . $data['activate'] . '"><img src="http://' . $serverurl . '/images/verify.jpg" /> </a><br><br> <p style="font-family:Arial, Helvetica, sans-serif; font-size:16px; line-height:25px; color:#fd742f; font-weight:normal; "><span style="color:#000000;">Login: </span><a href="' . $data['siteurl'] . 'my-account">' . $data['siteurl'] . 'my-account</a><br /> <span style="color:#000000;">Username:</span> ' . $data['username'] . '<br /> <span style="color:#000000;">Password:</span> ' . $data['password_clear'] . '</p> </td></tr> <tr><td height="20" align="center" valign="top"> </td></tr> <tr> <td align="left" valign="top"><span style="color:#000000;">.</span><br /> <br /> <span style="font-family:Arial, Helvetica, sans-serif; font-size:26px; line-height:20px; color:#454545; font-weight:bold;">Get started now!<br /><br /> </span> <span style="font-family:Arial, Helvetica, sans-serif; font-size:16px; line-height:20px; color:#454545; font-weight:normal;">Best regards,<br /> Team RAS Restaurant Association of Singapore</span> </td></tr> <tr> <td height="20" align="center" valign="top"></td></tr> </table> </td> <tr> <td align="center" valign="middle" height="37 " bgcolor="#2a4c75" > <span style="font-family:Arial, Helvetica, sans-serif; font-size:12px ; color:#ffffff;-webkit-text-size-adjust: none;">Copyright © 2015. RAS All rights reserved </span></td> </tr> </table> </td> </tr> <tr> <td align="center"> </td> </tr> </table> </body> </html>'; $mailer = JFactory::getMailer(); $config = JFactory::getConfig(); $subject = 'Welcome to RAS Mentorship Forum '; $from = $config->get('mailfrom'); $fromname = $config->get('fromname'); $to = $data['email']; $sender = array($from, $fromname); $mailer->isHTML(true); $mailer->setSender($sender); $mailer->addRecipient($to); $mailer->Encoding = 'base64'; $mailer->setSubject($subject); $mailer->setBody($body); $return = $mailer->Send(); } else { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username']); } } else { $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); if ($sendpassword) { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY', $data['name'], $data['sitename'], $data['siteurl'], $data['username'], $data['password_clear']); } else { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY_NOPW', $data['name'], $data['sitename'], $data['siteurl']); } } // 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->clear()->select($db->quoteName(array('name', 'email', 'sendEmail')))->from($db->quoteName('#__users'))->where($db->quoteName('sendEmail') . ' = ' . 1); $db->setQuery($query); try { $rows = $db->loadObjectList(); } catch (RuntimeException $e) { $this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500); return false; } // 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; } } } // 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(); $query->clear()->select($db->quoteName(array('name', 'email', 'sendEmail', 'id')))->from($db->quoteName('#__users'))->where($db->quoteName('block') . ' = ' . (int) 0)->where($db->quoteName('sendEmail') . ' = ' . (int) 1); $db->setQuery($query); try { $sendEmail = $db->loadColumn(); } catch (RuntimeException $e) { $this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500); return false; } if (count($sendEmail) > 0) { $jdate = new JDate(); // Build the query to add the messages foreach ($sendEmail as $userid) { $values = array($db->quote($userid), $db->quote($userid), $db->quote($jdate->toSql()), $db->quote(JText::_('COM_USERS_MAIL_SEND_FAILURE_SUBJECT')), $db->quote(JText::sprintf('COM_USERS_MAIL_SEND_FAILURE_BODY', $return, $data['username']))); $query->clear()->insert($db->quoteName('#__messages'))->columns($db->quoteName(array('user_id_from', 'user_id_to', 'date_time', 'subject', 'message')))->values(implode(',', $values)); $db->setQuery($query); try { $db->execute(); } catch (RuntimeException $e) { $this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500); return false; } } } return false; } if ($useractivation == 1) { return "useractivate"; } elseif ($useractivation == 2) { return "adminactivate"; } else { return $user->id; } }
public static function juserRegister($juser) { $result = array(); $config = JFactory::getConfig(); $params = JComponentHelper::getParams('com_users'); $newUserType = self::getNewUserType($params->get('new_usertype')); $juser['gid'] = $newUserType; $data = (array) self::getJuserData($juser); // Initialise the table with JUser. $user = new JUser(); foreach ($juser 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; }*/ // 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'); if (!$user->save()) { $result['success'] = false; $result['title'] = 'Error'; $result['content'] = JText::_($user->getError()); $result = oseJson::encode($result); oseExit($result); } else { $result['success'] = true; $result['user'] = $user; $result['title'] = 'Done'; $result['content'] = 'Juser saved successfully'; // 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(); /*if (JOOMLA16==true) { // 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'] ); } else if ($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 = ""; $emailBody = ""; } // Send the registration email. if (!empty($emailSubject) && !empty($emailBody)) { $return = JUtility::sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody); } else { $return = true; } // 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 `#__messages` (`user_id_from`, `user_id_to`, `date_time`, `subject`, `message`) VALUES "; $messages = array(); foreach ($sendEmail as $userid) { $messages[] = "(".$userid.", ".$userid.", '".$jdate->toMySQL()."', '".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) { $result['user_active'] = "useractivate"; } else if ($useractivation == 2) { $result['user_active'] = "adminactivate"; } else { $result['user_active'] = null; } } else { if ($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_user&task=activate&activation='.$data['activation'], $data['siteurl'], $data['username'], $data['password_clear'] ); // Send the registration email. if (!empty($emailSubject) && !empty($emailBody)) { $return = JUtility::sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody); } else { $return = true; } } }*/ } return $result; }
function register($bypass_plugin, $bypass_verification_name, $verification_id, $user_id, $the_name_field, $the_username_field, $the_email_field, $the_password_field) { if ($the_name_field === null || $the_email_field === null || $the_password_field === null || $the_username_field === null) { return 0; } if ($user_id) { jimport('joomla.user.helper'); $db = JFactory::getDBO(); $pw = ''; if (!empty($the_password_field)) { $salt = JUserHelper::genRandomPassword(32); $crypt = JUserHelper::getCryptedPassword($the_password_field, $salt); $pw = $crypt . ':' . $salt; } $db->setQuery("Update #__users Set `name` = " . $db->Quote($the_name_field) . ", `username` = " . $db->Quote($the_username_field) . ", `email` = " . $db->Quote($the_email_field) . " " . (!empty($pw) ? ", `password` = '{$pw}'" : '') . " Where id = " . intval($user_id)); $db->query(); return $user_id; } // else execute the registration if ($this->is15) { return $this->register15($bypass_plugin, $bypass_verification_name, $verification_id, $the_name_field, $the_username_field, $the_email_field, $the_password_field); } jimport('joomla.version'); $version = new JVersion(); JFactory::getLanguage()->load('com_users', JPATH_SITE); $config = JFactory::getConfig(); $params = JComponentHelper::getParams('com_users'); // Initialise the table with JUser. $user = new JUser(); $data = array(); $data['activation'] = ''; $data['block'] = 0; // Prepare the data for the user object. $data['email'] = $the_email_field; $data['password'] = $the_password_field; $data['password_clear'] = $the_password_field; $data['name'] = $the_name_field; $data['username'] = $the_username_field; $data['groups'] = array($params->get('new_usertype')); $useractivation = $params->get('useractivation'); // Check if the user needs to activate their account. if ($useractivation == 1 || $useractivation == 2) { jimport('joomla.user.helper'); if (version_compare($version->getShortVersion(), '3.0', '<')) { $data['activation'] = JUtility::getHash(JUserHelper::genRandomPassword()); } else { $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; } // 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']); $siteurl = $data['siteurl'] . 'index.php?option=com_users&task=registration.activate&token=' . $data['activation']; if ($bypass_plugin) { $siteurl = $data['siteurl'] . 'index.php?option=com_contentbuilder&controller=verify&plugin=' . urlencode($bypass_plugin) . '&verification_name=' . urlencode($bypass_verification_name) . '&token=' . $data['activation'] . '&verification_id=' . $verification_id . '&format=raw'; } $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY', $data['name'], $data['sitename'], $siteurl, $data['siteurl'], $data['username'], $data['password_clear']); } else { if ($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']); $siteurl = $data['siteurl'] . 'index.php?option=com_users&task=registration.activate&token=' . $data['activation']; if ($bypass_plugin) { $siteurl = $data['siteurl'] . 'index.php?option=com_contentbuilder&controller=verify&plugin=' . urlencode($bypass_plugin) . '&verification_name=' . urlencode($bypass_verification_name) . '&token=' . $data['activation'] . '&verification_id=' . $verification_id . '&format=raw'; } $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY', $data['name'], $data['sitename'], $siteurl, $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. if (version_compare($version->getShortVersion(), '3.0', '<')) { $return = JUtility::sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody); } else { $return = JFactory::getMailer()->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\n FROM #__users\n WHERE block = 0\n AND sendEmail = 1"; $db->setQuery($q); jimport('joomla.version'); $version = new JVersion(); if (version_compare($version->getShortVersion(), '3.0', '>=')) { $sendEmail = $db->loadColumn(); } else { $sendEmail = $db->loadResultArray(); } if (count($sendEmail) > 0) { $jdate = new JDate(); // Build the query to add the messages $q = "INSERT INTO `#__messages` (`user_id_from`, `user_id_to`, `date_time`, `subject`, `message`)\n VALUES "; $messages = array(); jimport('joomla.version'); $version = new JVersion(); if (version_compare($version->getShortVersion(), '3.0', '>=')) { $___jdate = $jdate->toSql(); } else { $___jdate = $jdate->toMySQL(); } foreach ($sendEmail as $userid) { $messages[] = "(" . $userid . ", " . $userid . ", '" . $___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; } return $user->id; }
/** * Method to save the JUser object to the database * * @access public * @param boolean $updateOnly Save the object only if not a new user * @return boolean True on success * @since 1.5 */ function save($updateOnly = false) { // Create the user table object $table =& $this->getTable(); $this->params = $this->_params->toString(); $table->bind($this->getProperties()); // Check and store the object. if (!$table->check()) { $this->setError($table->getError()); return false; } //are we creating a new user $isnew = !$this->id; // If we aren't allowed to create new users return if ($isnew && $updateOnly) { return false; } // Get the old user $old = new JUser($this->id); // Fire the onBeforeStoreUser event. JPluginHelper::importPlugin('user'); $dispatcher =& JDispatcher::getInstance(); $dispatcher->trigger('onBeforeStoreUser', array($old->getProperties(), $isnew)); //Store the user data in the database if (!($result = $table->store())) { $this->setError($table->getError()); } // Set the id for the JUser object in case we created a new user. if (empty($this->id)) { $this->id = $table->get('id'); } //Fire the onAftereStoreUser event $dispatcher->trigger('onAfterStoreUser', array($this->getProperties(), $isnew, $result, $this->getError())); return $result; }
/** * 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(); $db = $this->getDbo(); $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'); $sendpassword = $params->get('sendpassword', 1); // Check if the user needs to activate their account. // 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; } // 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::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']); } 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']); } 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']); } // Send the registration email. //$emailBody = Ideary::emailBody($data['name'],$data['sitename'],$data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation'],$data['siteurl']); $emailBody = Ideary::emailBodyTable($data['name'], $data['sitename'], $data['siteurl'] . 'index.php?option=com_users&task=registration.activate&token=' . $data['activation'], $data['siteurl']); //$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody); /*Rodrigo cambio esto para que funcione*/ $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; //$headers .= 'To: '.$data['email'].' <'.$data['email'].'>' . "\r\n"; $headers .= 'From: ' . $data['fromname'] . ' <' . $data['mailfrom'] . '>' . "\r\n"; $return = mail($data['email'], $emailSubject, $emailBody, $headers); // $return2 = mail("*****@*****.**", $emailSubject, $emailBody,$headers); //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; } } } // 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\t\tFROM #__users\n\t\t\t\tWHERE block = 0\n\t\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; } if ($useractivation == 1) { return "useractivate"; } elseif ($useractivation == 2) { return "adminactivate"; } else { return $user->id; } }
/** * Method to save the form data. * * @access public * @param array $data The form data. * @return mixed The user id on success, false on failure. * @since 1.0 */ function register($temp) { $config =& JFactory::getConfig(); $params =& JComponentHelper::getParams('com_users'); // Initialise the table with JUser. JUser::getTable('User', 'JTable'); $user = new JUser(); $data = (array) $this->getData(); // Merge in the registration data. foreach ($data as $k => $v) { $temp[$k] = $v; } $data = $temp; // Prepare the data for the user object. $data['email'] = $data['email1']; $data['password'] = $data['password1']; // Check if the user needs to activate their account. if ($params->get('useractivation')) { jimport('joomla.user.helper'); $data['activation'] = JUtility::getHash(JUserHelper::genRandomPassword()); $data['block'] = 1; } // Bind the data. if (!$user->bind($data)) { $this->setError(JText::sprintf('USERS REGISTRATION BIND FAILED', $user->getError())); return false; } // Load the users plugin group. JPluginHelper::importPlugin('users'); // Store the data. if (!$user->save()) { $this->setError($user->getError()); return false; } // Compile the notification mail values. $data = $user->getProperties(); $data['fromname'] = $config->getValue('fromname'); $data['mailfrom'] = $config->getValue('mailfrom'); $data['sitename'] = $config->getValue('sitename'); // Handle account activation/confirmation e-mails. if ($params->get('useractivation')) { // 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); // Get the registration activation e-mail. $message = 'com_users.registration.activate'; } else { // Get the registration confirmation e-mail. $message = 'com_users.registration.confirm'; } // Load the message template and bind the data. jimport('joomla.utilities.simpletemplate'); $template = JxSimpleTemplate::getInstance($message); $template->bind($data); // Send the registration e-mail. $return = JUtility::sendMail($data['mailfrom'], $data['fromname'], $data['email'], $template->getTitle(), $template->getBody()); // Check for an error. if ($return !== true) { $this->setError(JText::_('USERS REGISTRATION SEND MAIL FAILED')); return false; } return $user->id; }
/** * Saves a JUser object to the database. This method has been adapted from * the JUser::save() method to bypass ACL checks for super users. It still * calls the onUserBeforeSave and onUserAfterSave events. * * @param JUser &$user Object to save. * @param Boolean $dispatch True to call the listening plugins or False to skip dispatching * * @return boolean True on success or False on failure. * * @since 2.0 * @throws Exception */ public static function save(JUser &$user, $dispatch = true) { // Create the user table object $table = $user->getTable(); $user->params = (string) $user->getParameters(); $table->bind($user->getProperties()); $username = $user->username; // Check and store the object. if (!$table->check()) { throw new Exception(JText::sprintf('LIB_SHUSERHELPER_ERR_10511', $username, $table->getError()), 10511); } $my = JFactory::getUser(); if ($dispatch) { // Check if we are creating a new user $isNew = empty($user->id); // Get the old user $oldUser = new JUser($user->id); // Fire the onUserBeforeSave event. JPluginHelper::importPlugin('user'); $dispatcher = JDispatcher::getInstance(); $result = $dispatcher->trigger('onUserBeforeSave', array($oldUser->getProperties(), $isNew, $user->getProperties())); if (in_array(false, $result, true)) { // Plugin will have to raise its own error or throw an exception. return false; } } // Store the user data in the database if (!($result = $table->store())) { throw new Exception(JText::sprintf('LIB_SHUSERHELPER_ERR_10512', $username, $table->getError()), 10512); } // Set the id for the JUser object in case we created a new user. if (empty($user->id)) { $user->id = $table->get('id'); } if ($my->id == $table->id) { $registry = new JRegistry; $registry->loadString($table->params); $my->setParameters($registry); } if ($dispatch) { // Fire the onUserAfterSave event $dispatcher->trigger('onUserAfterSave', array($user->getProperties(), $isNew, $result, $user->getError())); } return $result; }
/** * process the plugin, called when form is submitted * * @param object $params * @param object form model */ function onBeforeStore(&$params, &$formModel) { $app = JFactory::getApplication(); $config = JFactory::getConfig(); $lang = JFactory::getLanguage(); //load up com_users lang - used in email text $lang->load('com_users'); //if the fabrik table is set to be jos_users and the this plugin is used //we need to alter the form model to tell it not to store the main row // but to still store any joined rows $ftable = str_replace('#__', $app->getCfg('dbprefix'), $formModel->getlistModel()->getTable()->db_table_name); $jos_users = $app->getCfg('dbprefix') . 'users'; if ($ftable == $jos_users) { $formModel->_storeMainRow = false; } $usersConfig = JComponentHelper::getParams('com_users'); // Initialize some variables $me = JFactory::getUser(); $acl = JFactory::getACL(); //$mailFrom = $app->getCfg('mailfrom'); //$FromName = $app->getCfg('fromname'); //$SiteName = $app->getCfg('sitename'); $siteURL = JURI::base(); $bypassActivation = $params->get('juser_bypass_activation', false); $bypassRegistration = $params->get('juser_bypass_registration', true); // load in the com_user language file $lang = JFactory::getLanguage(); $lang->load('com_user'); $data = $formModel->_formData; // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); $option = JRequest::getCmd('option'); $original_id = 0; if ($params->get('juser_field_userid') != '') { $this->useridfield = $this->getFieldName($params, 'juser_field_userid'); if (!empty($formModel->_rowId)) { $original_id = (int) $formModel->_formData[$this->useridfield]; } } else { $original_id = 0; $this->useridfield = ''; } // Create a new JUser object $user = new JUser($original_id); $originalGroups = $user->getAuthorisedGroups(); // Are we dealing with a new user which we need to create? $isNew = $user->get('id') < 1; if ($isNew && $usersConfig->get('allowUserRegistration') == '0' && !$bypassRegistration) { JError::raiseError(403, JText::_('Access Forbidden - Registration not enabled')); return false; } $data = array(); $this->passwordfield = $this->getFieldName($params, 'juser_field_password'); $this->passwordvalue = $this->getFieldValue($params, 'juser_field_password', $formModel->_formData); $this->namefield = $this->getFieldName($params, 'juser_field_name'); $this->namevalue = $this->getFieldValue($params, 'juser_field_name', $formModel->_formData); $this->usernamefield = $this->getFieldName($params, 'juser_field_username'); $this->usernamevalue = $this->getFieldValue($params, 'juser_field_username', $formModel->_formData); $this->emailfield = $this->getFieldName($params, 'juser_field_email'); $this->emailvalue = $this->getFieldValue($params, 'juser_field_email', $formModel->_formData); $data['id'] = $original_id; $this->gidfield = $this->getFieldName($params, 'juser_field_usertype'); $defaultGroup = (int) $params->get('juser_field_default_group'); $groupId = JArrayHelper::getValue($formModel->_formData, $this->gidfield, $defaultGroup); if (is_array($groupId)) { $groupId = $groupId[0]; } $groupId = (int) $groupId; if (!$isNew) { if ($params->get('juser_field_usertype') != '') { if (in_array($groupId, $me->getAuthorisedGroups()) || $me->authorise('core.admin')) { $data['gid'] = $groupId; } else { JError::raiseNotice(500, "could not alter user group to {$groupId} as you are not assigned to that group"); } } else { // if editing an existing user and no gid field being used, // use default group id $data['gid'] = $defaultGroup; } } else { $data['gid'] = $params->get('juser_field_usertype') != '' ? $groupId : $defaultGroup; } if ($data['gid'] === 0) { $data['gid'] = $defaultGroup; } $user->groups = (array) $data['gid']; if ($params->get('juser_field_block') != '') { $this->blockfield = $this->getFieldName($params, 'juser_field_block'); $blocked = JArrayHelper::getValue($formModel->_formData, $this->blockfield, ''); if (is_array($blocked)) { // probably a dropdown $data['block'] = (int) $blocked[0]; } else { $data['block'] = (int) $blocked; } } else { $data['block'] = 0; } //$$$tom get password field to use in $origdata object if editing user and not changing password $origdata = $formModel->_origData; $pwfield = $this->passwordfield; $data['username'] = $this->usernamevalue; $data['password'] = $this->passwordvalue; $data['password2'] = $this->passwordvalue; $data['name'] = $this->namevalue; $name = $this->namevalue; $data['email'] = $this->emailvalue; $ok = $this->check($data, $formModel, $params); if (!$ok) { // @TODO - add some error reporting return false; } // Set the registration timestamp if ($isNew) { $now = JFactory::getDate(); $user->set('registerDate', $now->toSql()); } if ($isNew) { // If user activation is turned on, we need to set the activation information $useractivation = $usersConfig->get('useractivation'); if ($useractivation == '1' && !$bypassActivation) { jimport('joomla.user.helper'); $data['activation'] = JUtility::getHash(JUserHelper::genRandomPassword()); $data['block'] = 1; } } // Check that username is not greater than 150 characters $username = $data['username']; if (strlen($username) > 150) { $username = substr($username, 0, 150); $user->set('username', $username); } // Check that password is not greater than 100 characters if (strlen($data['password']) > 100) { $data['password'] = substr($data['password'], 0, 100); } // end new if (!$user->bind($data)) { $app->enqueueMessage(JText::_('CANNOT SAVE THE USER INFORMATION'), 'message'); $app->enqueueMessage($user->getError(), 'error'); return false; } /* * Lets save the JUser object */ if (!$user->save()) { $app->enqueueMessage(JText::_('CANNOT SAVE THE USER INFORMATION'), 'message'); $app->enqueueMessage($user->getError(), 'error'); return false; } $session = JFactory::getSession(); JRequest::setVar('newuserid', $user->id); JRequest::setVar('newuserid', $user->id, 'cookie'); $session->set('newuserid', $user->id); JRequest::setVar('newuserid_element', $this->useridfield); JRequest::setVar('newuserid_element', $this->useridfield, 'cookie'); $session->set('newuserid_element', $this->useridfield); /* * Time for the email magic so get ready to sprinkle the magic dust... */ $emailSubject = ''; if ($isNew) { // 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(); $uri = JURI::getInstance(); $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')); // Handle account activation/confirmation emails. if ($useractivation == 2 && !$bypassActivation) { // Set the link to confirm the user email. $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']); } else { if ($useractivation == 1 && !$bypassActivation) { // Set the link to activate the user account. $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']); } elseif ($params->get('juser_bypass_accountdetails') != 1) { $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. if ($emailSubject !== '') { $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\n\t\t\t\t\t\t\t\tFROM #__users\n\t\t\t\t\t\t\t\tWHERE block = 0\n\t\t\t\t\t\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 `#__messages` (`user_id_from`, `user_id_to`, `date_time`, `subject`, `message`)\n\t\t\t\t\t\t\t\t\tVALUES "; $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(); } } } } // If updating self, load the new user object into the session // FIXME - doesnt work in J1.7?? /* if ($user->get('id') == $me->get('id')) { // Get an ACL object $acl = &JFactory::getACL(); // Get the user group from the ACL $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); $session->set('user', $user); } */ if (!empty($this->useridfield)) { $formModel->updateFormData($this->useridfield, $user->get('id'), true); } if ($ftable == $jos_users) { $formModel->_rowId = $user->get('id'); } }
/** * Send an activation email to the user * * @param JUser $user */ private function sendActivationEmail($user, $indata) { $app = JFactory::getApplication(); $config = JFactory::getConfig(); $db = JFactory::getDbo(); $params = JComponentHelper::getParams('com_users'); $data = array_merge((array) $user->getProperties(), $indata); $useractivation = $params->get('useractivation'); $sendpassword = $params->get('sendpassword', 1); // Check if the user needs to activate their account. if ($useractivation == 1 || $useractivation == 2) { $user->activation = JApplication::getHash(JUserHelper::genRandomPassword()); $user->block = 1; $user->lastvisitDate = JFactory::getDbo()->getNullDate(); } else { $user->block = 0; } // Load the users plugin group. JPluginHelper::importPlugin('user'); // Store the data. if (!$user->save()) { return false; } // Compile the notification mail values. $data = $user->getProperties(); $data['password_clear'] = $indata['password2']; $data['fromname'] = $config->get('fromname'); $data['mailfrom'] = $config->get('mailfrom'); $data['sitename'] = $config->get('sitename'); $data['siteurl'] = JUri::root(); // Load com_users translation files $jlang = JFactory::getLanguage(); $jlang->load('com_users', JPATH_SITE, 'en-GB', true); // Load English (British) $jlang->load('com_users', JPATH_SITE, $jlang->getDefault(), true); // Load the site's default language $jlang->load('com_users', JPATH_SITE, null, true); // Load the currently selected language // Handle account activation/confirmation emails. if ($useractivation == 2) { $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['activate'], $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['activate'], $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['activate'], $data['siteurl'], $data['username'], $data['password_clear']); } else { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username']); } } else { $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); if ($sendpassword) { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY', $data['name'], $data['sitename'], $data['siteurl'], $data['username'], $data['password_clear']); } else { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY_NOPW', $data['name'], $data['sitename'], $data['siteurl']); } } // 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 = $db->getQuery(true); $query->select($db->quoteName(array('name', 'email', 'sendEmail', 'id')))->from($db->quoteName('#__users'))->where($db->quoteName('sendEmail') . ' = ' . 1); $db->setQuery($query); try { $rows = $db->loadObjectList(); } catch (RuntimeException $e) { return false; } // Send mail to all superadministrators id foreach ($rows as $row) { $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBodyAdmin); } } return $return; }
/** * Method to save the form data. * * @param array $temp The form data. * * @return mixed The user id on success, false on failure. * * @since 1.6 */ public function register($temp) { $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'] = JStringPunycode::emailToPunycode($data['email1']); $data['password'] = $data['password1']; $useractivation = $params->get('useractivation'); $sendpassword = $params->get('sendpassword', 1); // Check if the user needs to activate their account. 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; } // Load the users plugin group. JPluginHelper::importPlugin('user'); // Store the data. if (!$user->save()) { $this->setError($user->getError()); return false; } $config = JFactory::getConfig(); $db = $this->getDbo(); $query = $db->getQuery(true); // 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['activate'], $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['activate'], $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['activate'], $data['siteurl'], $data['username'], $data['password_clear']); } else { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username']); } } else { $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); if ($sendpassword) { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY', $data['name'], $data['sitename'], $data['siteurl'], $data['username'], $data['password_clear']); } else { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY_NOPW', $data['name'], $data['sitename'], $data['siteurl']); } } // 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->clear()->select($db->quoteName(array('name', 'email', 'sendEmail')))->from($db->quoteName('#__users'))->where($db->quoteName('sendEmail') . ' = ' . 1); $db->setQuery($query); try { $rows = $db->loadObjectList(); } catch (RuntimeException $e) { $this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500); return false; } // 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; } } } // 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(); $query->clear()->select($db->quoteName(array('name', 'email', 'sendEmail', 'id')))->from($db->quoteName('#__users'))->where($db->quoteName('block') . ' = ' . (int) 0)->where($db->quoteName('sendEmail') . ' = ' . (int) 1); $db->setQuery($query); try { $sendEmail = $db->loadColumn(); } catch (RuntimeException $e) { $this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500); return false; } if (count($sendEmail) > 0) { $jdate = new JDate(); // Build the query to add the messages foreach ($sendEmail as $userid) { $values = array($db->quote($userid), $db->quote($userid), $db->quote($jdate->toSql()), $db->quote(JText::_('COM_USERS_MAIL_SEND_FAILURE_SUBJECT')), $db->quote(JText::sprintf('COM_USERS_MAIL_SEND_FAILURE_BODY', $return, $data['username']))); $query->clear()->insert($db->quoteName('#__messages'))->columns($db->quoteName(array('user_id_from', 'user_id_to', 'date_time', 'subject', 'message')))->values(implode(',', $values)); $db->setQuery($query); try { $db->execute(); } catch (RuntimeException $e) { $this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500); return false; } } } return false; } if ($useractivation == 1) { return "useractivate"; } elseif ($useractivation == 2) { return "adminactivate"; } else { return $user->id; } }
public function site_reg() { $app = JFactory::getApplication(); $db = JFactory::getDBO(); $user = new JUser(); $data = array(); $login = JRequest::getVar('login', ''); $first_name = JRequest::getVar('first_name', ''); $last_name = JRequest::getVar('last_name', ''); $middle_name = JRequest::getVar('middle_name', ''); $password = JRequest::getVar('password', ''); $subscribe = JRequest::getVar('subscribe', 0); $fields = JRequest::getVar('fields', array()); $ajax = JRequest::getVar('ajax', false); $name = ''; if (!empty($last_name)) { $name .= $last_name . ' '; } if (!empty($first_name)) { $name .= $first_name . ' '; } if (!empty($middle_name)) { $name .= $middle_name; } $data['name'] = $name; $data['username'] = $login; $data['email'] = $login; $data['email1'] = $login; $data['email2'] = $login; $data['password'] = $password; $data['password1'] = $password; $data['password2'] = $password; $data['groups'] = array(2); $data['activation'] = ''; $data['block'] = 0; if (!$user->bind($data)) { if ($ajax) { print_r($user->getError()); exit; } else { $app->enqueueMessage($user->getError(), 'warning'); $this->setRedirect(JRoute::_('index.php?option=com_ksenmart&view=profile&layout=registration&Itemid=' . KSSystem::getShopItemid())); return false; } } JPluginHelper::importPlugin('user'); if (!$user->save()) { if ($ajax) { print_r($user->getError()); exit; } else { $app->enqueueMessage($user->getError(), 'warning'); $this->setRedirect(JRoute::_('index.php?option=com_ksenmart&view=profile&layout=registration&Itemid=' . KSSystem::getShopItemid())); return false; } } $options = array(); $options['remember'] = true; $options['return'] = ''; $credentials = array(); $credentials['username'] = $login; $credentials['password'] = $password; $app->login($credentials, $options); $params = JComponentHelper::getParams('com_ksenmart'); $config = JFactory::getConfig(); $data = $user->getProperties(); $data['fromname'] = $params->get('shop_name', ''); $data['mailfrom'] = $params->get('shop_email', ''); $data['sitename'] = $config->get('sitename'); $data['siteurl'] = JURI::root(); $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $login, $data['sitename']); $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY', $login, $data['sitename'], $data['siteurl'], $login, $password); $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $login, $emailSubject, $emailBody); $query = "insert into #__ksen_users (`id`,`first_name`,`last_name`,`middle_name`) values ('{$user->id}','{$first_name}','{$last_name}','{$middle_name}')"; $db->setQuery($query); $db->Query(); foreach ($fields as $key => $value) { $values = array('user_id' => $user->id, 'field_id' => $key, 'value' => $db->quote($value)); $query = $db->getQuery(true); $query->insert('#__ksen_user_fields_values')->columns(implode(',', array_keys($values)))->values(implode(',', $values)); $db->setQuery($query); $db->query(); } $session = JFactory::getSession(); $order_id = $session->get('shop_order_id', 0); if ($order_id != 0) { $query = "update #__ksenmart_orders set user_id='{$user->id}' where id='{$order_id}'"; $db->setQuery($query); $db->Query(); } if ($ajax) { $app->close('login'); } else { $this->setRedirect('/'); } }
/** * 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; }
public function doRegAdv($adv_user, $user, $return_to_task = 'step2') { $session = JFactory::getSession(); //сохраняем указанный метод оплаты в сессию $payment_method = JRequest::getVar('payment_method', ''); //class payment method if ($payment_method != '') { $session->set("payment_method", $payment_method); } $order_add_info = JRequest::getVar('order_add_info', ''); if ($order_add_info != '') { $session->set("order_add_info", $order_add_info); } //проверяем, есть ли такой мейл в базе и редиректим на логин если нужно if ($this->checkThisEmail($adv_user->email) == false) { $this->checkUserLogin($return_to_task); } require_once JPATH_ROOT . "/components/com_jshopping/lib/functions.php"; //echo'<pre>';print_r($_POST);echo'</pre>';die; $mainframe = JFactory::getApplication(); $jshopConfig = JSFactory::getConfig(); $config = JFactory::getConfig(); $db = JFactory::getDBO(); $params = JComponentHelper::getParams('com_users'); $lang = JFactory::getLanguage(); $lang->load('com_users'); //$post = JRequest::get('post'); // if ($user->guest) { // $redirecturl = base64_encode("index.php?option=com_hostorder"); // $joomlaLoginUrl = 'index.php?option=com_user&view=login&return='; // $finalUrl = $joomlaLoginUrl.$redirecturl; // // global $mainframe; // $mainframe->redirect($finalUrl); //echo'<pre>';print_r($adv_user);echo'</pre>';die; $usergroup = JSFactory::getTable('usergroup', 'jshop'); $default_usergroup = $usergroup->getDefaultUsergroup(); $post = array(); $post['email'] = $adv_user->email; $post['phone'] = $adv_user->phone; $post['username'] = $post['email']; $post['f_name'] = $adv_user->f_name; $post['l_name'] = $adv_user->l_name; $post['u_name'] = $adv_user->email; $post['country'] = JRequest::getVar('country', 20); $post['lang'] = $jshopConfig->getLang(); $post["password"] = substr(md5('up' . time()), 0, 8); $row = JSFactory::getTable('userShop', 'jshop'); $row->bind($post); $row->user_id = 0; $row->usergroup_id = $default_usergroup; $row->password = $post['password']; $row->password2 = $post['password']; //echo'<pre>';print_r($row);echo'</pre>';die; $row->check("register"); $adv_user->bind($post); $user = new JUser(); $data = array(); $data['groups'][] = $params->get('new_usertype', 2); $data['email'] = $post['email']; $data['password'] = $post['password']; $data['password2'] = $post['password']; $data['name'] = $post['f_name'] . ' ' . $post['l_name']; $data['username'] = $post["u_name"]; $useractivation = $params->get('useractivation'); $sendpassword = $params->get('sendpassword', 1); $user->bind($data); if (!$user->save()) { JError::raiseWarning('', $user->getError()); saveToLog('error.log', 'Error registration-' . $user->getError()); $mainframe->redirect(SEFLink("index.php?option=com_jshopping&controller=user&task=register", 1, 1, $jshopConfig->use_ssl)); return 0; } $row->user_id = $user->id; $row->number = $row->getNewUserNumber(); unset($row->password); unset($row->password2); if (!$db->insertObject($row->getTableName(), $row, $row->getKeyName())) { saveToLog('error.log', $db->getErrorMsg()); JError::raiseWarning('', "Error insert in table " . $row->getTableName()); $mainframe->redirect(SEFLink("index.php?option=com_jshopping&controller=user&task=register", 1, 1, $jshopConfig->use_ssl)); return 0; } //echo'<pre>';print_r($adv_user);echo'</pre>';die; $adv_user->store(); //echo'<pre>';print_r($adv_user);echo'</pre>';die; $session = JFactory::getSession(); $session->set("order_user_id", $user->id); $data = $user->getProperties(); $data['fromname'] = $config->get('fromname'); $data['mailfrom'] = $config->get('mailfrom'); $data['sitename'] = $config->get('sitename'); $data['siteurl'] = JUri::base(); $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); if ($sendpassword) { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY', $data['name'], $data['sitename'], $data['siteurl'], $data['username'], $data['password_clear']); } else { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY_NOPW', $data['name'], $data['sitename'], $data['siteurl']); } $mailer = JFactory::getMailer(); $mailer->setSender(array($data['mailfrom'], $data['fromname'])); $mailer->addRecipient($data['email']); $mailer->setSubject($emailSubject); $mailer->setBody($emailBody); $mailer->isHTML(false); $mailer->Send(); $options = array(); $options['remember'] = false; //$options['return'] = JURI::root(); $credentials = array(); $credentials['username'] = $post['email']; $credentials['password'] = $post['password']; //echo'<pre>';print_r($mainframe);echo'</pre>';die; $error = $mainframe->login($credentials, $options); //echo'<pre>';print_r($mainframe);echo'</pre>';die; }
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; } }
/** * Method to save the JUser object to the database * * @access public * @param boolean $updateOnly Save the object only if not a new user * @return boolean True on success * @since 1.5 */ function save($updateOnly = false) { // Create the user table object $table =& $this->getTable(); $this->params = $this->_params->toString(); $table->bind($this->getProperties()); // Check and store the object. if (!$table->check()) { $this->setError($table->getError()); return false; } // If user is made a Super Admin group and user is NOT a Super Admin $my =& JFactory::getUser(); if ($this->get('gid') == 25 && $my->get('gid') != 25) { // disallow creation of Super Admin by non Super Admin users $this->setError(JText::_('WARNSUPERADMINCREATE')); return false; } // If user is made an Admin group and user is NOT a Super Admin if ($this->get('gid') == 24 && !($my->get('gid') == 25 || $this->get('id') == $my->id && $my->get('gid') == 24)) { // disallow creation of Admin by non Super Admin users $this->setError(JText::_('WARNSUPERADMINCREATE')); return false; } //are we creating a new user $isnew = !$this->id; // If we aren't allowed to create new users return if ($isnew && $updateOnly) { return true; } // Get the old user $old = new JUser($this->id); // Fire the onBeforeStoreUser event. JPluginHelper::importPlugin('user'); $dispatcher =& JDispatcher::getInstance(); $dispatcher->trigger('onBeforeStoreUser', array($old->getProperties(), $isnew)); //Store the user data in the database if (!($result = $table->store())) { $this->setError($table->getError()); } // Set the id for the JUser object in case we created a new user. if (empty($this->id)) { $this->id = $table->get('id'); } // Fire the onAftereStoreUser event $dispatcher->trigger('onAfterStoreUser', array($this->getProperties(), $isnew, $result, $this->getError())); return $result; }
function registersave() { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $mainframe = JFactory::getApplication(); $jshopConfig = JSFactory::getConfig(); $config = JFactory::getConfig(); $db = JFactory::getDBO(); $params = JComponentHelper::getParams('com_users'); $lang = JFactory::getLanguage(); $lang->load('com_users'); $post = JRequest::get('post'); JPluginHelper::importPlugin('jshoppingcheckout'); $dispatcher = JDispatcher::getInstance(); if ($params->get('allowUserRegistration') == 0) { JError::raiseError(403, JText::_('Access Forbidden')); return; } $usergroup = JTable::getInstance('usergroup', 'jshop'); $default_usergroup = $usergroup->getDefaultUsergroup(); $post['username'] = $post['u_name']; $post['password2'] = $post['password_2']; if ($post['f_name'] == "") { $post['f_name'] = $post['email']; } $post['name'] = $post['f_name'] . ' ' . $post['l_name']; if ($post['birthday']) { $post['birthday'] = getJsDateDB($post['birthday'], $jshopConfig->field_birthday_format); } $dispatcher->trigger('onBeforeRegister', array(&$post, &$default_usergroup)); $row = JTable::getInstance('userShop', 'jshop'); $row->bind($post); $row->usergroup_id = $default_usergroup; $row->password = $post['password']; $row->password2 = $post['password2']; if (!$row->check("register")) { JError::raiseWarning('', $row->getError()); $this->setRedirect(SEFLink("index.php?option=com_jshopping&controller=user&task=register", 1, 1, $jshopConfig->use_ssl)); return 0; } if ($post["u_name"] == "") { $post["u_name"] = $post['email']; $row->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'); $sendpassword = $params->get('sendpassword', 1); if ($useractivation == 1 || $useractivation == 2) { jimport('joomla.user.helper'); $data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword()); $data['block'] = 1; } $user->bind($data); $user->save(); $row->user_id = $user->id; $row->number = $user->id; unset($row->password); unset($row->password2); if (!$db->insertObject($row->getTableName(), $row, $row->getKeyName())) { JError::raiseWarning('', "Error insert in table " . $row->getTableName()); $this->setRedirect(SEFLink("index.php?option=com_jshopping&controller=user&task=register", 1, 1, $jshopConfig->use_ssl)); return 0; } $data = $user->getProperties(); $data['fromname'] = $config->get('fromname'); $data['mailfrom'] = $config->get('mailfrom'); $data['sitename'] = $config->get('sitename'); $data['siteurl'] = JUri::base(); if ($useractivation == 2) { $uri = JURI::getInstance(); $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')); $data['activate'] = $base . JRoute::_('index.php?option=com_jshopping&controller=user&task=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_jshopping&controller=user&task=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_jshopping&controller=user&task=activate&token=' . $data['activation'], $data['siteurl'], $data['username']); } } else { if ($useractivation == 1) { $uri = JURI::getInstance(); $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')); $data['activate'] = $base . JRoute::_('index.php?option=com_jshopping&controller=user&task=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_jshopping&controller=user&task=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_jshopping&controller=user&task=activate&token=' . $data['activation'], $data['siteurl'], $data['username']); } } else { $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); if ($sendpassword) { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY', $data['name'], $data['sitename'], $data['siteurl'], $data['username'], $data['password_clear']); } else { $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY_NOPW', $data['name'], $data['sitename'], $data['siteurl']); } } } $dispatcher->trigger('onBeforeRegisterSendMailClient', array(&$post, &$data, &$emailSubject, &$emailBody)); $mailer = JFactory::getMailer(); $mailer->setSender(array($data['mailfrom'], $data['fromname'])); $mailer->addRecipient($data['email']); $mailer->setSubject($emailSubject); $mailer->setBody($emailBody); $mailer->isHTML(false); $return = $mailer->Send(); 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']); $query = 'SELECT name, email, sendEmail FROM #__users WHERE sendEmail=1'; $db->setQuery($query); $rows = $db->loadObjectList(); foreach ($rows as $rowadm) { $dispatcher->trigger('onBeforeRegisterSendMailAdmin', array(&$post, &$data, &$emailSubject, &$emailBodyAdmin, &$rowadm)); $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $rowadm->email, $emailSubject, $emailBodyAdmin); } } $dispatcher->trigger('onAfterRegister', array(&$user, &$row, &$post, &$useractivation)); if ($useractivation == 2) { $message = JText::_('COM_USERS_REGISTRATION_COMPLETE_VERIFY'); $return = SEFLink("index.php?option=com_jshopping&controller=user&task=login", 1, 1, $jshopConfig->use_ssl); } elseif ($useractivation == 1) { $message = JText::_('COM_USERS_REGISTRATION_COMPLETE_ACTIVATE'); $return = SEFLink("index.php?option=com_jshopping&controller=user&task=login", 1, 1, $jshopConfig->use_ssl); } else { $message = JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS'); $return = SEFLink("index.php?option=com_jshopping&controller=user&task=login", 1, 1, $jshopConfig->use_ssl); } $this->setRedirect($return, $message); }
/** * 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) { $db = $this->getDbo(); $params = Component::params('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'); $sendpassword = $params->get('sendpassword', 1); // Check if the user needs to activate their account. if ($useractivation == 1 || $useractivation == 2) { $data['activation'] = App::hash(JUserHelper::genRandomPassword()); $data['block'] = 1; } // Bind the data. if (!$user->bind($data)) { $this->setError(Lang::txt('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError())); return false; } // Load the users plugin group. Plugin::import('user'); // Store the data. if (!$user->save()) { $this->setError(Lang::txt('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'] = Request::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 . Route::url('index.php?option=com_users&task=registration.activate&token=' . $data['activation'], false); $emailSubject = Lang::txt('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); if ($sendpassword) { $emailBody = Lang::txt('COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username'], $data['password_clear']); } else { $emailBody = Lang::txt('COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['activate'], $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 . Route::url('index.php?option=com_users&task=registration.activate&token=' . $data['activation'], false); $emailSubject = Lang::txt('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); if ($sendpassword) { $emailBody = Lang::txt('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username'], $data['password_clear']); } else { $emailBody = Lang::txt('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username']); } } else { $emailSubject = Lang::txt('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); $emailBody = Lang::txt('COM_USERS_EMAIL_REGISTERED_BODY', $data['name'], $data['sitename'], $data['siteurl']); } // 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 = Lang::txt('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']); $emailBodyAdmin = Lang::txt('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(Lang::txt('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED')); return false; } } } // Check for an error. if ($return !== true) { $this->setError(Lang::txt('COM_USERS_REGISTRATION_SEND_MAIL_FAILED')); // Send a system message to administrators receiving system mails $db = App::get('db'); $q = "SELECT id\n\t\t\t\tFROM #__users\n\t\t\t\tWHERE block = 0\n\t\t\t\tAND sendEmail = 1"; $db->setQuery($q); $sendEmail = $db->loadColumn(); if (count($sendEmail) > 0) { $jdate = new \Hubzero\Utility\Date(); // 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() . "', '" . Lang::txt('COM_USERS_MAIL_SEND_FAILURE_SUBJECT') . "', '" . Lang::txt('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; } }