forgotpwd.php

Go to the documentation of this file.
00001 <?php
00002 
00010 class ForgotPwd extends oxUBase
00011 {
00012 
00018     protected $_sThisTemplate = 'page/account/forgotpwd.tpl';
00019 
00025     protected $_sForgotEmail = null;
00026 
00032     protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00033 
00039     protected $_blUpdateLinkStatus = null;
00040 
00046     protected $_blBargainAction = true;
00047 
00055     public function forgotPassword()
00056     {
00057         $sEmail = oxRegistry::getConfig()->getRequestParameter('lgn_usr');
00058         $this->_sForgotEmail = $sEmail;
00059         $oEmail = oxNew('oxemail');
00060 
00061         // problems sending passwd reminder ?
00062         $iSuccess = false;
00063         if ($sEmail) {
00064             $iSuccess = $oEmail->sendForgotPwdEmail($sEmail);
00065         }
00066         if ($iSuccess !== true) {
00067             $sError = ($iSuccess === false) ? 'ERROR_MESSAGE_PASSWORD_EMAIL_INVALID' : 'MESSAGE_NOT_ABLE_TO_SEND_EMAIL';
00068             oxRegistry::get("oxUtilsView")->addErrorToDisplay($sError, false, true);
00069             $this->_sForgotEmail = false;
00070         }
00071     }
00072 
00079     public function updatePassword()
00080     {
00081         $sNewPass = oxRegistry::getConfig()->getRequestParameter('password_new', true);
00082         $sConfPass = oxRegistry::getConfig()->getRequestParameter('password_new_confirm', true);
00083 
00084         $oUser = oxNew('oxuser');
00085 
00087         $oInputValidator = oxRegistry::get('oxInputValidator');
00088         if (($oExcp = $oInputValidator->checkPassword($oUser, $sNewPass, $sConfPass, true))) {
00089             return oxRegistry::get("oxUtilsView")->addErrorToDisplay($oExcp->getMessage(), false, true);
00090         }
00091 
00092         // passwords are fine - updating and loggin user in
00093         if ($oUser->loadUserByUpdateId($this->getUpdateId())) {
00094 
00095             // setting new pass ..
00096             $oUser->setPassword($sNewPass);
00097 
00098             // resetting update pass params
00099             $oUser->setUpdateKey(true);
00100 
00101             // saving ..
00102             $oUser->save();
00103 
00104             // forcing user login
00105             oxRegistry::getSession()->setVariable('usr', $oUser->getId());
00106 
00107             return 'forgotpwd?success=1';
00108         } else {
00109             // expired reminder
00110             $oUtilsView = oxRegistry::get("oxUtilsView");
00111 
00112             return $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_PASSWORD_LINK_EXPIRED', false, true);
00113         }
00114     }
00115 
00121     public function updateSuccess()
00122     {
00123         return (bool) oxRegistry::getConfig()->getRequestParameter('success');
00124     }
00125 
00131     public function showUpdateScreen()
00132     {
00133         return (bool) $this->getUpdateId();
00134     }
00135 
00141     public function getUpdateId()
00142     {
00143         return oxRegistry::getConfig()->getRequestParameter('uid');
00144     }
00145 
00151     public function isExpiredLink()
00152     {
00153         if (($sKey = $this->getUpdateId())) {
00154             $blExpired = oxNew('oxuser')->isExpiredUpdateId($sKey);
00155         }
00156 
00157         return $blExpired;
00158     }
00159 
00165     public function getForgotEmail()
00166     {
00167         return $this->_sForgotEmail;
00168     }
00169 
00175     public function getBreadCrumb()
00176     {
00177         $aPaths = array();
00178         $aPath = array();
00179 
00180         $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
00181         $aPath['title'] = oxRegistry::getLang()->translateString('FORGOT_PASSWORD', $iBaseLanguage, false);
00182         $aPath['link'] = $this->getLink();
00183         $aPaths[] = $aPath;
00184 
00185         return $aPaths;
00186     }
00187 
00193     public function getTitle()
00194     {
00195         $sTitle = 'FORGOT_PASSWORD';
00196 
00197         if ($this->showUpdateScreen()) {
00198             $sTitle = 'NEW_PASSWORD';
00199         } elseif ($this->updateSuccess()) {
00200             $sTitle = 'CHANGE_PASSWORD';
00201         }
00202 
00203         return oxRegistry::getLang()->translateString($sTitle, oxRegistry::getLang()->getBaseLanguage(), false);
00204     }
00205 }