/** * Method to login a user. * * @access public * @since 1.0 */ function remind() { // Check the request token. JRequest::checkToken('post') or jexit(JText::_('JInvalid_Token')); $app =& JFactory::getApplication(); $model =& $this->getModel('User', 'UsersModel'); $data = JRequest::getVar('jform', array(), 'post', 'array'); // Submit the username remind request. $return = $model->processRemindRequest($data); // Check for a hard error. if (JError::isError($return)) { // Get the error message to display. if ($app->getCfg('error_reporting')) { $message = $return->getMessage(); } else { $message = JText::_('USERS_REMIND_REQUEST_ERROR'); } // Get the route to the next page. $itemid = UsersHelperRoute::getRemindRoute(); $itemid = $itemid !== null ? '&Itemid=' . $itemid : ''; $route = 'index.php?option=com_users&view=remind' . $itemid; // Go back to the complete form. $this->setRedirect(JRoute::_($route, false), $message, 'error'); return false; } elseif ($return === false) { // Get the route to the next page. $itemid = UsersHelperRoute::getRemindRoute(); $itemid = $itemid !== null ? '&Itemid=' . $itemid : ''; $route = 'index.php?option=com_users&view=remind' . $itemid; // Go back to the complete form. $message = JText::sprintf('USERS_REMIND_REQUEST_FAILED', $model->getError()); $this->setRedirect(JRoute::_($route, false), $message, 'notice'); return false; } else { // Get the route to the next page. $itemid = UsersHelperRoute::getLoginRoute(); $itemid = $itemid !== null ? '&Itemid=' . $itemid : ''; $route = 'index.php?option=com_users&view=login' . $itemid; // Proceed to the login form. $message = JText::_('USERS_REMIND_REQUEST_SUCCESS'); $this->setRedirect(JRoute::_($route, false), $message); return true; } }
/** * Method to start the password reset process. * * @since 1.6 */ public function processResetRequest($data) { $config = JFactory::getConfig(); // Get the form. $form = $this->getForm(); // 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 $message) { $this->setError($message); } return false; } // Find the user id for the given email address. $db = $this->getDbo(); $query = $db->getQuery(true); $query->select('id'); $query->from($db->quoteName('#__users')); $query->where($db->quoteName('email') . ' = ' . $db->q($data['email'])); // Get the user object. $db->setQuery((string) $query); $userId = $db->loadResult(); // Check for an error. if ($db->getErrorNum()) { $this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $db->getErrorMsg()), 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 = JApplication::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' . $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']); // 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; }
/** * 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; }
/** * Method to complete the password reset process. * * @since 1.6 */ public function complete() { // Check for request forgeries JSession::checkToken('post') or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); $model = $this->getModel('Reset', 'UsersModel'); $data = $this->input->post->get('jform', array(), 'array'); // Complete the password reset request. $return = $model->processResetComplete($data); // Check for a hard error. if ($return instanceof Exception) { // Get the error message to display. if ($app->get('error_reporting')) { $message = $return->getMessage(); } else { $message = JText::_('COM_USERS_RESET_COMPLETE_ERROR'); } // Get the route to the next page. $itemid = UsersHelperRoute::getResetRoute(); $itemid = $itemid !== null ? '&Itemid=' . $itemid : ''; $route = 'index.php?option=com_users&view=reset&layout=complete' . $itemid; // Go back to the complete form. $this->setRedirect(JRoute::_($route, false), $message, 'error'); return false; } elseif ($return === false) { // Complete failed. // Get the route to the next page. $itemid = UsersHelperRoute::getResetRoute(); $itemid = $itemid !== null ? '&Itemid=' . $itemid : ''; $route = 'index.php?option=com_users&view=reset&layout=complete' . $itemid; // Go back to the complete form. $message = JText::sprintf('COM_USERS_RESET_COMPLETE_FAILED', $model->getError()); $this->setRedirect(JRoute::_($route, false), $message, 'notice'); return false; } else { // Complete succeeded. // Get the route to the next page. $itemid = UsersHelperRoute::getLoginRoute(); $itemid = $itemid !== null ? '&Itemid=' . $itemid : ''; $route = 'index.php?option=com_users&view=login' . $itemid; // Proceed to the login form. $message = JText::_('COM_USERS_RESET_COMPLETE_SUCCESS'); $this->setRedirect(JRoute::_($route, false), $message); return true; } }
/** * @since 1.6 */ public function processRemindRequest($data) { // Get the form. $form = $this->getForm(); // 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 $return; } // 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'] ); // 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; }
/** * @since 1.6 */ public function processRemindRequest($data) { // Get the form. $form = $this->getForm(); // 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 $return; } // Check the validation results. if ($data === false) { // Get the validation messages from the form. foreach ($form->getErrors() as $message) { $this->setError($message); } return false; } // Find the user id for the given email address. $db = $this->getDbo(); $query = $db->getQuery(true); $query->select('*'); $query->from($db->quoteName('#__users')); $query->where($db->quoteName('email') . ' = ' . $db->Quote($data['email'])); // Get the user id. $db->setQuery((string) $query); $users = $db->loadObjectList('id'); $usersnames = array(); // Check for an error. if ($db->getErrorNum()) { $this->setError(Lang::txt('COM_USERS_DATABASE_ERROR', $db->getErrorMsg()), 500); return false; } // Check for a user. if (count($users) < 1) { $this->setError(Lang::txt('COM_USERS_USER_NOT_FOUND')); return false; } foreach ($users as $user) { // Make sure the user isn't blocked. if ($user->block) { unset($users[$user->id]); } else { $usersnames[] = $user->username; $email = $user->email; } } // Check for a user. if (count($users) < 1) { $this->setError(Lang::txt('COM_USERS_USER_NOT_FOUND')); return false; } // 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 = array(); $data['username'] = implode(', ', $usersnames); $data['fromname'] = Config::get('fromname'); $data['mailfrom'] = Config::get('mailfrom'); $data['sitename'] = Config::get('sitename'); $data['link_text'] = Route::url($link, false, $mode); $data['link_html'] = Route::url($link, true, $mode); $subject = Lang::txt('COM_USERS_EMAIL_USERNAME_REMINDER_SUBJECT', $data['sitename']); $body = Lang::txt('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'], $email, $subject, $body); // Check for an error. if ($return !== true) { $this->setError(Lang::txt('COM_USERS_MAIL_FAILED'), 500); return false; } return true; }
public function display($tpl = null) { // Get application $application = JFactory::getApplication(); // Get document $document = JFactory::getDocument(); // Get user $user = JFactory::getUser(); // Extra class for Front-end $this->class = ' jw-backend'; // Front-end permissions check. // We need to do this here since front-end requests are not executed through /administrator/components/com_k2/k2.php if ($application->isSite()) { $this->class = ' jw-frontend'; if (!$user->authorise('core.manage', 'com_k2')) { if ($user->guest) { // If user is guest redirect him to login page require_once JPATH_SITE . '/components/com_users/helpers/route.php'; $uri = JUri::getInstance(); $url = 'index.php?option=com_users&view=login&return=' . base64_encode($uri->toString()) . '&Itemid=' . UsersHelperRoute::getLoginRoute(); $application->redirect(JRoute::_($url, false), JText::_('K2_YOU_NEED_TO_LOGIN_FIRST')); return false; } else { throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403); } } } // Set the correct metadata $document->setMetaData('viewport', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'); // Load jQuery JHtml::_('jquery.framework'); // Keep alive the session JHtml::_('behavior.keepalive'); // Load the CSS if ($application->isSite()) { $document->addScript(JURI::root(true) . '/media/k2app/assets/js/frontend.js?v=3.0.0'); $document->addStyleSheet(JURI::root(true) . '/media/k2app/assets/css/frontend.css?v=3.0.0'); } $document->addStyleSheet('//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css?v=3.0.0'); $document->addStyleSheet(JURI::root(true) . '/media/k2app/assets/css/k2.css?v=3.0.0'); // Add javascript variables $document->addScriptDeclaration(' /* K2 v3.0.0 - START */ var K2SessionToken = "' . JSession::getFormToken() . '"; var K2Editor = ' . $this->getEditor() . '; var K2SitePath = "' . JURI::root(true) . '"; var K2BasePath = "' . JURI::base(true) . '"; var K2MediaManagerLanguage = "' . $this->getMediaManagerLanguage() . '"; var K2Language = ' . $this->getLanguage() . '; /* K2 v3.0.0 - FINISH */ '); // Add DropBox drop-in $params = JComponentHelper::getParams('com_k2'); if ($dropBoxAppKey = $params->get('dropboxAppKey')) { // Load DropBox script $document->addCustomTag('<script data-app-key="' . $dropBoxAppKey . '" id="dropboxjs" src="https://www.dropbox.com/static/api/2/dropins.js"></script>'); } // Load the application $document->addCustomTag('<script data-main="' . JURI::root(true) . '/media/k2app/app/main" src="' . JURI::root(true) . '/media/k2app/vendor/require/require.js?v=3.0.0"></script>'); // Set title if (class_exists('JToolBarHelper')) { JToolBarHelper::title(JText::_('COM_K2')); } // Display parent::display($tpl); }
/** * @return string */ public function getLogoutURL() { $Itemid = UsersHelperRoute::getLoginRoute(); return JRoute::_('index.php?option=com_users&view=login' . ($Itemid ? "&Itemid={$Itemid}" : '')); }
/** * Method to login a user. * * @return boolean * * @since 1.6 */ public function remind() { // Check the request token. JSession::checkToken('post') or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); $model = $this->getModel('User', 'UsersModel'); $data = $this->input->post->get('jform', array(), 'array'); // Submit the username remind request. $return = $model->processRemindRequest($data); // Check for a hard error. if ($return instanceof Exception) { // Get the error message to display. $message = $app->get('error_reporting') ? $return->getMessage() : JText::_('COM_USERS_REMIND_REQUEST_ERROR'); // Get the route to the next page. $itemid = UsersHelperRoute::getRemindRoute(); $itemid = $itemid !== null ? '&Itemid=' . $itemid : ''; $route = 'index.php?option=com_users&view=remind' . $itemid; // Go back to the complete form. $this->setRedirect(JRoute::_($route, false), $message, 'error'); return false; } if ($return === false) { // Complete failed. // Get the route to the next page. $itemid = UsersHelperRoute::getRemindRoute(); $itemid = $itemid !== null ? '&Itemid=' . $itemid : ''; $route = 'index.php?option=com_users&view=remind' . $itemid; // Go back to the complete form. $message = JText::sprintf('COM_USERS_REMIND_REQUEST_FAILED', $model->getError()); $this->setRedirect(JRoute::_($route, false), $message, 'notice'); return false; } // Complete succeeded. // Get the route to the next page. $itemid = UsersHelperRoute::getLoginRoute(); $itemid = $itemid !== null ? '&Itemid=' . $itemid : ''; $route = 'index.php?option=com_users&view=login' . $itemid; // Proceed to the login form. $message = JText::_('COM_USERS_REMIND_REQUEST_SUCCESS'); $this->setRedirect(JRoute::_($route, false), $message); return true; }
/** * 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 function checkSiteAccess() { // Get date $date = JFactory::getDate(); $now = $date->toSql(); // State check if ($this->state < 1 || (int) $this->id < 1) { throw new Exception(JText::_('K2_NOT_FOUND'), 404); } // Get user $user = JFactory::getUser(); $viewLevels = $user->getAuthorisedViewLevels(); // Access check if (!in_array($this->access, $viewLevels)) { if ($user->guest) { // Get application $application = JFactory::getApplication(); // Get document $document = JFactory::getDocument(); // In front end HTML requests redirect the user to the login page if ($application->isSite() && $document->getType() == 'html') { require_once JPATH_SITE . '/components/com_users/helpers/route.php'; $uri = JUri::getInstance(); $url = 'index.php?option=com_users&view=login&return=' . base64_encode($uri->toString()) . '&Itemid=' . UsersHelperRoute::getLoginRoute(); $application->redirect(JRoute::_($url, false), JText::_('K2_YOU_NEED_TO_LOGIN_FIRST')); } // Return false return false; } else { throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403); } } return true; }
/** * Method to login a user. * * @since 1.6 */ public function remind() { // Check the request token. Session::checkToken('post'); $model = $this->getModel('User', 'UsersModel'); $data = Request::getVar('jform', array(), 'post', 'array'); // Submit the username remind request. $return = $model->processRemindRequest($data); // Check for a hard error. if ($return instanceof Exception) { // Get the error message to display. if (Config::get('error_reporting')) { $message = $return->getMessage(); } else { $message = Lang::txt('COM_USERS_REMIND_REQUEST_ERROR'); } // Get the route to the next page. $itemid = UsersHelperRoute::getRemindRoute(); $itemid = $itemid !== null ? '&Itemid=' . $itemid : ''; $route = 'index.php?option=com_users&view=remind' . $itemid; // Go back to the complete form. $this->setRedirect(Route::url($route, false), $message, 'error'); return false; } elseif ($return === false) { // Complete failed. // Get the route to the next page. $itemid = UsersHelperRoute::getRemindRoute(); $itemid = $itemid !== null ? '&Itemid=' . $itemid : ''; $route = 'index.php?option=com_users&view=remind' . $itemid; // Go back to the complete form. $message = Lang::txt('COM_USERS_REMIND_REQUEST_FAILED', $model->getError()); $this->setRedirect(Route::url($route, false), $message, 'notice'); return false; } else { // Complete succeeded. // Get the route to the next page. $itemid = UsersHelperRoute::getLoginRoute(); $itemid = $itemid !== null ? '&Itemid=' . $itemid : ''; $route = 'index.php?option=com_users&view=login' . $itemid; // Proceed to the login form. $message = Lang::txt('COM_USERS_REMIND_REQUEST_SUCCESS'); $this->setRedirect(Route::url($route, false), $message); return true; } }
function processRemindRequest($data) { // Get the form. $form =& $this->getRemindForm(); // Check for an error. if (JError::isError($form)) { return $form; } // Validate the data. $data = $this->validate($form, $data); // Check the validator results. if (JError::isError($data) || $data === false) { return $data; } // Find the user id for the given e-mail address. $query = new JQuery(); $query->select('*'); $query->from('`#__users`'); $query->where('`email` = ' . $this->_db->Quote($data['email'])); // Get the user id. $this->_db->setQuery((string) $query); $user = $this->_db->loadObject(); // Check for an error. if ($this->_db->getErrorNum()) { return new JException(JText::sprintf('USERS_DATABASE_ERROR', $this->_db->getErrorMsg()), 500); } // Check for a user. if (empty($user)) { $this->setError(JText::_('USERS_USER_NOT_FOUND')); return false; } // Make sure the user isn't blocked. if ($user->block) { $this->setError(JText::_('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->getValue('force_ssl', 0) == 2 ? 1 : -1; // Put together the e-mail template data. $data = JArrayHelper::fromObject($user); $data['fromname'] = $config->getValue('fromname'); $data['mailfrom'] = $config->getValue('mailfrom'); $data['sitename'] = $config->getValue('sitename'); $data['link_text'] = JRoute::_($link, false, $mode); $data['link_html'] = JRoute::_($link, true, $mode); // Load the mail template. jimport('joomla.utilities.simpletemplate'); $template = new JSimpleTemplate(); if (!$template->load('users.username.remind.request')) { return new JException(JText::_('USERS_REMIND_MAIL_TEMPLATE_NOT_FOUND'), 500); } // Push in the email template variables. $template->bind($data); // Get the email information. $toEmail = $user->email; $subject = $template->getTitle(); $message = $template->getHtml(); // Send the password reset request e-mail. $return = JUtility::sendMail($data['mailfrom'], $data['fromname'], $toEmail, $subject, $message); // Check for an error. if ($return !== true) { return new JException(JText::_('USERS_MAIL_FAILED'), 500); } return true; }
function ajaxforgot() { error_reporting(0); require_once(JPATH_SITE . '/components/com_users/helpers/route.php'); $lang = JFactory::getLanguage(); $extension = 'com_users'; $base_dir = JPATH_SITE; $language_tag = $lang->getTag(); $reload = true; $lang->load($extension, $base_dir, $language_tag, $reload); $config = JFactory::getConfig(); $db = JFactory::getDbo(); $params = JComponentHelper::getParams('com_users'); $requestData ['email']= JRequest::getVar('email'); // Find the user id for the given email address. $query = $db->getQuery(true); $query->select('id'); $query->from($db->quoteName('#__users')); $query->where($db->quoteName('email').' = '.$db->Quote($requestData ['email'])); // Get the user object. $db->setQuery((string) $query); try { $userId = $db->loadResult(); } catch (RuntimeException $e) { //$this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500); awdwallController::ajaxResponse('$error$'.JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage())); } // Check for a user. if (empty($userId)) { awdwallController::ajaxResponse('$error$'.JText::_('COM_USERS_INVALID_EMAIL')); } // Get the user object. $user = JUser::getInstance($userId); // Make sure the user isn't blocked. if ($user->block) { awdwallController::ajaxResponse('$error$'.JText::_('COM_USERS_USER_BLOCKED')); } // Make sure the user isn't a Super Admin. if ($user->authorise('core.admin')) { awdwallController::ajaxResponse('$error$'.JText::_('COM_USERS_REMIND_SUPERADMIN_ERROR')); } // Make sure the user has not exceeded the reset limit $params = JFactory::getApplication()->getParams(); $maxCount = (int) $params->get('reset_count'); $resetHours = (int) $params->get('reset_time'); $result = true; $lastResetTime = strtotime($user->lastResetTime) ? strtotime($user->lastResetTime) : 0; $hoursSinceLastReset = (strtotime(JFactory::getDate()->toSql()) - $lastResetTime) / 3600; // If it's been long enough, start a new reset count if ($hoursSinceLastReset > $resetHours) { $user->lastResetTime = JFactory::getDate()->toSql(); $user->resetCount = 1; } // If we are under the max count, just increment the counter elseif ($user->resetCount < $maxCount) { $user->resetCount; } // At this point, we know we have exceeded the maximum resets for the time period else { $result = false; } if (!$result) { $resetLimit = (int) JFactory::getApplication()->getParams()->get('reset_time'); //$this->setError(JText::plural('COM_USERS_REMIND_LIMIT_ERROR_N_HOURS', $resetLimit)); awdwallController::ajaxResponse('$error$'.JText::plural('COM_USERS_REMIND_LIMIT_ERROR_N_HOURS', $resetLimit)); //return false; } // Set the confirmation token. $token = JApplication::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)) { awdwallController::ajaxResponse('$error$'.JText::sprintf('COM_USERS_USER_SAVE_FAILED', $user->getError())); //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'.$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'] ); // 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) { awdwallController::ajaxResponse('$error$'.JText::_('COM_USERS_MAIL_FAILED')); } awdwallController::ajaxResponse(JText::_('COM_COMAWDWALL_FORGOTPASS_SUCCESS_TEXT')); exit; }