Exemplo n.º 1
0
 public function resetpasswordAction()
 {
     /* @var $translate Zend_Translate */
     $translate = Zend_Registry::get('Zend_Translate');
     try {
         $frmAccount = new Acl_Form_Account();
         $this->view->frmAccount = $frmAccount;
         $frmAccount->removeElement('fullname');
         $frmAccount->removeElement('email_alternative');
         $frmAccount->removeElement('role_id');
         $frmAccount->getElement('email')->removeValidator('Db_NoRecordExists');
         $frmAccount->getElement('submit')->setLabel('ACL_SEND');
         $change = intval($this->getRequest()->getParam('change', 0));
         if ($change == 1) {
             $hashtoken = $frmAccount->createElement('textarea', 'ht');
             $hashtoken->setAttrib('cols', 10);
             $hashtoken->setAttrib('rows', 5);
             $hashtoken->setLabel('ACL_VERIFICATION_CODE');
             $hashtoken->addFilter(new Zend_Filter_StringTrim());
             $hashtoken->addFilter(new Zend_Filter_Alnum());
             $hashtoken->addValidator(new Zend_Validate_Alnum());
             $hashtoken->addValidator(new Zend_Validate_NotEmpty());
             $hashtoken->setOrder($frmAccount->getElement('email')->getOrder() + 1);
             $frmAccount->addElement($hashtoken);
             $frmAccount->getElement('password')->setLabel("ACL_NEW_PASSWORD");
             $frmAccount->setAction($this->_request->getBaseUrl() . "/changepassword");
         } else {
             $frmAccount->removeElement('password');
             $frmAccount->removeElement('password2');
             $frmAccount->setAction($this->_request->getBaseUrl() . "/resetpassword");
         }
         if ($this->getRequest()->isPost()) {
             if ($frmAccount->isValid($_POST)) {
                 $mdlAccount = new Acl_Model_Account();
                 $account = $mdlAccount->getByEmail($frmAccount->getValue('email'));
                 if ($account) {
                     if ($change == 0) {
                         $salt = hash('SHA512', md5($account->email . '.' . uniqid(rand(), TRUE)) . time() . '.' . $account->id);
                         $account->recoverpwdtoken = $salt;
                         $account->save();
                         $options = Zend_Registry::get('options');
                         $projectName = $options['resources']['layout']['projectname'];
                         $emailSupport = $options['resources']['layout']['email_support'];
                         $emailSupportName = $options['resources']['layout']['email_support_name'];
                         $serverurl = new Zend_View_Helper_ServerUrl();
                         $msg = sprintf($translate->translate("ACL_PASSWORD_RESET_REQUEST_BODY"), $projectName, $serverurl->serverUrl() . '/changepassword', $salt, $emailSupport);
                         $mail = new Zend_Mail();
                         $mail->setBodyHtml($msg);
                         $mail->setFrom($emailSupport, $emailSupportName);
                         $mail->addTo($account->email, $account->fullname);
                         $mail->setSubject($translate->translate('ACL_PASSWORD_RESET_EMAIL_SUBJECT'));
                         $mail->send();
                         $this->_helper->flashMessenger->addMessage(array('type' => 'info', 'header' => '', 'message' => $translate->translate("ACL_VALIDATION_CODE_SENT_MESSAGE")));
                         $this->_helper->redirector("changepassword", "account", "acl");
                     } else {
                         if (strcasecmp($account->recoverpwdtoken, $frmAccount->getValue('ht')) == 0) {
                             $account->password = crypt($frmAccount->getValue('password'), '$6$5000$' . $salt . '$');
                             $account->recoverpwdtoken = "";
                             $account->save();
                             $this->_helper->flashMessenger->addMessage(array('type' => 'info', 'header' => '', 'message' => $translate->translate("ACL_PASSWORD_CHANGED")));
                             $this->_helper->redirector("login", "authentication", "acl");
                         } else {
                             $account->recoverpwdtoken = "";
                             $account->save();
                             $this->_helper->flashMessenger->addMessage(array('type' => 'error', 'header' => '', 'message' => $translate->translate("ACL_VALIDATION_CODE_INVALID")));
                             $this->_helper->redirector("resetpassword", "account", "acl");
                         }
                     }
                 } else {
                     throw new Exception("");
                 }
             }
         }
     } catch (Exception $e) {
         #echo $e->getMessage();
         $this->_helper->flashMessenger->addMessage(array('type' => 'error', 'header' => '', 'message' => $translate->translate("ACL_ERROR_ON_RESET_PASSWORD")));
         $this->_helper->redirector("resetpassword", "account", "acl");
     }
     return;
 }