Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /* @var $options Options\ModuleOptions */
     $options = $serviceLocator->get('zfcuser_module_options');
     /* @var $dbAdapter Db\Adapter\Adapter */
     $dbAdapter = $serviceLocator->get('zfcuser_zend_db_adapter');
     $mapper = new Mapper\User();
     $mapper->setDbAdapter($dbAdapter);
     $entityClass = $options->getUserEntityClass();
     /* @var $hydrator Hydrator\HydratorInterface */
     $hydrator = $serviceLocator->get('zfcuser_user_hydrator');
     $mapper->setEntityPrototype(new $entityClass())->setHydrator($hydrator)->setTableName($options->getTableName());
     return $mapper;
 }
Exemplo n.º 2
0
 public function update($entity, $where = null, $tableName = null, HydratorInterface $hydrator = null)
 {
     if (!$where) {
         $where = 'user_id = ' . $entity->getId();
     }
     return parent::update($entity, $where, $tableName, $hydrator);
 }
Exemplo n.º 3
0
 public function update($entity, $where = null, $tableName = null, HydratorInterface $hydrator = null)
 {
     if (!$where) {
         $where = array('id' => $entity->getId());
     }
     return parent::update($entity, $where, $tableName, $hydrator);
 }
Exemplo n.º 4
0
 public function getServiceConfig()
 {
     return array('invokables' => array('ZfcUser\\Authentication\\Adapter\\Db' => 'ZfcUser\\Authentication\\Adapter\\Db', 'ZfcUser\\Authentication\\Storage\\Db' => 'ZfcUser\\Authentication\\Storage\\Db', 'ZfcUser\\Form\\Login' => 'ZfcUser\\Form\\Login', 'zfcuser_user_service' => 'ZfcUser\\Service\\User', 'zfcuser_register_form_hydrator' => 'Zend\\Stdlib\\Hydrator\\ClassMethods'), 'factories' => array('zfcuser_module_options' => function ($sm) {
         $config = $sm->get('Config');
         return new Options\ModuleOptions(isset($config['zfcuser']) ? $config['zfcuser'] : array());
     }, 'zfcuser_auth_service' => function ($sm) {
         return new \Zend\Authentication\AuthenticationService($sm->get('ZfcUser\\Authentication\\Storage\\Db'), $sm->get('ZfcUser\\Authentication\\Adapter\\AdapterChain'));
     }, 'ZfcUser\\Authentication\\Adapter\\AdapterChain' => 'ZfcUser\\Authentication\\Adapter\\AdapterChainServiceFactory', 'zfcuser_login_form' => function ($sm) {
         $options = $sm->get('zfcuser_module_options');
         $form = new Form\Login(null, $options);
         $form->setInputFilter(new Form\LoginFilter($options));
         return $form;
     }, 'zfcuser_register_form' => function ($sm) {
         $options = $sm->get('zfcuser_module_options');
         $form = new Form\Register(null, $options);
         //$form->setCaptchaElement($sm->get('zfcuser_captcha_element'));
         $form->setInputFilter(new Form\RegisterFilter(new Validator\NoRecordExists(array('mapper' => $sm->get('zfcuser_user_mapper'), 'key' => 'email')), new Validator\NoRecordExists(array('mapper' => $sm->get('zfcuser_user_mapper'), 'key' => 'username')), $options));
         return $form;
     }, 'zfcuser_change_password_form' => function ($sm) {
         $options = $sm->get('zfcuser_module_options');
         $form = new Form\ChangePassword(null, $sm->get('zfcuser_module_options'));
         $form->setInputFilter(new Form\ChangePasswordFilter($options));
         return $form;
     }, 'zfcuser_change_email_form' => function ($sm) {
         $options = $sm->get('zfcuser_module_options');
         $form = new Form\ChangeEmail(null, $options);
         $form->setInputFilter(new Form\ChangeEmailFilter($options, new Validator\NoRecordExists(array('mapper' => $sm->get('zfcuser_user_mapper'), 'key' => 'email'))));
         return $form;
     }, 'zfcuser_user_hydrator' => function ($sm) {
         $hydrator = new \Zend\Stdlib\Hydrator\ClassMethods();
         return $hydrator;
     }, 'zfcuser_user_mapper' => function ($sm) {
         $options = $sm->get('zfcuser_module_options');
         $mapper = new Mapper\User();
         $mapper->setDbAdapter($sm->get('zfcuser_zend_db_adapter'));
         $entityClass = $options->getUserEntityClass();
         $mapper->setEntityPrototype(new $entityClass());
         $mapper->setHydrator(new Mapper\UserHydrator());
         $mapper->setTableName($options->getTableName());
         return $mapper;
     }));
 }
 public function testValidLogin()
 {
     $request = new Request();
     $response = new Response();
     $serieTokenInCookie = new SerieToken(1, 'abc', 'def');
     $newSerie = new SerieToken(1, 'abc', 'ghi');
     // Assume valid user
     $this->userMapper->expects($this->once())->method('findById')->will($this->returnValue($this->getMock('ZfcUser\\Entity\\UserInterface')));
     // Request contains cookie
     $this->cookieService->expects($this->once())->method('read')->with($request, $response)->will($this->returnValue($serieTokenInCookie));
     // Response contains updated cookie
     $this->cookieService->expects($this->once())->method('writeSerie')->with($response, $newSerie);
     $newSerie->setExpiresAt(new \DateTime('+3 days'));
     $this->rememberMeService->expects($this->once())->method('getNextInSerie')->with($serieTokenInCookie)->will($this->returnValue($newSerie));
     $this->authService->expects($this->once())->method('authenticate');
     $eventManager = $this->getMock('Zend\\EventManager\\EventManagerInterface');
     $this->service->setEventManager($eventManager);
     $eventManager->expects($this->once())->method('trigger')->with('login', $this->service, ['token' => $newSerie]);
     $this->service->loginFrom($request, $response);
 }
 /**
  * {@inheritDoc}
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $options = $serviceLocator->get('zfcuser_module_options');
     $mapper = new UserMapper();
     $mapper->setDbAdapter($serviceLocator->get('zfcuser_zend_db_adapter'));
     $entityClass = $options->getUserEntityClass();
     $mapper->setEntityPrototype(new $entityClass());
     $mapper->setHydrator($serviceLocator->get('zfcuser_user_hydrator'));
     $mapper->setTableName($options->getTableName());
     return $mapper;
 }
Exemplo n.º 7
0
 public function testInsertUpdateDelete()
 {
     $baseEntity = new Entity();
     $baseEntity->setEmail('*****@*****.**');
     $baseEntity->setUsername('zfc-user-foo');
     $baseEntity->setPassword('zfc-user-foo');
     /* @var $entityEqual Entity */
     /* @var $dbAdapter Adapter */
     foreach ($this->realAdapter as $diver => $dbAdapter) {
         if ($dbAdapter === false) {
             continue;
         }
         $this->mapper->setDbAdapter($dbAdapter);
         // insert
         $entity = clone $baseEntity;
         $result = $this->mapper->insert($entity);
         $this->assertNotNull($entity->getId());
         $this->assertGreaterThanOrEqual(1, $entity->getId());
         $entityEqual = $this->mapper->findById($entity->getId());
         $this->assertEquals($entity, $entityEqual);
         // update
         $entity->setUsername($entity->getUsername() . '-' . $diver);
         $entity->setEmail($entity->getUsername() . '@github.com');
         $result = $this->mapper->update($entity);
         $entityEqual = $this->mapper->findById($entity->getId());
         $this->assertNotEquals($baseEntity->getUsername(), $entityEqual->getUsername());
         $this->assertNotEquals($baseEntity->getEmail(), $entityEqual->getEmail());
         $this->assertEquals($entity->getUsername(), $entityEqual->getUsername());
         $this->assertEquals($entity->getEmail(), $entityEqual->getEmail());
         /**
         *
         * @todo delete is currently protected
         
                     // delete
                     $result = $this->mapper->delete($entity->getId());
         
                     $this->assertNotEquals($baseEntity->getEmail(), $entityEqual->getEmail());
                     $this->assertEquals($entity->getEmail(), $entityEqual->getEmail());
         */
     }
     if (!isset($result)) {
         $this->markTestSkipped("Without real database we dont can test insert, update and delete");
     }
 }