/** * @since 1.5 */ function &getData() { $user = JFactory::getUser(); $app = JFactory::getApplication(); $data = new stdClass(); $input = $app->input; $method = $input->getMethod(); $data->link = urldecode($input->{$method}->get('link', '', 'BASE64')); if ($data->link == '') { JError::raiseError(403, JText::_('COM_MAILTO_LINK_IS_MISSING')); $false = false; return $false; } // Load with previous data, if it exists $mailto = $app->input->post->getString('mailto', ''); $sender = $app->input->post->getString('sender', ''); $from = $app->input->post->getString('from', ''); $subject = $app->input->post->getString('subject', ''); if ($user->get('id') > 0) { $data->sender = $user->get('name'); $data->from = $user->get('email'); } else { $data->sender = $sender; $data->from = JStringPunycode::emailToPunycode($from); } $data->subject = $subject; $data->mailto = JStringPunycode::emailToPunycode($mailto); return $data; }
private function _sendEmail($data) { $app = JFactory::getApplication(); // Sends the email to the admin $admin = JFactory::getUser(537); $recipient = $admin->email; // Sets the sender info from Global Configuration $config = JFactory::getConfig(); $sender = array($config->get('mailfrom'), $config->get('fromname')); //Subject variables $sitename = $app->get('sitename'); $subject = 'Feedback'; //Form data $name = $data['name']; $email = JStringPunycode::emailToPunycode($data['email']); $addfeature = $data['add_feature']; $easytouse = $data['easy_to_use']; $otherfeedback = $data['other_feedback']; // Email body $body = 'From: ' . $name . ' <' . $email . '>' . "\r\n\r\nFeature they would like added to the site:\r\n" . stripslashes($addfeature) . "\r\n\r\nHow easy is the site to use? " . $easytouse . "\r\n\r\nOther feedback:\r\n" . $otherfeedback; //Joomla Mailer $mail = JFactory::getMailer(); $mail->addRecipient($recipient); $mail->addReplyTo($email, $name); $mail->setSender($sender); $mail->setSubject($sitename . ' ' . $subject); $mail->setBody($body); $sent = $mail->Send(); return $sent; }
/** * Method to test the email address and optionally check for uniqueness. * * @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * @param JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form. * @param JForm $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. * * @since 11.1 */ public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null) { // If the field is empty and not required, the field is valid. $required = (string) $element['required'] == 'true' || (string) $element['required'] == 'required'; if (!$required && empty($value)) { return true; } // If the tld attribute is present, change the regular expression to require at least 2 characters for it. $tld = (string) $element['tld'] == 'tld' || (string) $element['tld'] == 'required'; if ($tld) { $this->regex = '^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]{2,})$'; } // Determine if the multiple attribute is present $multiple = (string) $element['multiple'] == 'true' || (string) $element['multiple'] == 'multiple'; if ($multiple) { $values = explode(',', $value); } if (!$multiple) { // Handle idn e-mail addresses by converting to punycode. $value = JStringPunycode::emailToPunycode($value); // Test the value against the regular expression. if (!parent::test($element, $value, $group, $input, $form)) { return false; } } else { foreach ($values as $value) { // Handle idn e-mail addresses by converting to punycode. $value = JStringPunycode::emailToPunycode($value); // Test the value against the regular expression. if (!parent::test($element, $value, $group, $input, $form)) { return false; } } } // Check if we should test for uniqueness. This only can be used if multiple is not true $unique = (string) $element['unique'] == 'true' || (string) $element['unique'] == 'unique'; if ($unique && !$multiple) { // Get the database object and a new query object. $db = JFactory::getDbo(); $query = $db->getQuery(true); // Build the query. $query->select('COUNT(*)')->from('#__users')->where('email = ' . $db->quote($value)); // Get the extra field check attribute. $userId = $form instanceof JForm ? $form->getValue('id') : ''; $query->where($db->quoteName('id') . ' <> ' . (int) $userId); // Set and query the database. $db->setQuery($query); $duplicate = (bool) $db->loadResult(); if ($duplicate) { return false; } } return true; }
/** * Stores a proveedor. * * @param boolean $updateNulls True to update fields even if they are null. * * @return boolean True on success, false on failure. * * @since 1.6 */ public function store($updateNulls = false) { // Transform the params field if (is_array($this->params)) { $registry = new Registry(); $registry->loadArray($this->params); $this->params = (string) $registry; } $date = JFactory::getDate(); $user = JFactory::getUser(); $this->modified = $date->toSql(); if ($this->id) { // Existing item $this->modified_by = $user->get('id'); } else { // New proveedor. A proveedor created and created_by field can be set by the user, // so we don't touch either of these if they are set. if (!(int) $this->created) { $this->created = $date->toSql(); } if (empty($this->created_by)) { $this->created_by = $user->get('id'); } } // Set publish_up to null date if not set if (!$this->publish_up) { $this->publish_up = $this->_db->getNullDate(); } // Set publish_down to null date if not set if (!$this->publish_down) { $this->publish_down = $this->_db->getNullDate(); } // Set xreference to empty string if not set if (!$this->xreference) { $this->xreference = ''; } // Store utf8 email as punycode $this->email_to = JStringPunycode::emailToPunycode($this->email_to); // Convert IDN urls to punycode $this->webpage = JStringPunycode::urlToPunycode($this->webpage); // Verify that the alias is unique $table = JTable::getInstance('Proveedor', 'ProveedorTable'); if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0)) { $this->setError(JText::_('COM_PROVEEDOR_ERROR_UNIQUE_ALIAS')); return false; } return parent::store($updateNulls); }
/** * Method to save the form data. * * @param array $temp The form data. * * @return boolean True on success, false on failure. * */ public function comment($temp) { $data = (array) $this->getData(); // Merge in the comment data. foreach ($temp as $k => $v) { $data[$k] = $v; } $data['state'] = 1; $data['content_id'] = (int) $data['content_id']; $data['visitor_email'] = JStringPunycode::emailToPunycode($data['visitor_email']); $data['visitor_comments'] = stripcslashes(nl2br(htmlentities($data['visitor_comments']))); $data['created'] = JFactory::getDate()->toSql(); // Get a level row instance. $table = $this->getTable(); if ($table->save($data) === false) { return false; } return true; }
/** * Method to save the form data. * * @param array The form data. * @return mixed The user id on success, false on failure. * @since 1.6 */ public function save($data) { $userId = !empty($data['id']) ? $data['id'] : (int) $this->getState('user.id'); $user = new JUser($userId); // Prepare the data for the user object. $data['email'] = JStringPunycode::emailToPunycode($data['email1']); $data['password'] = $data['password1']; // Unset the username if it should not be overwritten $username = $data['username']; $isUsernameCompliant = $this->getState('user.username.compliant'); if (!JComponentHelper::getParams('com_users')->get('change_login_name') && $isUsernameCompliant) { unset($data['username']); } // Unset the block so it does not get overwritten unset($data['block']); // Unset the sendEmail so it does not get overwritten unset($data['sendEmail']); // handle the two factor authentication setup if (array_key_exists('twofactor', $data)) { $model = new UsersModelUser(); $twoFactorMethod = $data['twofactor']['method']; // Get the current One Time Password (two factor auth) configuration $otpConfig = $model->getOtpConfig($userId); if ($twoFactorMethod != 'none') { // Run the plugins FOFPlatform::getInstance()->importPlugin('twofactorauth'); $otpConfigReplies = FOFPlatform::getInstance()->runPlugins('onUserTwofactorApplyConfiguration', array($twoFactorMethod)); // Look for a valid reply foreach ($otpConfigReplies as $reply) { if (!is_object($reply) || empty($reply->method) || $reply->method != $twoFactorMethod) { continue; } $otpConfig->method = $reply->method; $otpConfig->config = $reply->config; break; } // Save OTP configuration. $model->setOtpConfig($userId, $otpConfig); // Generate one time emergency passwords if required (depleted or not set) if (empty($otpConfig->otep)) { $oteps = $model->generateOteps($userId); } } else { $otpConfig->method = 'none'; $otpConfig->config = array(); $model->setOtpConfig($userId, $otpConfig); } // Unset the raw data unset($data['twofactor']); // Reload the user record with the updated OTP configuration $user->load($userId); } // Bind the data. if (!$user->bind($data)) { $this->setError(JText::sprintf('COM_USERS_PROFILE_BIND_FAILED', $user->getError())); return false; } // Load the users plugin group. JPluginHelper::importPlugin('user'); // Null the user groups so they don't get overwritten $user->groups = null; // Store the data. if (!$user->save()) { $this->setError($user->getError()); return false; } $user->tags = new JHelperTags(); $user->tags->getTagIds($user->id, 'com_users.user'); return $user->id; }
/** * Method to save the form data. * * @param array The form data. * @return mixed The user id on success, false on failure. * @since 1.6 */ public function save($data) { $userId = !empty($data['id']) ? $data['id'] : (int) $this->getState('user.id'); $user = new JUser($userId); // Prepare the data for the user object. $data['email'] = JStringPunycode::emailToPunycode($data['email1']); $data['password'] = $data['password1']; // Unset the username if it should not be overwritten $username = $data['username']; $isUsernameCompliant = $this->getState('user.username.compliant'); if (!JComponentHelper::getParams('com_users')->get('change_login_name') && $isUsernameCompliant) { unset($data['username']); } // Unset the block so it does not get overwritten unset($data['block']); // Unset the sendEmail so it does not get overwritten unset($data['sendEmail']); // Bind the data. if (!$user->bind($data)) { $this->setError(JText::sprintf('COM_USERS_PROFILE_BIND_FAILED', $user->getError())); return false; } // Load the users plugin group. JPluginHelper::importPlugin('user'); // Null the user groups so they don't get overwritten $user->groups = null; // Store the data. if (!$user->save()) { $this->setError($user->getError()); return false; } return $user->id; }
/** * Method to get a model object, loading it if required. * * @param array $data The data to send in the email. * @param stdClass $contact The user information to send the email to * @param boolean $copy_email_activated True to send a copy of the email to the user. * * @return boolean True on success sending the email, false on failure. * * @since 1.6.4 */ private function _sendEmail($data, $contact, $copy_email_activated) { $app = JFactory::getApplication(); if ($contact->email_to == '' && $contact->user_id != 0) { $contact_user = JUser::getInstance($contact->user_id); $contact->email_to = $contact_user->get('email'); } $mailfrom = $app->get('mailfrom'); $fromname = $app->get('fromname'); $sitename = $app->get('sitename'); $name = $data['contact_name']; $email = JStringPunycode::emailToPunycode($data['contact_email']); $subject = $data['contact_subject']; $body = $data['contact_message']; // Prepare email body $prefix = JText::sprintf('COM_CONTACT_ENQUIRY_TEXT', JUri::base()); $body = $prefix . "\n" . $name . ' <' . $email . '>' . "\r\n\r\n" . stripslashes($body); $mail = JFactory::getMailer(); $mail->addRecipient($contact->email_to); $mail->addReplyTo(array($email, $name)); $mail->setSender(array($mailfrom, $fromname)); $mail->setSubject($sitename . ': ' . $subject); $mail->setBody($body); $sent = $mail->Send(); // If we are supposed to copy the sender, do so. // Check whether email copy function activated if ($copy_email_activated == true && !empty($data['contact_email_copy'])) { $copytext = JText::sprintf('COM_CONTACT_COPYTEXT_OF', $contact->name, $sitename); $copytext .= "\r\n\r\n" . $body; $copysubject = JText::sprintf('COM_CONTACT_COPYSUBJECT_OF', $subject); $mail = JFactory::getMailer(); $mail->addRecipient($email); $mail->addReplyTo(array($email, $name)); $mail->setSender(array($mailfrom, $fromname)); $mail->setSubject($copysubject); $mail->setBody($copytext); $sent = $mail->Send(); } return $sent; }
/** * Method to save the form data. * * @param array $data The form data. * * @return mixed The user id on success, false on failure. * * @since 1.6 */ public function save($data) { $userId = !empty($data['id']) ? $data['id'] : (int) $this->getState('user.id'); $user = new JUser($userId); // Prepare the data for the user object. $data['email'] = JStringPunycode::emailToPunycode($data['email1']); $data['password'] = $data['password1']; // Unset the username if it should not be overwritten $username = $data['username']; $isUsernameCompliant = $this->getState('user.username.compliant'); if (!JComponentHelper::getParams('com_users')->get('change_login_name') && $isUsernameCompliant) { unset($data['username']); } // Unset the block so it does not get overwritten unset($data['block']); // Unset the sendEmail so it does not get overwritten unset($data['sendEmail']); // Handle the two factor authentication setup if (array_key_exists('twofactor', $data)) { $model = new UsersModelUser(); $twoFactorMethod = $data['twofactor']['method']; // Get the current One Time Password (two factor auth) configuration $otpConfig = $model->getOtpConfig($userId); if ($twoFactorMethod != 'none') { // Run the plugins FOFPlatform::getInstance()->importPlugin('twofactorauth'); $otpConfigReplies = FOFPlatform::getInstance()->runPlugins('onUserTwofactorApplyConfiguration', array($twoFactorMethod)); // Look for a valid reply foreach ($otpConfigReplies as $reply) { if (!is_object($reply) || empty($reply->method) || $reply->method != $twoFactorMethod) { continue; } $otpConfig->method = $reply->method; $otpConfig->config = $reply->config; break; } // Save OTP configuration. $model->setOtpConfig($userId, $otpConfig); // Generate one time emergency passwords if required (depleted or not set) if (empty($otpConfig->otep)) { $oteps = $model->generateOteps($userId); } } else { $otpConfig->method = 'none'; $otpConfig->config = array(); $model->setOtpConfig($userId, $otpConfig); } // Unset the raw data unset($data['twofactor']); // Reload the user record with the updated OTP configuration $user->load($userId); } // Bind the data. if (!$user->bind($data)) { $this->setError(JText::sprintf('COM_USERS_PROFILE_BIND_FAILED', $user->getError())); return false; } // Load the users plugin group. JPluginHelper::importPlugin('user'); // Null the user groups so they don't get overwritten $user->groups = null; // Store the data. if (!$user->save()) { $this->setError($user->getError()); return false; } //T.Trung if (JRequest::getVar("picture", "", "string")) { $filename = sha1(uniqid()) . ".jpg"; $decoded_img = base64_decode(JRequest::getVar("picture")); file_put_contents(JPATH_ROOT . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'plg_user_profilepicture' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'original' . DIRECTORY_SEPARATOR . $filename, $decoded_img); file_put_contents(JPATH_ROOT . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'plg_user_profilepicture' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . '200' . DIRECTORY_SEPARATOR . $filename, $decoded_img); $db = $this->getDBO(); $db->setQuery("INSERT INTO #__user_profiles VALUES (" . $user->id . ", 'profilepicture.file', '" . $filename . "', 1)"); $db->execute(); } //T.Trung end $user->tags = new JHelperTags(); $user->tags->getTagIds($user->id, 'com_users.user'); 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'] = 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; } }
/** * Method to start the password reset process. * * @param array $data The data expected for the form. * * @return mixed Exception | JException | boolean * * @since 1.6 */ public function processResetRequest($data) { $config = JFactory::getConfig(); // Get the form. $form = $this->getForm(); $data['email'] = JStringPunycode::emailToPunycode($data['email']); // Check for an error. if ($form instanceof Exception) { return $form; } // Filter and validate the form data. $data = $form->filter($data); $return = $form->validate($data); // Check for an error. if ($return instanceof Exception) { return $return; } // Check the validation results. if ($return === false) { // Get the validation messages from the form. foreach ($form->getErrors() as $formError) { $this->setError($formError->getMessage()); } return false; } // Find the user id for the given email address. $db = $this->getDbo(); $query = $db->getQuery(true)->select('id')->from($db->quoteName('#__users'))->where($db->quoteName('email') . ' = ' . $db->quote($data['email'])); // Get the user object. $db->setQuery($query); try { $userId = $db->loadResult(); } catch (RuntimeException $e) { $this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500); return false; } // Check for a user. if (empty($userId)) { $this->setError(JText::_('COM_USERS_INVALID_EMAIL')); return false; } // Get the user object. $user = JUser::getInstance($userId); // Make sure the user isn't blocked. if ($user->block) { $this->setError(JText::_('COM_USERS_USER_BLOCKED')); return false; } // Make sure the user isn't a Super Admin. if ($user->authorise('core.admin')) { $this->setError(JText::_('COM_USERS_REMIND_SUPERADMIN_ERROR')); return false; } // Make sure the user has not exceeded the reset limit if (!$this->checkResetLimit($user)) { $resetLimit = (int) JFactory::getApplication()->getParams()->get('reset_time'); $this->setError(JText::plural('COM_USERS_REMIND_LIMIT_ERROR_N_HOURS', $resetLimit)); return false; } // Set the confirmation token. $token = JApplicationHelper::getHash(JUserHelper::genRandomPassword()); $hashedToken = JUserHelper::hashPassword($token); $user->activation = $hashedToken; // Save the user to the database. if (!$user->save(true)) { return new JException(JText::sprintf('COM_USERS_USER_SAVE_FAILED', $user->getError()), 500); } // Assemble the password reset confirmation link. $mode = $config->get('force_ssl', 0) == 2 ? 1 : -1; $link = 'index.php?option=com_users&view=reset&layout=confirm&token=' . $token; // Put together the email template data. $data = $user->getProperties(); $data['fromname'] = $config->get('fromname'); $data['mailfrom'] = $config->get('mailfrom'); $data['sitename'] = $config->get('sitename'); $data['link_text'] = JRoute::_($link, false, $mode); $data['link_html'] = JRoute::_($link, true, $mode); $data['token'] = $token; $subject = JText::sprintf('COM_USERS_EMAIL_PASSWORD_RESET_SUBJECT', $data['sitename']); $body = JText::sprintf('COM_USERS_EMAIL_PASSWORD_RESET_BODY', $data['sitename'], $data['token'], $data['link_text']); // Send the password reset request email. $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $user->email, $subject, $body); // Check for an error. if ($return !== true) { return new JException(JText::_('COM_USERS_MAIL_FAILED'), 500); } return true; }
/** * Cleans single line inputs. * * @param string $value String to be cleaned. * * @return string Cleaned string. * * @since 11.1 */ public static function cleanLine($value) { $value = JStringPunycode::emailToPunycode($value); return trim(preg_replace('/(%0A|%0D|\\n+|\\r+)/i', '', $value)); }
/** * Send the remind username email * * @param array $data Array with the data received from the form * * @return boolean * * @since 1.6 */ public function processRemindRequest($data) { // Get the form. $form = $this->getForm(); $data['email'] = JStringPunycode::emailToPunycode($data['email']); // Check for an error. if (empty($form)) { return false; } // Validate the data. $data = $this->validate($form, $data); // Check for an error. if ($data instanceof Exception) { return false; } // Check the validation results. if ($data === false) { // Get the validation messages from the form. foreach ($form->getErrors() as $formError) { $this->setError($formError->getMessage()); } return false; } // Find the user id for the given email address. $db = $this->getDbo(); $query = $db->getQuery(true)->select('*')->from($db->quoteName('#__users'))->where($db->quoteName('email') . ' = ' . $db->quote($data['email'])); // Get the user id. $db->setQuery($query); try { $user = $db->loadObject(); } catch (RuntimeException $e) { $this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500); return false; } // Check for a user. if (empty($user)) { $this->setError(JText::_('COM_USERS_USER_NOT_FOUND')); return false; } // Make sure the user isn't blocked. if ($user->block) { $this->setError(JText::_('COM_USERS_USER_BLOCKED')); return false; } $config = JFactory::getConfig(); // Assemble the login link. $itemid = UsersHelperRoute::getLoginRoute(); $itemid = $itemid !== null ? '&Itemid=' . $itemid : ''; $link = 'index.php?option=com_users&view=login' . $itemid; $mode = $config->get('force_ssl', 0) == 2 ? 1 : -1; // Put together the email template data. $data = ArrayHelper::fromObject($user); $data['fromname'] = $config->get('fromname'); $data['mailfrom'] = $config->get('mailfrom'); $data['sitename'] = $config->get('sitename'); $data['link_text'] = JRoute::_($link, false, $mode); $data['link_html'] = JRoute::_($link, true, $mode); $subject = JText::sprintf('COM_USERS_EMAIL_USERNAME_REMINDER_SUBJECT', $data['sitename']); $body = JText::sprintf('COM_USERS_EMAIL_USERNAME_REMINDER_BODY', $data['sitename'], $data['username'], $data['link_text']); // Send the password reset request email. $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $user->email, $subject, $body); // Check for an error. if ($return !== true) { $this->setError(JText::_('COM_USERS_MAIL_FAILED'), 500); return false; } return true; }
/** * Method to start the password reset process. * * @param array $data The data expected for the form. * * @return mixed Exception | JException | boolean * * @since 1.6 */ public function processResetRequest($data) { $config = JFactory::getConfig(); // Get the form. $form = $this->getForm(); $data['email'] = JStringPunycode::emailToPunycode($data['email']); // Check for an error. if ($form instanceof Exception) { return $form; } // Filter and validate the form data. $data = $form->filter($data); $return = $form->validate($data); // Check for an error. if ($return instanceof Exception) { return $return; } // Check the validation results. if ($return === false) { // Get the validation messages from the form. foreach ($form->getErrors() as $formError) { $this->setError($formError->getMessage()); } return false; } // Find the user id for the given email address. $db = $this->getDbo(); $query = $db->getQuery(true)->select('id')->from($db->quoteName('#__users'))->where($db->quoteName('email') . ' = ' . $db->quote($data['email'])); // Get the user object. $db->setQuery($query); try { $userId = $db->loadResult(); } catch (RuntimeException $e) { $this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500); return false; } // Check for a user. if (empty($userId)) { $this->setError(JText::_('COM_USERS_INVALID_EMAIL')); return false; } // Get the user object. $user = JUser::getInstance($userId); // Make sure the user isn't blocked. if ($user->block) { $this->setError(JText::_('COM_USERS_USER_BLOCKED')); return false; } // Make sure the user isn't a Super Admin. if ($user->authorise('core.admin')) { $this->setError(JText::_('COM_USERS_REMIND_SUPERADMIN_ERROR')); return false; } // Make sure the user has not exceeded the reset limit if (!$this->checkResetLimit($user)) { $resetLimit = (int) JFactory::getApplication()->getParams()->get('reset_time'); $this->setError(JText::plural('COM_USERS_REMIND_LIMIT_ERROR_N_HOURS', $resetLimit)); return false; } // Set the confirmation token. $token = JApplicationHelper::getHash(JUserHelper::genRandomPassword()); $salt = JUserHelper::getSalt('crypt-md5'); $hashedToken = md5($token . $salt) . ':' . $salt; $user->activation = $hashedToken; // Save the user to the database. if (!$user->save(true)) { return new JException(JText::sprintf('COM_USERS_USER_SAVE_FAILED', $user->getError()), 500); } // Assemble the password reset confirmation link. $mode = $config->get('force_ssl', 0) == 2 ? 1 : -1; $itemid = UsersHelperRoute::getLoginRoute(); $itemid = $itemid !== null ? '&Itemid=' . $itemid : ''; $link = 'index.php?option=com_users&view=reset&layout=confirm&token=' . $token . $itemid; // Put together the email template data. $data = $user->getProperties(); $data['fromname'] = $config->get('fromname'); $data['mailfrom'] = $config->get('mailfrom'); $data['sitename'] = $config->get('sitename'); $data['link_text'] = JRoute::_($link, false, $mode); $data['link_html'] = JRoute::_($link, true, $mode); $data['token'] = $token; $subject = JText::sprintf('COM_USERS_EMAIL_PASSWORD_RESET_SUBJECT', $data['sitename']); /*$body = JText::sprintf( 'COM_USERS_EMAIL_PASSWORD_RESET_BODY', $data['sitename'], $data['token'], $data['link_text'] );*/ $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"><span style="font-family:Arial, Helvetica, sans-serif; font-size:14px; line-height:20px; color:#343434; font-weight:normal;">Dear <span style="color:#343434;text-transform:capitalize;">' . $data['name'] . ',</span><br /><br />We have received a request regarding the change of your password.</span> <br /><br /> <span style="font-family:Arial, Helvetica, sans-serif; font-size:14px; line-height:20px; color:#343434; font-weight:normal;">The verification code is - </span> ' . $data['token'] . ' <br /> <br /> <span style="font-family:Arial, Helvetica, sans-serif; font-size:14px; line-height:20px; color:#343434; font-weight:normal;">Please ignore this mail if you don’t want to reset your password.</span></td></tr> <tr><td height="20" align="center" valign="top"> </td></tr> <tr><td align="left" valign="top"> <span style="font-family:Arial, Helvetica, sans-serif; font-size:14px; line-height:20px; color:#343434; font-weight:normal;">Best regards,<br /> Team RAS</span> </td></tr> <tr><td height="20" align="center" valign="top"> </td></tr> </table> </td> </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 = 'Forgot Password Request'; $from = $config->get('mailfrom'); $fromname = $config->get('fromname'); $to = $user->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(); // Check for an error. if ($return !== true) { return new JException(JText::_('COM_USERS_MAIL_FAILED'), 500); } return true; }
/** * Function to punyencode utf8 mail when saving content * * @param string $text The strings to encode * * @return string The punyencoded mail * * @since 3.5 */ public function emailToPunycode($text) { $pattern = '/(("mailto:)+[\\w\\.\\-\\+]+\\@[^"?]+\\.+[^."?]+("|\\?))/'; if (preg_match_all($pattern, $text, $matches)) { foreach ($matches[0] as $match) { $match = (string) str_replace(array('?', '"'), '', $match); $text = (string) str_replace($match, JStringPunycode::emailToPunycode($match), $text); } } return $text; }
static function dataFilter($v, $maxlength = 0, $validation = 'string', $check_callable = 0) { if ($validation == '-1') { return flexicontent_html::striptagsandcut($v, $maxlength); } $v = $maxlength ? substr($v, 0, $maxlength) : $v; if ($check_callable) { if (strpos($validation, '::') !== false && is_callable(explode('::', $validation))) { return call_user_func(explode('::', $validation), $v); } elseif (function_exists($validation)) { return call_user_func($validation, $v); } // A callback function } // Do filtering if ($validation == '1') { $safeHtmlFilter = JFilterInput::getInstance(null, null, 1, 1); } else { if ($validation != '2') { $noHtmlFilter = JFilterInput::getInstance(); } } switch ($validation) { case '1': // Allow safe HTML $v = $safeHtmlFilter->clean($v, 'string'); break; case '2': // Filter according to user group Text Filters $v = JComponentHelper::filterText($v); break; case 'URL': case 'url': // This cleans some of the more dangerous characters but leaves special characters that are valid. $v = trim($noHtmlFilter->clean($v, 'HTML')); // <>" are never valid in a uri see http://www.ietf.org/rfc/rfc1738.txt. $v = str_replace(array('<', '>', '"'), '', $v); // Convert to Punycode string $v = FLEXI_J30GE ? JStringPunycode::urlToPunycode($v) : $v; break; case 'EMAIL': case 'email': // This cleans some of the more dangerous characters but leaves special characters that are valid. $v = trim($noHtmlFilter->clean($v, 'HTML')); // <>" are never valid in a email ? $v = str_replace(array('<', '>', '"'), '', $v); // Convert to Punycode string $v = FLEXI_J30GE ? JStringPunycode::emailToPunycode($v) : $v; // Check for valid email (punycode is ASCII so this should work with UTF-8 too) $email_regexp = "/^[a-zA-Z0-9.!#\$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\$/"; if (!preg_match($email_regexp, $v)) { $v = ''; } break; default: // Filter using JFilterInput $v = $noHtmlFilter->clean($v, $validation); break; } $v = trim($v); return $v; }
/** * 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; } }
/** * Send the remind username email * * @param array $data Array with the data received from the form * * @return boolean * * @since 1.6 */ public function processRemindRequest($data) { // Get the form. $form = $this->getForm(); $data['email'] = JStringPunycode::emailToPunycode($data['email']); // Check for an error. if (empty($form)) { return false; } // Validate the data. $data = $this->validate($form, $data); // Check for an error. if ($data instanceof Exception) { return false; } // Check the validation results. if ($data === false) { // Get the validation messages from the form. foreach ($form->getErrors() as $formError) { $this->setError($formError->getMessage()); } return false; } // Find the user id for the given email address. $db = $this->getDbo(); $query = $db->getQuery(true)->select('*')->from($db->quoteName('#__users'))->where($db->quoteName('email') . ' = ' . $db->quote($data['email'])); // Get the user id. $db->setQuery($query); try { $user = $db->loadObject(); } catch (RuntimeException $e) { $this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500); return false; } // Check for a user. if (empty($user)) { $this->setError(JText::_('COM_USERS_USER_NOT_FOUND')); return false; } // Make sure the user isn't blocked. if ($user->block) { $this->setError(JText::_('COM_USERS_USER_BLOCKED')); return false; } $config = JFactory::getConfig(); // Assemble the login link. $itemid = UsersHelperRoute::getLoginRoute(); $itemid = $itemid !== null ? '&Itemid=' . $itemid : ''; $link = 'index.php?option=com_users&view=login' . $itemid; $mode = $config->get('force_ssl', 0) == 2 ? 1 : -1; // Put together the email template data. $data = JArrayHelper::fromObject($user); $data['fromname'] = $config->get('fromname'); $data['mailfrom'] = $config->get('mailfrom'); $data['sitename'] = $config->get('sitename'); $data['link_text'] = JRoute::_($link, false, $mode); $data['link_html'] = JRoute::_($link, true, $mode); $subject = JText::sprintf('COM_USERS_EMAIL_USERNAME_REMINDER_SUBJECT', $data['sitename']); /* $body = JText::sprintf( 'COM_USERS_EMAIL_USERNAME_REMINDER_BODY', $data['sitename'], $data['username'], $data['link_text'] ); */ $serverurl = $_SERVER['HTTP_HOST']; ######################## Costume User name Remind Email Templates By Vishal ################## $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"><span style="font-family:Arial, Helvetica, sans-serif; font-size:14px; line-height:20px; color:#343434; font-weight:normal;">Dear <span style="color:#343434; text-transform:capitalize;">' . $data['name'] . ',</span><br /><br /> Please find your username below.</span> <br /><br /> <span style="font-family:Arial, Helvetica, sans-serif; font-size:14px; line-height:20px; color:#343434; font-weight:normal;"> <strong style="color:#f77635">Username:</strong> ' . $data['name'] . ' </span><br /> </td></tr> <tr><td height="20" align="center" valign="top"> </td></tr> <tr><td align="left" valign="top"> <span style="font-family:Arial, Helvetica, sans-serif; font-size:14px; line-height:20px; color:#343434; font-weight:normal;">Best regards,<br /> Team RAS</span> </td></tr> <tr><td height="20" align="center" valign="top"> </td></tr> </table> </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 = 'Forgot Username Request'; $from = $config->get('mailfrom'); $fromname = $config->get('fromname'); $to = $user->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(); ################################################################# // Send the password reset request email. //$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $user->email, $subject, $body); // Check for an error. if ($return !== true) { $this->setError(JText::_('COM_USERS_MAIL_FAILED'), 500); return false; } 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; }
/** * Validation and filtering * * @return boolean True if satisfactory * * @since 11.1 */ public function check() { // Set user id to null istead of 0, if needed if ($this->id === 0) { $this->id = null; } // Validate user information if (trim($this->name) == '') { $this->setError(JText::_('JLIB_DATABASE_ERROR_PLEASE_ENTER_YOUR_NAME')); return false; } if (trim($this->username) == '') { $this->setError(JText::_('JLIB_DATABASE_ERROR_PLEASE_ENTER_A_USER_NAME')); return false; } if (preg_match('#[<>"\'%;()&\\s\\\\]|\\.\\./#', $this->username) || strlen(utf8_decode($this->username)) < 2) { $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_VALID_AZ09', 2)); return false; } if (trim($this->email) == "" || !JMailHelper::isEmailAddress($this->email)) { $this->setError(JText::_('JLIB_DATABASE_ERROR_VALID_MAIL')); return false; } // Convert e-mail to punycode for storage $this->email = JStringPunycode::emailToPunycode($this->email); // Set the registration timestamp if (empty($this->registerDate) || $this->registerDate == $this->_db->getNullDate()) { $this->registerDate = JFactory::getDate()->toSql(); } // Set the lastvisitDate timestamp if (empty($this->lastvisitDate)) { $this->lastvisitDate = $this->_db->getNullDate(); } // Check for existing username $query = $this->_db->getQuery(true)->select($this->_db->quoteName('id'))->from($this->_db->quoteName('#__users'))->where($this->_db->quoteName('username') . ' = ' . $this->_db->quote($this->username))->where($this->_db->quoteName('id') . ' != ' . (int) $this->id); $this->_db->setQuery($query); $xid = (int) $this->_db->loadResult(); if ($xid && $xid != (int) $this->id) { $this->setError(JText::_('JLIB_DATABASE_ERROR_USERNAME_INUSE')); return false; } // Check for existing email $query->clear()->select($this->_db->quoteName('id'))->from($this->_db->quoteName('#__users'))->where($this->_db->quoteName('email') . ' = ' . $this->_db->quote($this->email))->where($this->_db->quoteName('id') . ' != ' . (int) $this->id); $this->_db->setQuery($query); $xid = (int) $this->_db->loadResult(); if ($xid && $xid != (int) $this->id) { $this->setError(JText::_('JLIB_DATABASE_ERROR_EMAIL_INUSE')); return false; } // Check for root_user != username $config = JFactory::getConfig(); $rootUser = $config->get('root_user'); if (!is_numeric($rootUser)) { $query->clear()->select($this->_db->quoteName('id'))->from($this->_db->quoteName('#__users'))->where($this->_db->quoteName('username') . ' = ' . $this->_db->quote($rootUser)); $this->_db->setQuery($query); $xid = (int) $this->_db->loadResult(); if ($rootUser == $this->username && (!$xid || $xid && $xid != (int) $this->id) || $xid && $xid == (int) $this->id && $rootUser != $this->username) { $this->setError(JText::_('JLIB_DATABASE_ERROR_USERNAME_CANNOT_CHANGE')); return false; } } return true; }
/** * Helper wrapper method for emailToPunycode * * @param string $email The UTF-8 e-mail to transform. * * @return string The punycode e-mail. * * @see JStringPunycode::emailToPunycode() * @since 3.4 */ public function emailToPunycode($email) { return JStringPunycode::emailToPunycode($email); }
/** * Send the message and display a notice * * @return void * * @since 1.5 */ public function send() { // Check for request forgeries JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); $session = JFactory::getSession(); $timeout = $session->get('com_mailto.formtime', 0); if ($timeout == 0 || time() - $timeout < 20) { JError::raiseNotice(500, JText::_('COM_MAILTO_EMAIL_NOT_SENT')); return $this->mailto(); } $SiteName = $app->get('sitename'); $link = MailtoHelper::validateHash($this->input->get('link', '', 'post')); // Verify that this is a local link if (!$link || !JUri::isInternal($link)) { // Non-local url... JError::raiseNotice(500, JText::_('COM_MAILTO_EMAIL_NOT_SENT')); return $this->mailto(); } // An array of email headers we do not want to allow as input $headers = array('Content-Type:', 'MIME-Version:', 'Content-Transfer-Encoding:', 'bcc:', 'cc:'); // An array of the input fields to scan for injected headers $fields = array('mailto', 'sender', 'from', 'subject'); /* * Here is the meat and potatoes of the header injection test. We * iterate over the array of form input and check for header strings. * If we find one, send an unauthorized header and die. */ foreach ($fields as $field) { foreach ($headers as $header) { if (strpos($_POST[$field], $header) !== false) { JError::raiseError(403, ''); } } } /* * Free up memory */ unset($headers, $fields); $email = $this->input->post->getString('mailto', ''); $sender = $this->input->post->getString('sender', ''); $from = $this->input->post->getString('from', ''); $subject_default = JText::sprintf('COM_MAILTO_SENT_BY', $sender); $subject = $this->input->post->getString('subject', $subject_default); // Check for a valid to address $error = false; if (!$email || !JMailHelper::isEmailAddress($email)) { $error = JText::sprintf('COM_MAILTO_EMAIL_INVALID', $email); JError::raiseWarning(0, $error); } // Check for a valid from address if (!$from || !JMailHelper::isEmailAddress($from)) { $error = JText::sprintf('COM_MAILTO_EMAIL_INVALID', $from); JError::raiseWarning(0, $error); } if ($error) { return $this->mailto(); } // Build the message to send $msg = JText::_('COM_MAILTO_EMAIL_MSG'); $link = $link; $body = sprintf($msg, $SiteName, $sender, $from, $link); // Clean the email data $subject = JMailHelper::cleanSubject($subject); $body = JMailHelper::cleanBody($body); // To send we need to use punycode. $from = JStringPunycode::emailToPunycode($from); $from = JMailHelper::cleanAddress($from); $email = JStringPunycode::emailToPunycode($email); // Send the email if (JFactory::getMailer()->sendMail($from, $sender, $email, $subject, $body) !== true) { JError::raiseNotice(500, JText::_('COM_MAILTO_EMAIL_NOT_SENT')); return $this->mailto(); } $this->input->set('view', 'sent'); $this->display(); }
/** * Tests JStringPunycode::emailToPunycode * * @return void * * @since 3.2 */ public function testEmailToPunycode() { $this->assertEquals(JStringPunycode::emailToPunycode('example@джумла-тест.рф'), 'example@xn----7sblgc4ag8bhcd.xn--p1ai', 'Tests punycode encoding a UTF8 email in Cyrillic'); $this->assertEquals(JStringPunycode::emailToPunycode('example@au-gré-de-nos-plumes.fr'), '*****@*****.**', 'Tests punycode encoding a UTF8 email in French'); }