forgotpwd.php

Go to the documentation of this file.
00001 <?php
00002 
00010 class ForgotPwd extends oxUBase
00011 {
00016     protected $_sThisTemplate = 'page/account/forgotpwd.tpl';
00017 
00022     protected $_sForgotEmail = null;
00023 
00029     protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00030 
00036     protected $_blUpdateLinkStatus = null;
00037 
00042     protected $_blBargainAction = true;
00043 
00053     public function forgotPassword()
00054     {
00055         $sEmail = oxConfig::getParameter( 'lgn_usr' );
00056         $this->_sForgotEmail = $sEmail;
00057         $oEmail = oxNew( 'oxemail' );
00058 
00059         // problems sending passwd reminder ?
00060         $iSuccess = false;
00061         if ( $sEmail ) {
00062             $iSuccess = $oEmail->sendForgotPwdEmail( $sEmail );
00063         }
00064         if ( $iSuccess !== true ) {
00065             $sError = ($iSuccess === false)? 'ERROR_MESSAGE_PASSWORD_EMAIL_INVALID' : 'MESSAGE_NOT_ABLE_TO_SEND_EMAIL';
00066             oxRegistry::get("oxUtilsView")->addErrorToDisplay($sError, false, true);
00067             $this->_sForgotEmail = false;
00068         }
00069     }
00070 
00077     public function updatePassword()
00078     {
00079         $sNewPass  = oxConfig::getParameter( 'password_new', true );
00080         $sConfPass = oxConfig::getParameter( 'password_new_confirm', true );
00081 
00082         $oUser = oxNew( 'oxuser' );
00083         if ( ( $oExcp = $oUser->checkPassword( $sNewPass, $sConfPass, true ) ) ) {
00084             switch ( $oExcp->getMessage() ) {
00085                 case 'ERROR_MESSAGE_INPUT_EMPTYPASS':
00086                 case 'ERROR_MESSAGE_PASSWORD_TOO_SHORT':
00087                     return oxRegistry::get("oxUtilsView")->addErrorToDisplay('ERROR_MESSAGE_PASSWORD_TOO_SHORT', false, true);
00088                 default:
00089                     return oxRegistry::get("oxUtilsView")->addErrorToDisplay('ERROR_MESSAGE_PASSWORD_DO_NOT_MATCH', false, true);
00090             }
00091         }
00092 
00093         // passwords are fine - updating and loggin user in
00094         if ( $oUser->loadUserByUpdateId( $this->getUpdateId() ) ) {
00095 
00096             // setting new pass ..
00097             $oUser->setPassword( $sNewPass );
00098 
00099             // resetting update pass params
00100             $oUser->setUpdateKey( true );
00101 
00102             // saving ..
00103             $oUser->save();
00104 
00105             // forcing user login
00106             oxSession::setVar( 'usr', $oUser->getId() );
00107             return 'forgotpwd?success=1';
00108         } else {
00109             // expired reminder
00110             return oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_PASSWORD_LINK_EXPIRED', false, true );
00111         }
00112     }
00113 
00119     public function updateSuccess()
00120     {
00121         return (bool) oxConfig::getParameter( 'success' );
00122     }
00123 
00129     public function showUpdateScreen()
00130     {
00131         return (bool) $this->getUpdateId();
00132     }
00133 
00139     public function getUpdateId()
00140     {
00141         return oxConfig::getParameter( 'uid' );
00142     }
00143 
00149     public function isExpiredLink()
00150     {
00151         if ( ( $sKey = $this->getUpdateId() ) ) {
00152             $blExpired = oxNew( 'oxuser' )->isExpiredUpdateId( $sKey );
00153         }
00154 
00155         return $blExpired;
00156     }
00157 
00163     public function getForgotEmail()
00164     {
00165         return $this->_sForgotEmail;
00166     }
00167 
00173     public function getBreadCrumb()
00174     {
00175         $aPaths = array();
00176         $aPath = array();
00177 
00178         $aPath['title'] = oxRegistry::getLang()->translateString( 'FORGOT_PASSWORD', oxRegistry::getLang()->getBaseLanguage(), false );
00179         $aPath['link']  = $this->getLink();
00180         $aPaths[] = $aPath;
00181 
00182         return $aPaths;
00183     }
00184 }