00001 <?php
00002
00003
00012 class Account_Password extends Account
00013 {
00014
00020 protected $_sThisTemplate = 'account_password.tpl';
00021
00027 protected $_blPasswordChanged = false;
00028
00034 protected $_blHasPassword = true;
00035
00043 public function render()
00044 {
00045 parent::render();
00046
00047
00048 $this->_aViewData['blpasswordchanged'] = $this->isPasswordChanged();
00049
00050
00051 $oUser = $this->getUser();
00052 if ( !$oUser ) {
00053 return $this->_sThisTemplate = $this->_sThisLoginTemplate;
00054 }
00055 if ( $oUser->oxuser__oxisopenid->value == 1 && strpos( $oUser->oxuser__oxpassword->value, 'openid_' ) === 0 ) {
00056 $this->_blHasPassword = false;
00057 }
00058
00059 return $this->_sThisTemplate;
00060 }
00061
00067 public function changePassword()
00068 {
00069 $oUser = $this->getUser();
00070 if ( !$oUser ) {
00071 return;
00072 }
00073
00074 $sOldPass = oxConfig::getParameter( 'password_old' );
00075 $sNewPass = oxConfig::getParameter( 'password_new' );
00076 $sConfPass = oxConfig::getParameter( 'password_new_confirm' );
00077
00078 try {
00079 $oUser->checkPassword( $sNewPass, $sConfPass, true );
00080 } catch ( Exception $oExcp ) {
00081 switch ( $oExcp->getMessage() ) {
00082 case 'EXCEPTION_INPUT_EMPTYPASS':
00083 case 'EXCEPTION_INPUT_PASSTOOSHORT':
00084 return oxUtilsView::getInstance()->addErrorToDisplay('ACCOUNT_PASSWORD_ERRPASSWORDTOSHORT', false, true);
00085 default:
00086 return oxUtilsView::getInstance()->addErrorToDisplay('ACCOUNT_PASSWORD_ERRPASSWDONOTMATCH', false, true);
00087 }
00088 }
00089
00090 if ( !$sOldPass || !$oUser->isSamePassword( $sOldPass ) ) {
00091 oxUtilsView::getInstance()->addErrorToDisplay('ACCOUNT_PASSWORD_ERRINCORRECTCURRENTPASSW', false, true, 'user');
00092 return;
00093 }
00094
00095
00096 $oUser->setPassword( $sNewPass );
00097 if ( $oUser->save() ) {
00098 $this->_blPasswordChanged = true;
00099 }
00100 }
00101
00107 public function isPasswordChanged()
00108 {
00109 return $this->_blPasswordChanged;
00110 }
00111
00117 public function hasPassword()
00118 {
00119 return $this->_blHasPassword;
00120 }
00121 }