account_password.php

Go to the documentation of this file.
00001 <?php
00002 
00003 
00012 class Account_Password extends Account
00013 {
00019     protected $_sThisTemplate = 'page/account/password.tpl';
00020 
00026     protected $_blPasswordChanged = false;
00027 
00035     public function render()
00036     {
00037 
00038         parent::render();
00039 
00040         // is logged in ?
00041         $oUser = $this->getUser();
00042         if ( !$oUser ) {
00043             return $this->_sThisTemplate = $this->_sThisLoginTemplate;
00044         }
00045 
00046         return $this->_sThisTemplate;
00047 
00048     }
00049 
00055     public function changePassword()
00056     {
00057         $oUser = $this->getUser();
00058         if ( !$oUser ) {
00059             return;
00060         }
00061 
00062         $sOldPass  = oxConfig::getParameter( 'password_old', true );
00063         $sNewPass  = oxConfig::getParameter( 'password_new', true );
00064         $sConfPass = oxConfig::getParameter( 'password_new_confirm', true );
00065 
00066         if ( ( $oExcp = $oUser->checkPassword( $sNewPass, $sConfPass, true ) ) ) {
00067             switch ( $oExcp->getMessage() ) {
00068                 case 'ERROR_MESSAGE_INPUT_EMPTYPASS':
00069                 case 'ERROR_MESSAGE_PASSWORD_TOO_SHORT':
00070                     return oxRegistry::get("oxUtilsView")->addErrorToDisplay('ERROR_MESSAGE_PASSWORD_TOO_SHORT', false, true);
00071                 default:
00072                     return oxRegistry::get("oxUtilsView")->addErrorToDisplay('ERROR_MESSAGE_PASSWORD_DO_NOT_MATCH', false, true);
00073             }
00074         }
00075         
00076         if ( !$sOldPass || !$oUser->isSamePassword( $sOldPass ) ) {
00077             return oxRegistry::get("oxUtilsView")->addErrorToDisplay('ERROR_MESSAGE_CURRENT_PASSWORD_INVALID', false, true);
00078         }
00079 
00080         // testing passed - changing password
00081         $oUser->setPassword( $sNewPass );
00082         if ( $oUser->save() ) {
00083             $this->_blPasswordChanged = true;
00084             // deleting user autologin cookies.
00085             oxRegistry::get("oxUtilsServer")->deleteUserCookie( $this->getConfig()->getShopId() );
00086         }
00087     }
00088 
00094     public function isPasswordChanged()
00095     {
00096         return $this->_blPasswordChanged;
00097     }
00098 
00104     public function getBreadCrumb()
00105     {
00106         $aPaths = array();
00107         $aPath = array();
00108 
00109         $aPath['title'] = oxRegistry::getLang()->translateString( 'MY_ACCOUNT', oxRegistry::getLang()->getBaseLanguage(), false );
00110         $aPath['link']  = oxRegistry::get("oxSeoEncoder")->getStaticUrl( $this->getViewConfig()->getSelfLink() . 'cl=account' );
00111         $aPaths[] = $aPath;
00112 
00113         $aPath['title'] = oxRegistry::getLang()->translateString( 'CHANGE_PASSWORD', oxRegistry::getLang()->getBaseLanguage(), false );
00114         $aPath['link']  = $this->getLink();
00115         $aPaths[] = $aPath;
00116 
00117         return $aPaths;
00118     }
00119 }