Example #1
0
 /**
  *  forgot-password action test
  */
 public function testForgotPasswordAction()
 {
     $mailTransportMock = $this->getMockBuilder('Zend\\Mail\\Transport\\Smtp')->disableOriginalConstructor()->getMock();
     $mailTransportMock->expects($this->once())->method('send')->will($this->returnValue(null));
     $mailMessageMock = $this->getMockBuilder('Zend\\Mail\\Message')->disableOriginalConstructor()->getMock();
     $mailMessageMock->expects($this->once())->method('addTo')->will($this->returnSelf());
     $mailMessageMock->expects($this->once())->method('setSubject')->will($this->returnSelf());
     $mailMessageMock->expects($this->once())->method('setBody')->will($this->returnSelf());
     $form = new SetNewPasswordForm('forgot-password', ['serviceLocator' => $this->getApplicationServiceLocator()]);
     $data = array('email' => $this->userData['email'], 'security' => $form->get('security')->getValue());
     $this->getApplicationServiceLocator()->setAllowOverride(true);
     $this->getApplicationServiceLocator()->setService('mail.transport', $mailTransportMock);
     $this->getApplicationServiceLocator()->setService('mail.message', $mailMessageMock);
     $this->createUserWithHash($this->userData);
     $this->dispatch('/user/signup/forgot-password', 'POST', $data);
     $this->assertEquals(302, $this->getResponse()->getStatusCode());
     $this->assertRedirectTo('/');
 }
Example #2
0
 /**
  * @return \Zend\Http\Response|ViewModel
  * @throws \Exception
  */
 public function recoverPasswordAction()
 {
     if (!($confirm = $this->params('hash'))) {
         $this->flashMessenger()->addErrorMessage('Invalid code!');
         return $this->redirect()->toRoute('home');
     }
     $form = new Form\SetNewPasswordForm('set-new-password', ['serviceLocator' => $this->getServiceLocator()]);
     if ($this->getRequest()->isPost()) {
         $form->setData($this->getRequest()->getPost());
         if ($form->isValid()) {
             $userService = new \User\Service\User($this->getServiceLocator());
             $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
             /** @var \User\Entity\User $user */
             $user = $objectManager->getRepository('User\\Entity\\User')->findOneBy(array('confirm' => $confirm));
             if (!$user) {
                 throw new \Exception('Invalid confirmation code');
             }
             try {
                 $userService->changePassword($user, $form);
                 $user->setConfirm(null);
                 $objectManager->persist($user);
                 $objectManager->flush();
                 $this->flashMessenger()->addSuccessMessage('You have successfully changed your password!');
                 $criteria = Criteria::create()->where(Criteria::expr()->eq('provider', 'equals'));
                 $user->getAuths()->matching($criteria)->first()->login($this->getServiceLocator());
                 $session = new Container('location');
                 $location = $session->location;
                 if ($location) {
                     $session->getManager()->getStorage()->clear('location');
                     return $this->redirect()->toUrl($location);
                 }
                 return $this->redirect()->toRoute('home');
             } catch (\Exception $exception) {
                 throw $exception;
             }
         }
     }
     return new ViewModel(array('form' => $form));
 }
Example #3
0
File: User.php Project: zfury/cmf
 /**
  * @param SetNewPasswordForm $form
  * @return Entity\User
  * @throws \Exception
  */
 public function changePassword(\User\Entity\User $user, SetNewPasswordForm $form)
 {
     /** @var \User\Service\Auth $userAuth */
     $userAuth = $this->getServiceLocator()->get('\\User\\Service\\Auth');
     $userAuth->generateEquals($user, $form->getData()['password']);
     return $user;
 }