public function setUp()
 {
     $this->controllerName = 'Sds\\IdentityModule\\Controller\\IdentityController';
     parent::setUp();
     $this->documentManager = $this->serviceManager->get('doctrine.odm.documentmanager.default');
     static::$staticDcumentManager = $this->documentManager;
     if (!static::$dbIdentityCreated) {
         //create the mock identity
         $documentManager = $this->documentManager;
         $identity = new Identity();
         $identity->setIdentityName('toby');
         $documentManager->persist($identity);
         $documentManager->flush();
         $documentManager->clear();
         static::$dbIdentityCreated = true;
     }
 }
Пример #2
0
 public static function create($documentManager)
 {
     //Create data in the db to query against
     $documentManager->getConnection()->selectDatabase('identityModuleTest');
     $identity = new Identity();
     $identity->setIdentityName('toby');
     $identity->setFirstName('Toby');
     $identity->setLastName('Awesome');
     $identity->setCredential('password1');
     $identity->setEmail('*****@*****.**');
     $documentManager->persist($identity);
     $documentManager->flush();
     $documentManager->clear();
 }
 /**
  * This completes the credential reset process.
  *
  * @param type $code
  * @param type $data
  * @return type
  */
 public function update($id, $data)
 {
     $documentManager = $this->options->getDocumentManager();
     $token = $documentManager->createQueryBuilder($this->options->getDocumentClass())->field('code')->equals($id)->field('expires')->gt(new \DateTime())->getQuery()->getSingleResult();
     if (!isset($token)) {
         throw new Exception\DocumentNotFoundException();
     }
     $identity = $documentManager->getRepository($this->options->getIdentityClass())->findOneBy(['identityName' => $token->getIdentityName()]);
     $identity->setCredential($data['credential']);
     //need to trick AccessControl to allow update even though there is no authenticated identity
     $accessControlIdentity = new Identity();
     $accessControlIdentity->addRole('forgotCredentialController');
     $serviceLocator = $this->options->getServiceLocator();
     $serviceLocator->setService('identity', $accessControlIdentity);
     $serviceLocator->get('accesscontroller')->resetRoles(true);
     $documentManager->remove($token);
     $this->flush();
     $this->response->setStatusCode(204);
     return $this->response;
 }
 public function hasRole($role)
 {
     $this->__load();
     return parent::hasRole($role);
 }