-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1347 from nextcloud/bring-back-remember-me
fix remember me login
- Loading branch information
Showing
20 changed files
with
643 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?php | ||
/** | ||
* @copyright Copyright (c) 2016, ownCloud, Inc. | ||
* @copyright Copyright (c) 2016, Christoph Wurst <[email protected]> | ||
* | ||
* @author Christoph Wurst <[email protected]> | ||
* | ||
|
@@ -56,7 +57,11 @@ class DefaultTokenProvider implements IProvider { | |
* @param ILogger $logger | ||
* @param ITimeFactory $time | ||
*/ | ||
public function __construct(DefaultTokenMapper $mapper, ICrypto $crypto, IConfig $config, ILogger $logger, ITimeFactory $time) { | ||
public function __construct(DefaultTokenMapper $mapper, | ||
ICrypto $crypto, | ||
IConfig $config, | ||
ILogger $logger, | ||
ITimeFactory $time) { | ||
$this->mapper = $mapper; | ||
$this->crypto = $crypto; | ||
$this->config = $config; | ||
|
@@ -73,9 +78,10 @@ public function __construct(DefaultTokenMapper $mapper, ICrypto $crypto, IConfig | |
* @param string|null $password | ||
* @param string $name | ||
* @param int $type token type | ||
* @param int $remember whether the session token should be used for remember-me | ||
* @return IToken | ||
*/ | ||
public function generateToken($token, $uid, $loginName, $password, $name, $type = IToken::TEMPORARY_TOKEN) { | ||
public function generateToken($token, $uid, $loginName, $password, $name, $type = IToken::TEMPORARY_TOKEN, $remember = IToken::DO_NOT_REMEMBER) { | ||
$dbToken = new DefaultToken(); | ||
$dbToken->setUid($uid); | ||
$dbToken->setLoginName($loginName); | ||
|
@@ -85,6 +91,7 @@ public function generateToken($token, $uid, $loginName, $password, $name, $type | |
$dbToken->setName($name); | ||
$dbToken->setToken($this->hashToken($token)); | ||
$dbToken->setType($type); | ||
$dbToken->setRemember($remember); | ||
$dbToken->setLastActivity($this->time->getTime()); | ||
|
||
$this->mapper->insert($dbToken); | ||
|
@@ -96,6 +103,7 @@ public function generateToken($token, $uid, $loginName, $password, $name, $type | |
* Save the updated token | ||
* | ||
* @param IToken $token | ||
* @throws InvalidTokenException | ||
*/ | ||
public function updateToken(IToken $token) { | ||
if (!($token instanceof DefaultToken)) { | ||
|
@@ -151,6 +159,28 @@ public function getToken($tokenId) { | |
} | ||
} | ||
|
||
/** | ||
* @param string $oldSessionId | ||
* @param string $sessionId | ||
* @throws InvalidTokenException | ||
*/ | ||
public function renewSessionToken($oldSessionId, $sessionId) { | ||
$token = $this->getToken($oldSessionId); | ||
|
||
$newToken = new DefaultToken(); | ||
$newToken->setUid($token->getUID()); | ||
$newToken->setLoginName($token->getLoginName()); | ||
if (!is_null($token->getPassword())) { | ||
$password = $this->decryptPassword($token->getPassword(), $oldSessionId); | ||
$newToken->setPassword($this->encryptPassword($password, $sessionId)); | ||
} | ||
$newToken->setName($token->getName()); | ||
$newToken->setToken($this->hashToken($sessionId)); | ||
$newToken->setType(IToken::TEMPORARY_TOKEN); | ||
$newToken->setLastActivity($this->time->getTime()); | ||
$this->mapper->insert($newToken); | ||
} | ||
|
||
/** | ||
* @param IToken $savedToken | ||
* @param string $tokenId session token | ||
|
@@ -207,8 +237,11 @@ public function invalidateTokenById(IUser $user, $id) { | |
*/ | ||
public function invalidateOldTokens() { | ||
$olderThan = $this->time->getTime() - (int) $this->config->getSystemValue('session_lifetime', 60 * 60 * 24); | ||
$this->logger->info('Invalidating tokens older than ' . date('c', $olderThan)); | ||
$this->mapper->invalidateOld($olderThan); | ||
$this->logger->info('Invalidating session tokens older than ' . date('c', $olderThan)); | ||
$this->mapper->invalidateOld($olderThan, IToken::DO_NOT_REMEMBER); | ||
$rememberThreshold = $this->time->getTime() - (int) $this->config->getSystemValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15); | ||
$this->logger->info('Invalidating remembered session tokens older than ' . date('c', $rememberThreshold)); | ||
$this->mapper->invalidateOld($rememberThreshold, IToken::REMEMBER); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.