OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
forgotpwd.php
Go to the documentation of this file.
1 <?php
2 
10 class ForgotPwd extends oxUBase
11 {
16  protected $_sThisTemplate = 'page/account/forgotpwd.tpl';
17 
22  protected $_sForgotEmail = null;
23 
30 
36  protected $_blUpdateLinkStatus = null;
37 
42  protected $_blBargainAction = true;
43 
53  public function forgotPassword()
54  {
55  $sEmail = oxConfig::getParameter( 'lgn_usr' );
56  $this->_sForgotEmail = $sEmail;
57  $oEmail = oxNew( 'oxemail' );
58 
59  // problems sending passwd reminder ?
60  $iSuccess = false;
61  if ( $sEmail ) {
62  $iSuccess = $oEmail->sendForgotPwdEmail( $sEmail );
63  }
64  if ( $iSuccess !== true ) {
65  $sError = ($iSuccess === false)? 'ERROR_MESSAGE_PASSWORD_EMAIL_INVALID' : 'MESSAGE_NOT_ABLE_TO_SEND_EMAIL';
66  oxRegistry::get("oxUtilsView")->addErrorToDisplay($sError, false, true);
67  $this->_sForgotEmail = false;
68  }
69  }
70 
77  public function updatePassword()
78  {
79  $sNewPass = oxConfig::getParameter( 'password_new', true );
80  $sConfPass = oxConfig::getParameter( 'password_new_confirm', true );
81 
82  $oUser = oxNew( 'oxuser' );
83  if ( ( $oExcp = $oUser->checkPassword( $sNewPass, $sConfPass, true ) ) ) {
84  switch ( $oExcp->getMessage() ) {
85  case 'ERROR_MESSAGE_INPUT_EMPTYPASS':
86  case 'ERROR_MESSAGE_PASSWORD_TOO_SHORT':
87  return oxRegistry::get("oxUtilsView")->addErrorToDisplay('ERROR_MESSAGE_PASSWORD_TOO_SHORT', false, true);
88  default:
89  return oxRegistry::get("oxUtilsView")->addErrorToDisplay('ERROR_MESSAGE_PASSWORD_DO_NOT_MATCH', false, true);
90  }
91  }
92 
93  // passwords are fine - updating and loggin user in
94  if ( $oUser->loadUserByUpdateId( $this->getUpdateId() ) ) {
95 
96  // setting new pass ..
97  $oUser->setPassword( $sNewPass );
98 
99  // resetting update pass params
100  $oUser->setUpdateKey( true );
101 
102  // saving ..
103  $oUser->save();
104 
105  // forcing user login
106  oxSession::setVar( 'usr', $oUser->getId() );
107  return 'forgotpwd?success=1';
108  } else {
109  // expired reminder
110  return oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'ERROR_MESSAGE_PASSWORD_LINK_EXPIRED', false, true );
111  }
112  }
113 
119  public function updateSuccess()
120  {
121  return (bool) oxConfig::getParameter( 'success' );
122  }
123 
129  public function showUpdateScreen()
130  {
131  return (bool) $this->getUpdateId();
132  }
133 
139  public function getUpdateId()
140  {
141  return oxConfig::getParameter( 'uid' );
142  }
143 
149  public function isExpiredLink()
150  {
151  if ( ( $sKey = $this->getUpdateId() ) ) {
152  $blExpired = oxNew( 'oxuser' )->isExpiredUpdateId( $sKey );
153  }
154 
155  return $blExpired;
156  }
157 
163  public function getForgotEmail()
164  {
165  return $this->_sForgotEmail;
166  }
167 
173  public function getBreadCrumb()
174  {
175  $aPaths = array();
176  $aPath = array();
177 
178  $aPath['title'] = oxRegistry::getLang()->translateString( 'FORGOT_PASSWORD', oxRegistry::getLang()->getBaseLanguage(), false );
179  $aPath['link'] = $this->getLink();
180  $aPaths[] = $aPath;
181 
182  return $aPaths;
183  }
184 }