Пример #1
0
 public static function sendResetMail($oUser, $bShowUserName = false, $sLinkBase = null, $bForceReset = false)
 {
     UserPeer::ignoreRights(true);
     $oUser->setPasswordRecoverHint(PasswordHash::generateHint());
     $oUser->save();
     $oEmailTemplate = new Template('e_mail_pw_recover', array(DIRNAME_TEMPLATES, 'login'));
     $oEmailTemplate->replaceIdentifier('full_name', $oUser->getFullName());
     $oEmailTemplate->replaceIdentifier('first_name', $oUser->getFirstName());
     $oEmailTemplate->replaceIdentifier('last_name', $oUser->getLastName());
     $oEmailTemplate->replaceIdentifier('username', $oUser->getUsername());
     if ($bShowUserName) {
         $oEmailTemplate->replaceIdentifier('username_info', TranslationPeer::getString('wns.login.password_reset.your_username') . ': ' . $oUser->getUsername());
     }
     $sInfoTextKey = 'wns.login.password_recover_email_text2';
     if ($bForceReset) {
         $sInfoTextKey = 'wns.login.password_recover_email_text2_force';
     }
     $oEmailTemplate->replaceIdentifier('ignore_or_reset_info', TranslationPeer::getString($sInfoTextKey));
     if ($sLinkBase === null) {
         if (Manager::$CURRENT_MANAGER instanceof FrontendManager) {
             // We’re most likely on a login page: link to self should be ok
             $sLinkBase = LinkUtil::linkToSelf(null, null, true);
         } else {
             // Use the login manager
             $sLinkBase = LinkUtil::link(array(), 'LoginManager');
         }
     }
     $aParams = array('recover_hint' => md5($oUser->getPasswordRecoverHint()), 'recover_username' => $oUser->getUsername());
     if (Session::getSession()->hasAttribute('login_referrer')) {
         $aParams['recover_referrer'] = Session::getSession()->getAttribute('login_referrer');
     }
     $sLink = "http://" . $_SERVER['HTTP_HOST'] . $sLinkBase . LinkUtil::prepareLinkParameters($aParams);
     $oEmailTemplate->replaceIdentifier('new_pw_url', $sLink);
     $oEmail = new EMail(TranslationPeer::getString('wns.login.password_recover_email_subject'), $oEmailTemplate);
     $sSenderAddress = LinkUtil::getDomainHolderEmail('cms');
     $oEmail->setSender(Settings::getSetting('domain_holder', 'name', 'rapila on ' . $_SERVER['HTTP_HOST']), $sSenderAddress);
     $oEmail->addRecipient($oUser->getEmail(), $oUser->getFullName());
     $oEmail->send();
 }