本文整理汇总了PHP中JStringPunycode::emailToPunycode方法的典型用法代码示例。如果您正苦于以下问题:PHP JStringPunycode::emailToPunycode方法的具体用法?PHP JStringPunycode::emailToPunycode怎么用?PHP JStringPunycode::emailToPunycode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JStringPunycode
的用法示例。
在下文中一共展示了JStringPunycode::emailToPunycode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: stdClass
/**
* @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;
}
示例2: _sendEmail
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;
}
示例3: test
/**
* 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;
}
示例4: store
/**
* 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);
}
示例5: comment
/**
* 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;
}
示例6: save
/**
* 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;
}
示例7: save
/**
* 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;
}
示例8: _sendEmail
/**
* 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;
}
示例9: save
/**
* 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;
}
示例10: register
/**
* 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.
//.........这里部分代码省略.........
示例11: processResetRequest
/**
* 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;
}
示例12: cleanLine
/**
* 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));
}
示例13: processRemindRequest
/**
* 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;
}
示例14: processResetRequest
/**
* 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">
//.........这里部分代码省略.........
示例15: emailToPunycode
/**
* 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;
}