Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix login remember me with google authentication #740

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
composer.lock
.php_cs*
/coverage
/nbproject/private/
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions nbproject/project.properties
Original file line number Diff line number Diff line change
@@ -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=.
9 changes: 9 additions & 0 deletions nbproject/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.php.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/php-project/1">
<name>users</name>
</data>
</configuration>
</project>
11 changes: 11 additions & 0 deletions src/Controller/Traits/LoginTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -288,6 +289,11 @@ public function verify()

$user['secret_verified'] = true;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Expand Down Expand Up @@ -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()
Expand Down
27 changes: 27 additions & 0 deletions tests/TestCase/Controller/Traits/LoginTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down