diff --git a/.gitignore b/.gitignore index c89d5a392..3ca489870 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ composer.lock .php_cs* /coverage +/nbproject/private/ \ No newline at end of file diff --git a/composer.json b/composer.json index 2609599e4..4bcf8b3ef 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "cakedc/auth": "^3.0" }, "require-dev": { - "phpunit/phpunit": "^5.0", + "phpunit/phpunit": "^5.7|^6.0", "cakephp/cakephp-codesniffer": "^2.0", "league/oauth2-facebook": "@stable", "league/oauth2-instagram": "@stable", diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 000000000..2babf34a9 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,7 @@ +include.path=${php.global.include.path} +php.version=PHP_70 +source.encoding=UTF-8 +src.dir=src +tags.asp=false +tags.short=false +web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 000000000..33dfcdaa2 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,9 @@ + + + org.netbeans.modules.php.project + + + users + + + diff --git a/src/Controller/Traits/LoginTrait.php b/src/Controller/Traits/LoginTrait.php index 10a99ff12..d33a9c3c6 100644 --- a/src/Controller/Traits/LoginTrait.php +++ b/src/Controller/Traits/LoginTrait.php @@ -272,6 +272,7 @@ public function verify() $verificationCode = $this->request->getData('code'); $user = $this->request->getSession()->read('temporarySession'); $entity = $this->getUsersTable()->get($user['id']); + $userRememberMe = $this->request->getSession()->read('Users.hasRememberMe'); if (!empty($entity['secret'])) { $codeVerified = $this->GoogleAuthenticator->verifyCode($entity['secret'], $verificationCode); @@ -288,6 +289,11 @@ public function verify() $user['secret_verified'] = true; } + + if ($userRememberMe) { + $this->request->data(Configure::read('Users.RememberMe.Cookie.name'), $userRememberMe); + $this->request->getSession()->delete('Users.hasRememberMe'); + } $this->request->getSession()->delete('temporarySession'); $this->Auth->setUser($user); @@ -339,6 +345,11 @@ protected function _afterIdentifyUser($user, $socialLogin = false, $googleAuthen // storing user's session in the temporary one // until the GA verification is checked $this->request->getSession()->write('temporarySession', $user); + + if (Configure::read('Users.RememberMe.active')) { + $this->request->getSession()->write('Users.hasRememberMe', $this->request->getData(Configure::read('Users.RememberMe.Cookie.name'))); + } + $url = Configure::read('GoogleAuthenticator.verifyAction'); $url = array_merge($url, [ '?' => $this->request->getQueryParams() diff --git a/tests/TestCase/Controller/Traits/LoginTraitTest.php b/tests/TestCase/Controller/Traits/LoginTraitTest.php index a897f0f50..34f2094f2 100644 --- a/tests/TestCase/Controller/Traits/LoginTraitTest.php +++ b/tests/TestCase/Controller/Traits/LoginTraitTest.php @@ -416,6 +416,33 @@ public function testVerifyHappy() ]); $this->Trait->verify(); } + /** + * testVerifyGoogleAuthenticator + * + */ + public function testVerifyGoogleAuthenticator() + { + Configure::write('Users.GoogleAuthenticator.login', true); + + $this->Trait->request = $this->getMockBuilder('Cake\Network\Request') + ->setMethods(['is', 'getData', 'allow', 'getSession']) + ->getMock(); + $this->Trait->request->expects($this->once()) + ->method('is') + ->with('post') + ->will($this->returnValue(false)); + + $this->_mockSession([ + 'temporarySession' => [ + 'id' => 1, + 'secret_verified' => 1, + ], + 'Users' => [ + 'hasRememberMe' => 1 + ] + ]); + $this->Trait->verify(); + } /** * testVerifyNoUser