OXID eShop CE  4.10.6
 All Classes Namespaces Files Functions Variables Pages
forgotpwd.php
Go to the documentation of this file.
1 <?php
2 
10 class ForgotPwd extends oxUBase
11 {
12 
18  protected $_sThisTemplate = 'page/account/forgotpwd.tpl';
19 
25  protected $_sForgotEmail = null;
26 
33 
39  protected $_blUpdateLinkStatus = null;
40 
46  protected $_blBargainAction = true;
47 
55  public function forgotPassword()
56  {
57  $sEmail = oxRegistry::getConfig()->getRequestParameter('lgn_usr');
58  $this->_sForgotEmail = $sEmail;
59  $oEmail = oxNew('oxemail');
60 
61  // problems sending passwd reminder ?
62  $iSuccess = false;
63  if ($sEmail) {
64  $iSuccess = $oEmail->sendForgotPwdEmail($sEmail);
65  }
66  if ($iSuccess !== true) {
67  $sError = ($iSuccess === false) ? 'ERROR_MESSAGE_PASSWORD_EMAIL_INVALID' : 'MESSAGE_NOT_ABLE_TO_SEND_EMAIL';
68  oxRegistry::get("oxUtilsView")->addErrorToDisplay($sError, false, true);
69  $this->_sForgotEmail = false;
70  }
71  }
72 
79  public function updatePassword()
80  {
81  $sNewPass = oxRegistry::getConfig()->getRequestParameter('password_new', true);
82  $sConfPass = oxRegistry::getConfig()->getRequestParameter('password_new_confirm', true);
83 
84  $oUser = oxNew('oxuser');
85 
87  $oInputValidator = oxRegistry::get('oxInputValidator');
88  if (($oExcp = $oInputValidator->checkPassword($oUser, $sNewPass, $sConfPass, true))) {
89  return oxRegistry::get("oxUtilsView")->addErrorToDisplay($oExcp->getMessage(), false, true);
90  }
91 
92  // passwords are fine - updating and loggin user in
93  if ($oUser->loadUserByUpdateId($this->getUpdateId())) {
94 
95  // setting new pass ..
96  $oUser->setPassword($sNewPass);
97 
98  // resetting update pass params
99  $oUser->setUpdateKey(true);
100 
101  // saving ..
102  $oUser->save();
103 
104  // forcing user login
105  oxRegistry::getSession()->setVariable('usr', $oUser->getId());
106 
107  return 'forgotpwd?success=1';
108  } else {
109  // expired reminder
110  $oUtilsView = oxRegistry::get("oxUtilsView");
111 
112  return $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_PASSWORD_LINK_EXPIRED', false, true);
113  }
114  }
115 
121  public function updateSuccess()
122  {
123  return (bool) oxRegistry::getConfig()->getRequestParameter('success');
124  }
125 
131  public function showUpdateScreen()
132  {
133  return (bool) $this->getUpdateId();
134  }
135 
141  public function getUpdateId()
142  {
143  return oxRegistry::getConfig()->getRequestParameter('uid');
144  }
145 
151  public function isExpiredLink()
152  {
153  if (($sKey = $this->getUpdateId())) {
154  $blExpired = oxNew('oxuser')->isExpiredUpdateId($sKey);
155  }
156 
157  return $blExpired;
158  }
159 
165  public function getForgotEmail()
166  {
167  return $this->_sForgotEmail;
168  }
169 
175  public function getBreadCrumb()
176  {
177  $aPaths = array();
178  $aPath = array();
179 
180  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
181  $aPath['title'] = oxRegistry::getLang()->translateString('FORGOT_PASSWORD', $iBaseLanguage, false);
182  $aPath['link'] = $this->getLink();
183  $aPaths[] = $aPath;
184 
185  return $aPaths;
186  }
187 
193  public function getTitle()
194  {
195  $sTitle = 'FORGOT_PASSWORD';
196 
197  if ($this->showUpdateScreen()) {
198  $sTitle = 'NEW_PASSWORD';
199  } elseif ($this->updateSuccess()) {
200  $sTitle = 'CHANGE_PASSWORD';
201  }
202 
203  return oxRegistry::getLang()->translateString($sTitle, oxRegistry::getLang()->getBaseLanguage(), false);
204  }
205 }