コード例 #1
0
 public function indexAction()
 {
     $userId = $this->params()->fromRoute('userId', null);
     $token = $this->params()->fromRoute('token', null);
     try {
         $this->service->proceed($userId, $token);
         return $this->redirect()->toRoute('lang/my', array('action' => 'password'));
     } catch (Exception\TokenExpirationDateExpiredException $e) {
         $this->notification()->danger('Cannot proceed, token expired');
     } catch (Exception\UserNotFoundException $e) {
         $this->notification()->danger('User cannot be found for specified token');
     } catch (\Exception $e) {
         $this->logger->crit($e);
         $this->notification()->danger('An unexpected error has occurred, please contact your system administrator');
     }
     return $this->redirect()->toRoute('lang/forgot-password');
 }
コード例 #2
0
 public function testProceed()
 {
     $tokenHash = uniqid('tokenHash');
     $expirationDate = new \DateTime();
     $expirationDate->modify('+1 hour');
     $token = new Token();
     $token->setExpirationDate($expirationDate)->setHash($tokenHash);
     $expiredToken = new Token();
     $expiredToken->setExpirationDate(new \DateTime('2014-01-01 00:00:00'));
     $expiredToken->setHash(uniqid('tokenHash'));
     $user = UserEntityProvider::createEntityWithRandomData();
     $user->getTokens()->add($token);
     $user->getTokens()->add($expiredToken);
     $userId = $user->getId();
     $this->userRepositoryMock->expects($this->once())->method('findOneBy')->with(array('id' => new \MongoId($userId), 'tokens.hash' => $tokenHash))->willReturn($user);
     $this->repositoryServiceMock->expects($this->once())->method('remove')->with($expiredToken);
     $this->authenticationServiceMock->expects($this->once())->method('getStorage')->willReturnSelf();
     $this->authenticationServiceMock->expects($this->once())->method('write')->with($user->getId());
     $this->testedObject->proceed($userId, $tokenHash);
 }