Example #1
0
 /**
  * Lost password action
  *
  * Allows user to initiate a password reset request.
  *
  * @return void
  */
 public function lostpasswordAction()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         return $this->getHelper('Redirector')->gotoRoute(array(), 'home');
     }
     $request = $this->getRequest();
     $form = new \Application_Form_UserLostPassword();
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $data = $form->getValues();
             try {
                 /*
                 if(null === ($user = UserService::findOneByEmail($data['email']))) {
                   throw new UserControllerException('Sorry. We have no record of that email address');
                 }
                 */
                 if (null !== ($user = UserService::findOneByUsername($data['username']))) {
                     UserService::sendPasswordResetEmail($user);
                 }
                 // Redirect user to home page
                 $this->view->success = 1;
                 //$message = 'An email containing further instructions has been sent to <code>'.$user->getEmail().'</code>.'
                 $message = 'An email containing further instructions has been sent to the email address on file.' . ' Please follow the instructions in the email to reset your password.';
                 $this->_helper->sessionMessenger($message, 'success');
                 return $this->getHelper('Redirector')->gotoRoute(array(), 'home');
             } catch (UserControllerException $e) {
                 $this->getResponse()->setHttpResponseCode(500);
                 $this->view->success = 0;
                 $this->view->messages()->addMessage($e->getMessage(), 'error');
             } catch (Exception $e) {
                 // @codeCoverageIgnoreStart
                 $this->getResponse()->setHttpResponseCode(500);
                 $this->view->success = 0;
                 $message = 'development' == APPLICATION_ENV ? $e->getMessage() : 'Application error: UCLPA001';
                 $this->view->messages()->addMessage($message, 'error');
                 Logger::err($e->getMessage());
             }
             // @codeCoverageIgnoreEnd
         } else {
             // Submitted form data is invalid
             $this->getResponse()->setHttpResponseCode(500);
             $this->view->success = 0;
         }
     }
     $this->view->form = $form;
 }
Example #2
0
 public function testSendPasswordResetEmail()
 {
     $siteDomain = 'mytestsite.tld';
     $siteName = 'MY_TEST_SITE';
     $_SERVER['HTTP_HOST'] = $siteDomain;
     Zend_Registry::set('config', array());
     Zend_Registry::set('siteName', $siteName);
     $recipient = 'root@localhost';
     $user = UserTest::createTestUser();
     $user->setEmail($recipient);
     // Real address in case we actually send mail
     $mock = new MockMailTransport();
     UserService::sendPasswordResetEmail($user, $mock);
     $subject = '[' . $siteName . '] Lost password';
     $this->assertTrue($mock->called);
     $this->assertEquals($subject, $mock->subject);
     $this->assertEquals('noreply@' . $siteDomain, $mock->from);
     $this->assertContains($recipient, $mock->recipients);
     $this->assertContains('We recently received a request to reset your password.', $mock->mail->getBodyText()->getRawContent());
     #$this->assertContains('Content-Transfer-Encoding: quoted-printable', $mock->header);
     #$this->assertContains('Content-Type: text/plain', $mock->header);
     $this->assertContains("From: {$siteName} <noreply@{$siteDomain}>", $mock->header);
     $this->assertContains("Subject: {$subject}", $mock->header);
     $this->assertContains("To: {$recipient}", $mock->header);
     #$this->assertContains('Cc: Example no. 1 for cc <*****@*****.**>', $mock->header);
 }