From 467940418c9376b6f64e51b07eb38921796e1807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Str=C3=B8m?= Date: Sat, 6 Aug 2016 16:23:14 +0200 Subject: [PATCH 1/5] Return error if userObject is not found --- .../Authentication/Adapter/Cookie.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/GoalioRememberMe/Authentication/Adapter/Cookie.php b/src/GoalioRememberMe/Authentication/Adapter/Cookie.php index 0aea5c3..26eca0b 100644 --- a/src/GoalioRememberMe/Authentication/Adapter/Cookie.php +++ b/src/GoalioRememberMe/Authentication/Adapter/Cookie.php @@ -77,6 +77,16 @@ public function authenticate(AuthEvent $e) $userObject = $this->getUserMapper()->findById($cookie[0]); + if(!$userObject) { + $this->getRememberMeMapper()->removeAll($cookie[0]); + $this->getRememberMeService()->removeCookie(); + $this->setSatisfied(false); + + $e->setCode(AuthenticationResult::FAILURE) + ->setMessages(array('User not found.')); + return false; + } + $this->getRememberMeService()->updateSerie($rememberMe); // Success! @@ -171,4 +181,4 @@ public function logout() } } -} \ No newline at end of file +} From 2fe37ff1b42f92ddc6d85db0fd3162fe96c0fff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Str=C3=B8m?= Date: Fri, 23 Dec 2016 23:48:23 +0100 Subject: [PATCH 2/5] remove ServiceManagerAwareInterface --- src/GoalioRememberMe/Authentication/Adapter/Cookie.php | 8 +++++++- src/GoalioRememberMe/Module.php | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/GoalioRememberMe/Authentication/Adapter/Cookie.php b/src/GoalioRememberMe/Authentication/Adapter/Cookie.php index 26eca0b..4858f59 100644 --- a/src/GoalioRememberMe/Authentication/Adapter/Cookie.php +++ b/src/GoalioRememberMe/Authentication/Adapter/Cookie.php @@ -10,7 +10,7 @@ use Zend\Stdlib\ResponseInterface as Response; use ZfcUser\Authentication\Adapter\AdapterChainEvent as AuthEvent; -class Cookie extends AbstractAdapter implements ServiceManagerAwareInterface +class Cookie extends AbstractAdapter { protected $userMapper; @@ -19,6 +19,12 @@ class Cookie extends AbstractAdapter implements ServiceManagerAwareInterface protected $serviceManager; protected $rememberMeService; + + public function __construct($serviceManager) + { + + $this->serviceManager = $serviceManager; + } public function authenticate(AuthEvent $e) { diff --git a/src/GoalioRememberMe/Module.php b/src/GoalioRememberMe/Module.php index a697a5f..4c95c39 100644 --- a/src/GoalioRememberMe/Module.php +++ b/src/GoalioRememberMe/Module.php @@ -1,6 +1,7 @@ array( - 'GoalioRememberMe\Authentication\Adapter\Cookie' => 'GoalioRememberMe\Authentication\Adapter\Cookie', 'GoalioRememberMe\Form\Login' => 'GoalioRememberMe\Form\Login', 'goaliorememberme_rememberme_service' => 'GoalioRememberMe\Service\RememberMe', ), 'factories' => array( + 'GoalioRememberMe\Authentication\Adapter\Cookie' => function ($sm) { + return new Cookie($sm); + }, + 'goaliorememberme_module_options' => function ($sm) { $config = $sm->get('Config'); return new Options\ModuleOptions(isset($config['goaliorememberme']) ? $config['goaliorememberme'] : array()); From 387882ccf592efbf9f2ee3bd01bb81ff8a412b18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Str=C3=B8m?= Date: Sat, 24 Dec 2016 09:56:50 +0100 Subject: [PATCH 3/5] Use servicemanager directly --- src/GoalioRememberMe/Authentication/Adapter/Cookie.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/GoalioRememberMe/Authentication/Adapter/Cookie.php b/src/GoalioRememberMe/Authentication/Adapter/Cookie.php index 4858f59..ca8976c 100644 --- a/src/GoalioRememberMe/Authentication/Adapter/Cookie.php +++ b/src/GoalioRememberMe/Authentication/Adapter/Cookie.php @@ -138,7 +138,7 @@ public function setRememberMeMapper($rememberMeMapper) public function getRememberMeMapper() { if (null === $this->rememberMeMapper) { - $this->rememberMeMapper = $this->getServiceManager()->get('goaliorememberme_rememberme_mapper'); + $this->rememberMeMapper = $this->serviceManager->get('goaliorememberme_rememberme_mapper'); } return $this->rememberMeMapper; } @@ -151,7 +151,7 @@ public function setUserMapper($userMapper) public function getUserMapper() { if (null === $this->userMapper) { - $this->userMapper = $this->getServiceManager()->get('zfcuser_user_mapper'); + $this->userMapper = $this->serviceManager->get('zfcuser_user_mapper'); } return $this->userMapper; } @@ -164,7 +164,7 @@ public function setRememberMeService($rememberMeService) public function getRememberMeService() { if (null === $this->rememberMeService) { - $this->rememberMeService = $this->getServiceManager()->get('goaliorememberme_rememberme_service'); + $this->rememberMeService = $this->serviceManager->get('goaliorememberme_rememberme_service'); } return $this->rememberMeService; } @@ -176,7 +176,7 @@ public function getRememberMeService() */ public function logout() { - $authService = $this->getServiceManager()->get('zfcuser_auth_service'); + $authService = $this->serviceManager->get('zfcuser_auth_service'); $user = $authService->getIdentity(); $cookie = explode("\n", $this->getRememberMeService()->getCookie()); From c6c38a773fa3f3b922cc7e31786b94ac83be299f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Str=C3=B8m?= Date: Sat, 24 Dec 2016 10:17:31 +0100 Subject: [PATCH 4/5] Remove servicemanagerawareinterface --- src/GoalioRememberMe/Authentication/Adapter/Cookie.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/GoalioRememberMe/Authentication/Adapter/Cookie.php b/src/GoalioRememberMe/Authentication/Adapter/Cookie.php index ca8976c..a33c419 100644 --- a/src/GoalioRememberMe/Authentication/Adapter/Cookie.php +++ b/src/GoalioRememberMe/Authentication/Adapter/Cookie.php @@ -4,10 +4,7 @@ use ZfcUser\Authentication\Adapter\AbstractAdapter; use Zend\Authentication\Result as AuthenticationResult; -use Zend\ServiceManager\ServiceManagerAwareInterface; use Zend\ServiceManager\ServiceManager; -use Zend\Stdlib\RequestInterface as Request; -use Zend\Stdlib\ResponseInterface as Response; use ZfcUser\Authentication\Adapter\AdapterChainEvent as AuthEvent; class Cookie extends AbstractAdapter From 6331605cd204b17f7e3b0e16e5effb83070ae0e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Str=C3=B8m?= Date: Sat, 24 Dec 2016 10:53:17 +0100 Subject: [PATCH 5/5] Remove servicemanagerawareinterface --- src/GoalioRememberMe/Module.php | 6 ++++-- src/GoalioRememberMe/Service/RememberMe.php | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/GoalioRememberMe/Module.php b/src/GoalioRememberMe/Module.php index 4c95c39..58bc445 100644 --- a/src/GoalioRememberMe/Module.php +++ b/src/GoalioRememberMe/Module.php @@ -28,10 +28,12 @@ public function getServiceConfig() { return array( 'invokables' => array( 'GoalioRememberMe\Form\Login' => 'GoalioRememberMe\Form\Login', - 'goaliorememberme_rememberme_service' => 'GoalioRememberMe\Service\RememberMe', - ), + ), 'factories' => array( + 'goaliorememberme_rememberme_service' => function ($sm) { + return new\GoalioRememberMe\Service\RememberMe($sm); + }, 'GoalioRememberMe\Authentication\Adapter\Cookie' => function ($sm) { return new Cookie($sm); diff --git a/src/GoalioRememberMe/Service/RememberMe.php b/src/GoalioRememberMe/Service/RememberMe.php index 77e14ba..6def295 100644 --- a/src/GoalioRememberMe/Service/RememberMe.php +++ b/src/GoalioRememberMe/Service/RememberMe.php @@ -2,17 +2,22 @@ namespace GoalioRememberMe\Service; -use Zend\ServiceManager\ServiceManagerAwareInterface; use Zend\ServiceManager\ServiceManager; use ZfcBase\EventManager\EventProvider; use GoalioRememberMe\Options\RememberMeOptionsInterface; use Zend\Math\Rand; -class RememberMe extends EventProvider implements ServiceManagerAwareInterface +class RememberMe extends EventProvider { protected $mapper, $options; protected $serviceManager; + + public function __construct($serviceManager) + { + + $this->serviceManager = $serviceManager; + } public function createToken($length = 16) {