/** * {@inheritDoc} */ public function createService(ServiceLocatorInterface $serviceLocator) { $options = $serviceLocator->get('zfcuser_module_options'); $form = new Register(null, $options); //$form->setCaptchaElement($sm->get('zfcuser_captcha_element')); $form->setInputFilter(new RegisterFilter(new NoRecordExists(array('mapper' => $serviceLocator->get('zfcuser_user_mapper'), 'key' => 'email')), new NoRecordExists(array('mapper' => $serviceLocator->get('zfcuser_user_mapper'), 'key' => 'code')), $options)); return $form; }
public function testSetGetRegistrationOptions() { $options = $this->getMock('ZfcUser\\Options\\RegistrationOptionsInterface'); $options->expects($this->once())->method('getEnableUsername')->will($this->returnValue(false)); $options->expects($this->once())->method('getEnableDisplayName')->will($this->returnValue(false)); $options->expects($this->any())->method('getUseRegistrationFormCaptcha')->will($this->returnValue(false)); $form = new Form(null, $options); $this->assertSame($options, $form->getRegistrationOptions()); $optionsNew = $this->getMock('ZfcUser\\Options\\RegistrationOptionsInterface'); $form->setRegistrationOptions($optionsNew); $this->assertSame($optionsNew, $form->getRegistrationOptions()); }
public function testSetCaptchaElement() { $options = $this->getMock('ZfcUser\\Options\\RegistrationOptionsInterface'); $options->expects($this->once())->method('getEnableUsername')->will($this->returnValue(false)); $options->expects($this->once())->method('getEnableDisplayName')->will($this->returnValue(false)); $options->expects($this->any())->method('getUseRegistrationFormCaptcha')->will($this->returnValue(false)); $captcha = $this->getMock('\\Zend\\Form\\Element\\Captcha'); $form = new Form(null, $options); $form->setCaptchaElement($captcha); $reflection = $this->helperMakePropertyAccessable($form, 'captchaElement'); $this->assertSame($captcha, $reflection->getValue($form)); }
/** * {@inheritDoc} */ public function createService(ServiceLocatorInterface $serviceManager) { /* @var $options Options\ModuleOptions */ $options = $serviceManager->get('zfcuser_module_options'); $userMapper = $serviceManager->get('zfcuser_user_mapper'); $emailValidator = new NoRecordExists(array('mapper' => $userMapper, 'key' => 'email')); $userNameValidator = new NoRecordExists(array('mapper' => $userMapper, 'key' => 'username')); $inputFilter = new RegisterFilter($emailValidator, $userNameValidator, $options); $form = new Register(null, $options); // $form->setCaptchaElement($sm->get('zfcuser_captcha_element')); $form->setInputFilter($inputFilter); return $form; }
public function __construct(RegistrationOptionsInterface $registrationOptions) { $this->setRegistrationOptions($registrationOptions); parent::__construct(null, $registrationOptions); if (!$this->has('userId')) { $this->add(array('name' => 'userId', 'type' => 'Zend\\Form\\Element\\Hidden', 'attributes' => array('type' => 'hidden'))); } }
public function createService(ServiceLocatorInterface $formElementManager) { if ($formElementManager instanceof FormElementManager) { $sm = $formElementManager->getServiceLocator(); $fem = $formElementManager; } else { $sm = $formElementManager; $fem = $sm->get('FormElementManager'); } $options = $sm->get('zfcuser_module_options'); $form = new Form\Register(null, $options); // Inject the FormElementManager to support custom FormElements $form->getFormFactory()->setFormElementManager($fem); //$form->setCaptchaElement($sm->get('zfcuser_captcha_element')); $form->setHydrator($sm->get('zfcuser_register_form_hydrator')); $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; }
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 __construct($name = null, UserCreateOptionsInterface $createOptions, RegistrationOptionsInterface $registerOptions, $serviceManager) { $this->setCreateOptions($createOptions); $this->setServiceManager($serviceManager); parent::__construct($name, $registerOptions); if ($createOptions->getCreateUserAutoPassword()) { $this->remove('password'); $this->remove('passwordVerify'); } foreach ($this->getCreateOptions()->getCreateFormElements() as $name => $element) { // avoid adding fields twice (e.g. email) // if ($this->get($element)) continue; $this->add(array('name' => $element, 'options' => array('label' => $name), 'attributes' => array('type' => 'text'))); } $this->get('submit')->setAttribute('label', 'Create'); }
public function __construct(EntityManager $em, $name = null, RegistrationOptionsInterface $options) { $this->setUseInputFilterDefaults(false); // remove zf2 default validators parent::__construct($name, $options); $this->em = $em; // $this->get('userId') // ->setName('user_id'); $this->add(array('name' => 'id', 'attributes' => array('type' => 'hidden'))); $this->get('email')->setLabel('Email Address')->setAttributes(array('placeholder' => 'We will be sending your login details here', 'class' => 'form-control', 'id' => 'email')); $this->get('username')->setAttributes(array('placeholder' => 'Username (this can be changed later)', 'class' => 'form-control', 'id' => 'username')); $this->get('password')->setAttributes(array('placeholder' => 'Minimum of 6 characters', 'class' => 'form-control', 'id' => 'password')); $this->get('passwordVerify')->setAttributes(array('placeholder' => 'Must match the password', 'class' => 'form-control', 'id' => 'passwordVerify')); $this->get('submit')->setName('install')->setLabel('Install')->setAttributes(array('class' => 'btn btn-primary btn-block', 'id' => 'install')); $this->add(array('name' => 'firstname', 'options' => array('label' => 'First Name'), 'attributes' => array('type' => 'text', 'placeholder' => 'John', 'class' => 'form-control', 'id' => 'firstname', 'autofocus' => 'autofocus')))->add(array('name' => 'lastname', 'options' => array('label' => 'Last Name'), 'attributes' => array('type' => 'text', 'placeholder' => 'Doe', 'class' => 'form-control', 'id' => 'lastname')))->add(array('type' => 'DoctrineModule\\Form\\Element\\ObjectSelect', 'name' => 'role', 'options' => array('label' => 'Role', 'object_manager' => $this->em, 'target_class' => 'ZfMuscle\\Entity\\Role', 'property' => 'roleId', 'empty_option' => 'please select...', 'is_method' => true, 'find_method' => array('name' => 'getRoles')), 'attributes' => array('class' => 'full-width', 'data-placeholder' => 'Select User Role', 'data-init-plugin' => 'select2', 'id' => 'role'))); }
public function __construct($name = null, UserEditOptionsInterface $options, RegistrationOptionsInterface $registerOptions, $serviceManager) { $this->setUserEditOptions($options); $this->setServiceManager($serviceManager); parent::__construct($name, $registerOptions); $this->remove('captcha'); if ($this->userEditOptions->getAllowPasswordChange()) { $this->add(array('name' => 'reset_password', 'type' => 'Zend\\Form\\Element\\Checkbox', 'options' => array('label' => 'Reset password to random'))); $password = $this->get('password'); $password->setAttribute('required', false); $password->setOptions(array('label' => 'Password (only if want to change)')); $this->remove('passwordVerify'); } else { $this->remove('password')->remove('passwordVerify'); } foreach ($this->getUserEditOptions()->getEditFormElements() as $name => $element) { // avoid adding fields twice (e.g. email) // if ($this->get($element)) continue; $this->add(array('name' => $element, 'options' => array('label' => $name), 'attributes' => array('type' => 'text'))); } $this->get('submit')->setLabel('Save')->setValue('Save'); $this->add(array('name' => 'userId', 'attributes' => array('type' => 'hidden'))); }