diff --git a/README.md b/README.md index 4bfca59..f44f745 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,7 @@ can be a little slow because we are a small company with only two developers. I Requirements ------------ -* [Zend Framework 2](https://github.com/zendframework/zf2) (latest master). -* [ZfcBase](https://github.com/ZF-Commons/ZfcBase) (latest master). +* [Laminas]() (latest master). * [ZfcUser](https://github.com/ZF-Commons/ZfcUser) (latest master). * [GoalioMailService](https://github.com/goalio/GoalioMailService) (latest master). @@ -58,7 +57,6 @@ Installation return array( 'modules' => array( // ... - 'ZfcBase', 'ZfcUser', 'GoalioMailService', 'GoalioForgotPassword' @@ -71,9 +69,9 @@ Installation 3. Make sure that the MailService is configured correctly. -### Post-Install: Zend\Db +### Post-Install: Laminas\Db -1. If you do not already have a valid Zend\Db\Adapter\Adapter in your service +1. If you do not already have a valid Laminas\Db\Adapter\Adapter in your service manager configuration, put the following in `./config/autoload/database.local.php`: array( 'factories' => array( - 'Zend\Db\Adapter\Adapter' => function ($sm) use ($dbParams) { - return new Zend\Db\Adapter\Adapter(array( + 'Laminas\Db\Adapter\Adapter' => function ($sm) use ($dbParams) { + return new Laminas\Db\Adapter\Adapter(array( 'driver' => 'pdo', 'dsn' => 'mysql:dbname='.$dbParams['database'].';host='.$dbParams['hostname'], 'database' => $dbParams['database'], @@ -126,7 +124,7 @@ The following options are available: - **reset_expire** - Integer value in seconds when the login cookie should expire. Default is `86400` (24 hours). - **email_transport** - String value which transport class to use. - Default is `Zend\Mail\Transport\Sendmail`. + Default is `Laminas\Mail\Transport\Sendmail`. - **reset_email_subject_line** - String value which transport class to use. Default is `You requested to reset your password`. - **email_from_address** - Array diff --git a/composer.json b/composer.json index 23d9148..d920cb9 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,15 @@ "zfcuser" ], "homepage": "https://github.com/goalio/GoalioForgotPassword", + "repositories": [ + { + "type": "vcs", + "url": "git@gitlab.di.lv:DIVI/divi-mail.git", + "trunk-path": "trunk", + "branches-path": "branches", + "tags-path": "tags" + } + ], "authors": [ { "name": "Philipp Dobrigkeit", @@ -16,8 +25,8 @@ } ], "require": { - "goalio/goalio-mailservice": "1.*", - "zf-commons/zfc-user": "1.*" + "divi/divi-mail": "^1.0", + "zf-commons/zfc-user": "4.*" }, "autoload": { "psr-0": { diff --git a/config/goalioforgotpassword.global.php.dist b/config/goalioforgotpassword.global.php.dist index dd86a81..cace21b 100644 --- a/config/goalioforgotpassword.global.php.dist +++ b/config/goalioforgotpassword.global.php.dist @@ -36,9 +36,9 @@ $settings = array( /** * Mail Transport to use * - * Default: 'Zend\Mail\Transport\Sendmail' + * Default: 'Laminas\Mail\Transport\Sendmail' */ - //'email_transport' => 'Zend\Mail\Transport\Sendmail', + //'email_transport' => 'Laminas\Mail\Transport\Sendmail', /** * Password Model Entity Class diff --git a/config/module.config.php b/config/module.config.php index 8d1bc49..a7c9b5a 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -9,8 +9,8 @@ ), ), 'controllers' => array( - 'invokables' => array( - 'goalioforgotpassword_forgot' => 'GoalioForgotPassword\Controller\ForgotController', + 'factories' => array( + 'goalioforgotpassword_forgot' => 'GoalioForgotPassword\Factory\Controller\ForgotControllerFactory', ), ), diff --git a/src/GoalioForgotPassword/Controller/ForgotController.php b/src/GoalioForgotPassword/Controller/ForgotController.php index 52f3213..ef42670 100644 --- a/src/GoalioForgotPassword/Controller/ForgotController.php +++ b/src/GoalioForgotPassword/Controller/ForgotController.php @@ -2,11 +2,11 @@ namespace GoalioForgotPassword\Controller; -use Zend\Form\Form; -use Zend\Mvc\Controller\AbstractActionController; -use Zend\Stdlib\ResponseInterface as Response; -use Zend\Stdlib\Parameters; -use Zend\View\Model\ViewModel; +use Laminas\Form\Form; +use Laminas\Mvc\Controller\AbstractActionController; +use Laminas\Stdlib\ResponseInterface as Response; +use Laminas\Stdlib\Parameters; +use Laminas\View\Model\ViewModel; use GoalioForgotPassword\Service\Password as PasswordService; use GoalioForgotPassword\Options\ForgotControllerOptionsInterface; @@ -54,6 +54,15 @@ class ForgotController extends AbstractActionController */ protected $zfcUserOptions; + public function __construct($passwordService, $forgotForm, $resetForm, $userService, $options, $zfcUserOptions) { + $this->passwordService = $passwordService; + $this->forgotForm = $forgotForm; + $this->resetForm = $resetForm; + $this->userService = $userService; + $this->options = $options; + $this->zfcUserOptions = $zfcUserOptions; + } + /** * User page */ @@ -160,9 +169,6 @@ public function resetAction() public function getUserService() { - if (!$this->userService) { - $this->userService = $this->getServiceLocator()->get('zfcuser_user_service'); - } return $this->userService; } @@ -174,9 +180,6 @@ public function setUserService(UserService $userService) public function getPasswordService() { - if (!$this->passwordService) { - $this->passwordService = $this->getServiceLocator()->get('goalioforgotpassword_password_service'); - } return $this->passwordService; } @@ -188,9 +191,6 @@ public function setPasswordService(PasswordService $passwordService) public function getForgotForm() { - if (!$this->forgotForm) { - $this->setForgotForm($this->getServiceLocator()->get('goalioforgotpassword_forgot_form')); - } return $this->forgotForm; } @@ -201,9 +201,6 @@ public function setForgotForm(Form $forgotForm) public function getResetForm() { - if (!$this->resetForm) { - $this->setResetForm($this->getServiceLocator()->get('goalioforgotpassword_reset_form')); - } return $this->resetForm; } @@ -231,17 +228,11 @@ public function setOptions(ForgotControllerOptionsInterface $options) */ public function getOptions() { - if (!$this->options instanceof ForgotControllerOptionsInterface) { - $this->setOptions($this->getServiceLocator()->get('goalioforgotpassword_module_options')); - } return $this->options; } public function getZfcUserOptions() { - if (!$this->zfcUserOptions instanceof PasswordOptionsInterface) { - $this->zfcUserOptions = $this->getServiceLocator()->get('zfcuser_module_options'); - } return $this->zfcUserOptions; } } diff --git a/src/GoalioForgotPassword/Factory/Controller/ForgotControllerFactory.php b/src/GoalioForgotPassword/Factory/Controller/ForgotControllerFactory.php new file mode 100644 index 0000000..0533de1 --- /dev/null +++ b/src/GoalioForgotPassword/Factory/Controller/ForgotControllerFactory.php @@ -0,0 +1,34 @@ +get('goalioforgotpassword_password_service'), + $container->get('goalioforgotpassword_forgot_form'), + $container->get('goalioforgotpassword_reset_form'), + $container->get('zfcuser_user_service'), + $container->get('goalioforgotpassword_module_options'), + $container->get('zfcuser_module_options') + ); + + return $controller; + } + + public function createService(ServiceLocatorInterface $serviceLocator) { + return $this->__invoke($serviceLocator,null); + } +} diff --git a/src/GoalioForgotPassword/Factory/Service/PasswordFactory.php b/src/GoalioForgotPassword/Factory/Service/PasswordFactory.php new file mode 100644 index 0000000..23cee9c --- /dev/null +++ b/src/GoalioForgotPassword/Factory/Service/PasswordFactory.php @@ -0,0 +1,32 @@ +get('goalioforgotpassword_module_options'), + $container->get('goalioforgotpassword_password_mapper'), + $container->get('zfcuser_user_mapper'), + $container->get('goaliomailservice_message'), + $container->get('zfcuser_module_options') + ); + + return $controller; + } + + public function createService(ServiceLocatorInterface $serviceLocator) { + return $this->__invoke($serviceLocator,null); + } +} diff --git a/src/GoalioForgotPassword/Form/Forgot.php b/src/GoalioForgotPassword/Form/Forgot.php index 4ffd9dd..b925c54 100644 --- a/src/GoalioForgotPassword/Form/Forgot.php +++ b/src/GoalioForgotPassword/Form/Forgot.php @@ -2,18 +2,18 @@ namespace GoalioForgotPassword\Form; -use Zend\Form\Element; -use ZfcBase\Form\ProvidesEventsForm; +use Laminas\Form\Element; +use Laminas\Form\Form; use GoalioForgotPassword\Options\ForgotOptionsInterface; -class Forgot extends ProvidesEventsForm +class Forgot extends Form { /** * @var AuthenticationOptionsInterface */ protected $forgotOptions; - public function __construct($name = null, ForgotOptionsInterface $options) + public function __construct($name, ForgotOptionsInterface $options) { $this->setForgotOptions($options); parent::__construct($name); @@ -36,7 +36,6 @@ public function __construct($name = null, ForgotOptionsInterface $options) 'priority' => -100, )); - $this->getEventManager()->trigger('init', $this); } public function setForgotOptions(ForgotOptionsInterface $forgotOptions) diff --git a/src/GoalioForgotPassword/Form/ForgotFilter.php b/src/GoalioForgotPassword/Form/ForgotFilter.php index 93067cd..e5e4f3b 100644 --- a/src/GoalioForgotPassword/Form/ForgotFilter.php +++ b/src/GoalioForgotPassword/Form/ForgotFilter.php @@ -2,7 +2,7 @@ namespace GoalioForgotPassword\Form; -use Zend\InputFilter\InputFilter; +use Laminas\InputFilter\InputFilter; use GoalioForgotPassword\Options\ForgotOptionsInterface; class ForgotFilter extends InputFilter @@ -12,6 +12,8 @@ class ForgotFilter extends InputFilter */ protected $options; + protected $emailValidator; + public function __construct( $emailValidator, ForgotOptionsInterface $options) { $this->setOptions($options); diff --git a/src/GoalioForgotPassword/Form/Reset.php b/src/GoalioForgotPassword/Form/Reset.php index 07c15e5..b2eb102 100644 --- a/src/GoalioForgotPassword/Form/Reset.php +++ b/src/GoalioForgotPassword/Form/Reset.php @@ -2,19 +2,18 @@ namespace GoalioForgotPassword\Form; -use Zend\Form\Form; -use Zend\Form\Element; -use ZfcBase\Form\ProvidesEventsForm; +use Laminas\Form\Form; +use Laminas\Form\Element; use GoalioForgotPassword\Options\ForgotOptionsInterface; -class Reset extends ProvidesEventsForm +class Reset extends Form { /** * @var ForgotOptionsInterface */ protected $forgotOptions; - public function __construct($name = null, ForgotOptionsInterface $forgotOptions) + public function __construct($name, ForgotOptionsInterface $forgotOptions) { $this->setForgotOptions($forgotOptions); parent::__construct($name); @@ -50,7 +49,6 @@ public function __construct($name = null, ForgotOptionsInterface $forgotOptions) 'priority' => -100, )); - $this->getEventManager()->trigger('init', $this); } public function setForgotOptions(ForgotOptionsInterface $forgotOptions) diff --git a/src/GoalioForgotPassword/Form/ResetFilter.php b/src/GoalioForgotPassword/Form/ResetFilter.php index 1371701..cc29412 100644 --- a/src/GoalioForgotPassword/Form/ResetFilter.php +++ b/src/GoalioForgotPassword/Form/ResetFilter.php @@ -2,13 +2,15 @@ namespace GoalioForgotPassword\Form; -use ZfcBase\InputFilter\ProvidesEventsInputFilter as InputFilter; +use Laminas\InputFilter\InputFilter; use GoalioForgotPassword\Options\ForgotOptionsInterface; class ResetFilter extends InputFilter { - public function __construct(ForgotOptionsInterface $options) + protected $passwordValidator; + public function __construct(ForgotOptionsInterface $options, $passwordValidator, $config) { + $this->passwordValidator = $passwordValidator; $this->add(array( 'name' => 'newCredential', 'required' => true, @@ -16,9 +18,10 @@ public function __construct(ForgotOptionsInterface $options) array( 'name' => 'StringLength', 'options' => array( - 'min' => 6, + 'min' => $config['minPasswordLength'], ), ), + $this->passwordValidator, ), 'filters' => array( array('name' => 'StringTrim'), @@ -32,7 +35,7 @@ public function __construct(ForgotOptionsInterface $options) array( 'name' => 'StringLength', 'options' => array( - 'min' => 6, + 'min' => $config['minPasswordLength'], ), ), array( @@ -41,12 +44,12 @@ public function __construct(ForgotOptionsInterface $options) 'token' => 'newCredential' ) ), + $this->passwordValidator, ), 'filters' => array( array('name' => 'StringTrim'), ), )); - $this->getEventManager()->trigger('init', $this); } } diff --git a/src/GoalioForgotPassword/Form/Service/ForgotFactory.php b/src/GoalioForgotPassword/Form/Service/ForgotFactory.php index dc9a716..e7fd301 100644 --- a/src/GoalioForgotPassword/Form/Service/ForgotFactory.php +++ b/src/GoalioForgotPassword/Form/Service/ForgotFactory.php @@ -3,24 +3,28 @@ use GoalioForgotPassword\Form\Forgot; use GoalioForgotPassword\Form\ForgotFilter; -use Zend\ServiceManager\ServiceLocatorInterface; -use Zend\ServiceManager\FactoryInterface; +use Laminas\ServiceManager\ServiceLocatorInterface; +use Laminas\ServiceManager\FactoryInterface; class ForgotFactory implements FactoryInterface { - public function createService(ServiceLocatorInterface $serviceLocator) { - $options = $serviceLocator->get('goalioforgotpassword_module_options'); + public function __invoke(\Interop\Container\ContainerInterface $container, $requestedName, array $options = NULL) { + $options = $container->get('goalioforgotpassword_module_options'); $form = new Forgot(null, $options); $validator = new \ZfcUser\Validator\RecordExists(array( - 'mapper' => $serviceLocator->get('zfcuser_user_mapper'), + 'mapper' => $container->get('zfcuser_user_mapper'), 'key' => 'email' )); - $translator = $serviceLocator->get('Translator'); + $translator = $container->get('MvcTranslator'); $validator->setMessage($translator->translate('The email address you entered was not found.')); $form->setInputFilter(new ForgotFilter($validator,$options)); return $form; } -} \ No newline at end of file + public function createService(ServiceLocatorInterface $serviceLocator) { + return $this->__invoke($serviceLocator,null); + } + +} diff --git a/src/GoalioForgotPassword/Form/Service/ResetFactory.php b/src/GoalioForgotPassword/Form/Service/ResetFactory.php index c4830b0..df21c3b 100644 --- a/src/GoalioForgotPassword/Form/Service/ResetFactory.php +++ b/src/GoalioForgotPassword/Form/Service/ResetFactory.php @@ -1,18 +1,45 @@ get('goalioforgotpassword_module_options'); + public function __invoke(\Interop\Container\ContainerInterface $container, $requestedName, array $options = NULL) { + $options = $container->get('goalioforgotpassword_module_options'); + $config = $container->get('config'); $form = new Reset(null, $options); - $form->setInputFilter(new ResetFilter($options)); + + $additionalConfig = $config['zfcuser']; + $siteConfigService = null; + + $configForFilter = []; + $configForFilter['minPasswordLength'] = 6; + if(isset($config['zfcuser']['minPasswordLength'])){ + $configForFilter['minPasswordLength'] = $config['zfcuser']['minPasswordLength']; + } + + if ($container->has(SiteConfigService::class)) { + $additionalConfig = $container->get(SiteConfigService::class); + $configForFilter['minPasswordLength'] = $additionalConfig->get('minPasswordLength'); + } + $form->setInputFilter(new ResetFilter($options, + new PasswordIsValid( + $container->get('zfcuser_module_options'), + $additionalConfig + ), + $configForFilter, + )); return $form; } + public function createService(ServiceLocatorInterface $serviceLocator) { + return $this->__invoke($serviceLocator,null); + } + } diff --git a/src/GoalioForgotPassword/Mapper/AbstractDbMapper.php b/src/GoalioForgotPassword/Mapper/AbstractDbMapper.php new file mode 100644 index 0000000..66351ed --- /dev/null +++ b/src/GoalioForgotPassword/Mapper/AbstractDbMapper.php @@ -0,0 +1,339 @@ +isInitialized) { + return; + } + + if (!$this->dbAdapter instanceof Adapter) { + throw new \Exception('No db adapter present'); + } + + if (!$this->hydrator instanceof HydratorInterface) { + $this->hydrator = new ClassMethods; + } + + if (!is_object($this->entityPrototype)) { + throw new \Exception('No entity prototype set'); + } + + $this->isInitialized = true; + } + + /** + * @param string|null $table + * @return Select + */ + protected function getSelect($table = null) + { + $this->initialize(); + return $this->getSlaveSql()->select($table ?: $this->getTableName()); + } + + /** + * @param Select $select + * @param object|null $entityPrototype + * @param HydratorInterface|null $hydrator + * @return HydratingResultSet + */ + protected function select(Select $select, $entityPrototype = null, HydratorInterface $hydrator = null) + { + $this->initialize(); + + $stmt = $this->getSlaveSql()->prepareStatementForSqlObject($select); + + $resultSet = new HydratingResultSet($hydrator ?: $this->getHydrator(), + $entityPrototype ?: $this->getEntityPrototype()); + + $resultSet->initialize($stmt->execute()); + return $resultSet; + } + + /** + * @param object|array $entity + * @param string|TableIdentifier|null $tableName + * @param HydratorInterface|null $hydrator + * @return ResultInterface + */ + protected function insert($entity, $tableName = null, HydratorInterface $hydrator = null) + { + $this->initialize(); + $tableName = $tableName ?: $this->tableName; + + $sql = $this->getSql()->setTable($tableName); + $insert = $sql->insert(); + + $rowData = $this->entityToArray($entity, $hydrator); + $insert->values($rowData); + + $statement = $sql->prepareStatementForSqlObject($insert); + + return $statement->execute(); + } + + /** + * @param object|array $entity + * @param string|array|\Closure $where + * @param string|TableIdentifier|null $tableName + * @param HydratorInterface|null $hydrator + * @return ResultInterface + */ + protected function update($entity, $where, $tableName = null, HydratorInterface $hydrator = null) + { + $this->initialize(); + $tableName = $tableName ?: $this->tableName; + + $sql = $this->getSql()->setTable($tableName); + $update = $sql->update(); + + $rowData = $this->entityToArray($entity, $hydrator); + $update->set($rowData) + ->where($where); + + $statement = $sql->prepareStatementForSqlObject($update); + + return $statement->execute(); + } + + /** + * @param string|array|\Closure $where + * @param string|TableIdentifier|null $tableName + * @return ResultInterface + */ + protected function delete($where, $tableName = null) + { + $tableName = $tableName ?: $this->tableName; + + $sql = $this->getSql()->setTable($tableName); + $delete = $sql->delete(); + + $delete->where($where); + + $statement = $sql->prepareStatementForSqlObject($delete); + + return $statement->execute(); + } + + /** + * @return string + */ + protected function getTableName() + { + return $this->tableName; + } + + /** + * @return object + */ + public function getEntityPrototype() + { + return $this->entityPrototype; + } + + /** + * @param object $entityPrototype + * @return AbstractDbMapper + */ + public function setEntityPrototype($entityPrototype) + { + $this->entityPrototype = $entityPrototype; + $this->resultSetPrototype = null; + return $this; + } + + /** + * @return Adapter + */ + public function getDbAdapter() + { + return $this->dbAdapter; + } + + /** + * @param Adapter $dbAdapter + * @return AbstractDbMapper + */ + public function setDbAdapter(Adapter $dbAdapter) + { + $this->dbAdapter = $dbAdapter; + if ($dbAdapter instanceof MasterSlaveAdapterInterface) { + $this->setDbSlaveAdapter($dbAdapter->getSlaveAdapter()); + } + return $this; + } + + /** + * @return Adapter + */ + public function getDbSlaveAdapter() + { + return $this->dbSlaveAdapter ?: $this->dbAdapter; + } + + /** + * @param Adapter $dbSlaveAdapter + * @return AbstractDbMapper + */ + public function setDbSlaveAdapter(Adapter $dbSlaveAdapter) + { + $this->dbSlaveAdapter = $dbSlaveAdapter; + return $this; + } + + /** + * @return HydratorInterface + */ + public function getHydrator() + { + if (!$this->hydrator) { + $this->hydrator = new ClassMethods(false); + } + return $this->hydrator; + } + + /** + * @param HydratorInterface $hydrator + * @return AbstractDbMapper + */ + public function setHydrator(HydratorInterface $hydrator) + { + $this->hydrator = $hydrator; + $this->resultSetPrototype = null; + return $this; + } + + /** + * @return Sql + */ + protected function getSql() + { + if (!$this->sql instanceof Sql) { + $this->sql = new Sql($this->getDbAdapter()); + } + + return $this->sql; + } + + /** + * @param Sql $sql + * @return AbstractDbMapper + */ + protected function setSql(Sql $sql) + { + $this->sql = $sql; + return $this; + } + + /** + * @return Sql + */ + protected function getSlaveSql() + { + if (!$this->slaveSql instanceof Sql) { + $this->slaveSql = new Sql($this->getDbSlaveAdapter()); + } + + return $this->slaveSql; + } + + /** + * @param Sql $sql + * @return AbstractDbMapper + */ + protected function setSlaveSql(Sql $sql) + { + $this->slaveSql = $sql; + return $this; + } + + /** + * Uses the hydrator to convert the entity to an array. + * + * Use this method to ensure that you're working with an array. + * + * @param object $entity + * @param HydratorInterface|null $hydrator + * @return array + */ + protected function entityToArray($entity, HydratorInterface $hydrator = null) + { + if (is_array($entity)) { + return $entity; // cut down on duplicate code + } elseif (is_object($entity)) { + if (!$hydrator) { + $hydrator = $this->getHydrator(); + } + return $hydrator->extract($entity); + } + throw new \InvalidArgumentException('Entity passed to db mapper should be an array or object.'); + } +} diff --git a/src/GoalioForgotPassword/Mapper/Password.php b/src/GoalioForgotPassword/Mapper/Password.php index 145e13c..d7b37c0 100644 --- a/src/GoalioForgotPassword/Mapper/Password.php +++ b/src/GoalioForgotPassword/Mapper/Password.php @@ -1,9 +1,9 @@ get('goalioforgotpassword_module_options'); + public function __invoke(ContainerInterface $container, $requestedName, array $options = NULL) { + $options = $container->get('goalioforgotpassword_module_options'); $mapper = new Password(); - $mapper->setDbAdapter($serviceLocator->get('zfcuser_zend_db_adapter')); + $mapper->setDbAdapter($container->get('zfcuser_zend_db_adapter')); $entityClass = $options->getPasswordEntityClass(); $mapper->setEntityPrototype(new $entityClass); $mapper->setHydrator(new PasswordHydrator()); return $mapper; } -} \ No newline at end of file + public function createService(ServiceLocatorInterface $serviceLocator) { + return $this->__invoke($serviceLocator,null); + } + +} diff --git a/src/GoalioForgotPassword/Module.php b/src/GoalioForgotPassword/Module.php index f90ff74..cf4335e 100644 --- a/src/GoalioForgotPassword/Module.php +++ b/src/GoalioForgotPassword/Module.php @@ -1,9 +1,9 @@ array( - 'goalioforgotpassword_password_service' => 'GoalioForgotPassword\Service\Password', + ), 'factories' => array( @@ -36,6 +36,7 @@ public function getServiceConfig() { 'goalioforgotpassword_forgot_form' => 'GoalioForgotPassword\Form\Service\ForgotFactory', 'goalioforgotpassword_reset_form' => 'GoalioForgotPassword\Form\Service\ResetFactory', 'goalioforgotpassword_password_mapper' => 'GoalioForgotPassword\Mapper\Service\PasswordFactory', + 'goalioforgotpassword_password_service' => 'GoalioForgotPassword\Factory\Service\PasswordFactory', ), ); } diff --git a/src/GoalioForgotPassword/Options/ModuleOptions.php b/src/GoalioForgotPassword/Options/ModuleOptions.php index e40448a..597a31c 100644 --- a/src/GoalioForgotPassword/Options/ModuleOptions.php +++ b/src/GoalioForgotPassword/Options/ModuleOptions.php @@ -2,7 +2,7 @@ namespace GoalioForgotPassword\Options; -use Zend\Stdlib\AbstractOptions; +use Laminas\Stdlib\AbstractOptions; class ModuleOptions extends AbstractOptions implements ForgotOptionsInterface @@ -25,7 +25,7 @@ class ModuleOptions extends AbstractOptions implements /** * @var string */ - protected $emailTransport = 'Zend\Mail\Transport\Sendmail'; + protected $emailTransport = 'Laminas\Mail\Transport\Sendmail'; /** * @var string diff --git a/src/GoalioForgotPassword/Options/Service/ModuleOptionsFactory.php b/src/GoalioForgotPassword/Options/Service/ModuleOptionsFactory.php index ccb1b24..7778711 100644 --- a/src/GoalioForgotPassword/Options/Service/ModuleOptionsFactory.php +++ b/src/GoalioForgotPassword/Options/Service/ModuleOptionsFactory.php @@ -2,14 +2,18 @@ namespace GoalioForgotPassword\Options\Service; use GoalioForgotPassword\Options\ModuleOptions; -use Zend\ServiceManager\ServiceLocatorInterface; -use Zend\ServiceManager\FactoryInterface; +use Laminas\ServiceManager\ServiceLocatorInterface; +use Laminas\ServiceManager\FactoryInterface; class ModuleOptionsFactory implements FactoryInterface { - public function createService(ServiceLocatorInterface $serviceLocator) { - $config = $serviceLocator->get('Config'); + public function __invoke(\Interop\Container\ContainerInterface $container, $requestedName, array $options = NULL) { + $config = $container->get('Config'); return new ModuleOptions(isset($config['goalioforgotpassword']) ? $config['goalioforgotpassword'] : array()); } -} \ No newline at end of file + public function createService(ServiceLocatorInterface $serviceLocator) { + return $this->__invoke($serviceLocator,null); + } + +} diff --git a/src/GoalioForgotPassword/Service/Password.php b/src/GoalioForgotPassword/Service/Password.php index 05154d9..4f39196 100644 --- a/src/GoalioForgotPassword/Service/Password.php +++ b/src/GoalioForgotPassword/Service/Password.php @@ -2,25 +2,17 @@ namespace GoalioForgotPassword\Service; -use Zend\Mail\Transport\TransportInterface; - use ZfcUser\Options\PasswordOptionsInterface; use GoalioForgotPassword\Options\ForgotOptionsInterface; -use Zend\ServiceManager\ServiceManager; - -use Zend\ServiceManager\ServiceManagerAwareInterface; - use ZfcUser\Mapper\UserInterface as UserMapperInterface; use GoalioForgotPassword\Mapper\Password as PasswordMapper; -use Zend\Crypt\Password\Bcrypt; -use Zend\Form\Form; - -use ZfcBase\EventManager\EventProvider; +use Laminas\Crypt\Password\Bcrypt; +use ZfcUser\EventManager\EventProvider; -class Password extends EventProvider implements ServiceManagerAwareInterface +class Password extends EventProvider { /** * @var ModelMapper @@ -31,7 +23,16 @@ class Password extends EventProvider implements ServiceManagerAwareInterface protected $options; protected $zfcUserOptions; protected $emailRenderer; - protected $emailTransport; + protected $mailservice; + + public function __construct($options, $passwordMapper, $userMapper, $mailservice, $zfcUserOptions) + { + $this->options = $options; + $this->passwordMapper = $passwordMapper; + $this->userMapper = $userMapper; + $this->mailservice = $mailservice; + $this->zfcUserOptions = $zfcUserOptions; + } public function findByRequestKey($token) { @@ -45,8 +46,8 @@ public function findByEmail($email) public function cleanExpiredForgotRequests() { - // TODO: reset expiry time from options - return $this->getPasswordMapper()->cleanExpiredForgotRequests(); + $expireOption = $this->getOptions()->getResetExpire(); + return $this->getPasswordMapper()->cleanExpiredForgotRequests($expireOption); } public function cleanPriorForgotRequests($userId) @@ -69,7 +70,6 @@ public function sendProcessForgotRequest($userId, $email) $model->setUserId($userId); $model->setRequestTime(new \DateTime('now')); $model->generateRequestKey(); - $this->getEventManager()->trigger(__FUNCTION__, $this, array('record' => $model, 'userId' => $userId)); $this->getPasswordMapper()->persist($model); $this->sendForgotEmailMessage($email, $model); @@ -77,13 +77,14 @@ public function sendProcessForgotRequest($userId, $email) public function sendForgotEmailMessage($to, $model) { - $mailService = $this->getServiceManager()->get('goaliomailservice_message'); + $mailService = $this->mailservice; + $resetExpire = $this->getOptions()->getResetExpire(); $from = $this->getOptions()->getEmailFromAddress(); $subject = $this->getOptions()->getResetEmailSubjectLine(); $template = $this->getOptions()->getResetEmailTemplate(); - $message = $mailService->createTextMessage($from, $to, $subject, $template, array('record' => $model)); + $message = $mailService->createHtmlMessage($from, $to, $subject, $template, ['record' => $model, 'userEmail' => $to, 'resetExpire' => $resetExpire]); $mailService->send($message); } @@ -98,25 +99,14 @@ public function resetPassword($password, $user, array $data) $pass = $bcrypt->create($newPass); $user->setPassword($pass); - $this->getEventManager()->trigger(__FUNCTION__, $this, array('user' => $user)); $this->getUserMapper()->update($user); + // trigger reset password event + $this->getEventManager()->trigger(__FUNCTION__, $this, ['user' => $user]); $this->remove($password); - $this->getEventManager()->trigger(__FUNCTION__.'.post', $this, array('user' => $user)); return true; } - public function getServiceManager() - { - return $this->serviceManager; - } - - public function setServiceManager(ServiceManager $serviceManager) - { - $this->serviceManager = $serviceManager; - return $this; - } - /** * getUserMapper * @@ -124,9 +114,6 @@ public function setServiceManager(ServiceManager $serviceManager) */ public function getUserMapper() { - if (null === $this->userMapper) { - $this->userMapper = $this->getServiceManager()->get('zfcuser_user_mapper'); - } return $this->userMapper; } @@ -150,10 +137,6 @@ public function setPasswordMapper(PasswordMapper $passwordMapper) public function getPasswordMapper() { - if (null === $this->passwordMapper) { - $this->setPasswordMapper($this->getServiceManager()->get('goalioforgotpassword_password_mapper')); - } - return $this->passwordMapper; } @@ -163,26 +146,8 @@ public function setMessageRenderer(ViewRenderer $emailRenderer) return $this; } - public function getMessageTransport() - { - if (!$this->emailTransport instanceof TransportInterface) { - $this->setEmailTransport($this->getServiceManager()->get('goalioforgotpassword_email_transport')); - } - - return $this->emailTransport; - } - - public function setMessageTransport(EmailTransport $emailTransport) - { - $this->emailTransport = $emailTransport; - return $this; - } - public function getOptions() { - if (!$this->options instanceof ForgotOptionsInterface) { - $this->setOptions($this->getServiceManager()->get('goalioforgotpassword_module_options')); - } return $this->options; } @@ -194,9 +159,6 @@ public function setOptions(ForgotOptionsInterface $opt) public function getZfcUserOptions() { - if (!$this->zfcUserOptions instanceof PasswordOptionsInterface) { - $this->setZfcUserOptions($this->getServiceManager()->get('zfcuser_module_options')); - } return $this->zfcUserOptions; } diff --git a/tests/GoalioForgotPasswordTest/Util/ServiceManagerFactory.php b/tests/GoalioForgotPasswordTest/Util/ServiceManagerFactory.php index 8638b58..027d760 100644 --- a/tests/GoalioForgotPasswordTest/Util/ServiceManagerFactory.php +++ b/tests/GoalioForgotPasswordTest/Util/ServiceManagerFactory.php @@ -2,8 +2,8 @@ namespace GoalioForgotPasswordTest\Util; -use Zend\ServiceManager\ServiceManager; -use Zend\Mvc\Service\ServiceManagerConfig; +use Laminas\ServiceManager\ServiceManager; +use Laminas\Mvc\Service\ServiceManagerConfig; class ServiceManagerFactory { @@ -29,9 +29,9 @@ public static function getServiceManager() isset(static::$config['service_manager']) ? static::$config['service_manager'] : array() )); $serviceManager->setService('ApplicationConfig', static::$config); - $serviceManager->setFactory('ServiceListener', 'Zend\Mvc\Service\ServiceListenerFactory'); + $serviceManager->setFactory('ServiceListener', 'Laminas\Mvc\Service\ServiceListenerFactory'); - /** @var $moduleManager \Zend\ModuleManager\ModuleManager */ + /** @var $moduleManager \Laminas\ModuleManager\ModuleManager */ $moduleManager = $serviceManager->get('ModuleManager'); $moduleManager->loadModules(); //$serviceManager->setAllowOverride(true);