Ejemplo n.º 1
0
 public function forgotpasswordAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         try {
             if (empty($data['email'])) {
                 throw new Exception($this->_('Please enter your email address'));
             }
             $admin = new Admin_Model_Admin();
             $admin->findByEmail($data['email']);
             if (!$admin->getId()) {
                 throw new Exception($this->_("This email address does not exist"));
             }
             $password = Core_Model_Lib_String::generate(8);
             $admin->setPassword($password)->save();
             $sender = System_Model_Config::getValueFor("support_email");
             $support_name = System_Model_Config::getValueFor("support_name");
             $layout = $this->getLayout()->loadEmail('admin', 'forgot_password');
             $subject = $this->_('%s - Your new password', $support_name);
             $layout->getPartial('content_email')->setPassword($password);
             $content = $layout->render();
             $mail = new Zend_Mail('UTF-8');
             $mail->setBodyHtml($content);
             $mail->setFrom($sender, $support_name);
             $mail->addTo($admin->getEmail(), $admin->getName());
             $mail->setSubject($subject);
             $mail->send();
             $data = array("success" => 1);
         } catch (Exception $e) {
             $data = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
Ejemplo n.º 2
0
 public function forgotpasswordpostAction()
 {
     if ($datas = $this->getRequest()->getPost() and !$this->getSession()->isLoggedIn('admin') and !$this->getSession()->isLoggedIn('pos')) {
         try {
             if (empty($datas['email'])) {
                 throw new Exception($this->_('Please enter your email address'));
             }
             $admin = new Admin_Model_Admin();
             $admin->findByEmail($datas['email']);
             if (!$admin->getId()) {
                 throw new Exception($this->_("Your email address does not exist"));
             }
             $password = Core_Model_Lib_String::generate(8);
             $admin->setPassword($password)->save();
             $sender = System_Model_Config::getValueFor("support_email");
             $support_name = System_Model_Config::getValueFor("support_name");
             $layout = $this->getLayout()->loadEmail('admin', 'forgot_password');
             $subject = $this->_('%s - Your new password', $support_name);
             $layout->getPartial('content_email')->setPassword($password);
             $content = $layout->render();
             $mail = new Zend_Mail('UTF-8');
             $mail->setBodyHtml($content);
             $mail->setFrom($sender, $support_name);
             $mail->addTo($admin->getEmail(), $admin->getName());
             $mail->setSubject($subject);
             $mail->send();
             $this->getSession()->addSuccess($this->_('Your new password has been sent to the entered email address'));
         } catch (Exception $e) {
             $this->getSession()->addError($e->getMessage());
         }
     }
     $this->_redirect('/');
     return $this;
 }