From 62270a2c48efd128ffdf033f5143c4188a761d98 Mon Sep 17 00:00:00 2001 From: Marco Date: Sat, 24 Mar 2018 23:13:04 +0100 Subject: [PATCH] Permit restriction to selector in 'deleteRememberDirectiveForUserById' --- src/Auth.php | 4 ++-- src/UserManager.php | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Auth.php b/src/Auth.php index 6963c52..dba55f1 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -454,8 +454,8 @@ final class Auth extends UserManager { $this->setRememberCookie($selector, $token, $expires); } - protected function deleteRememberDirectiveForUserById($userId) { - parent::deleteRememberDirectiveForUserById($userId); + protected function deleteRememberDirectiveForUserById($userId, $selector = null) { + parent::deleteRememberDirectiveForUserById($userId, $selector); $this->setRememberCookie(null, null, \time() - 3600); } diff --git a/src/UserManager.php b/src/UserManager.php index 285ce9c..4c1a845 100644 --- a/src/UserManager.php +++ b/src/UserManager.php @@ -371,13 +371,22 @@ abstract class UserManager { * Clears an existing directive that keeps the user logged in ("remember me") * * @param int $userId the ID of the user who shouldn't be kept signed in anymore + * @param string $selector (optional) the selector which the deletion should be restricted to * @throws AuthError if an internal problem occurred (do *not* catch) */ - protected function deleteRememberDirectiveForUserById($userId) { + protected function deleteRememberDirectiveForUserById($userId, $selector = null) { + $whereMappings = []; + + if (isset($selector)) { + $whereMappings['selector'] = (string) $selector; + } + + $whereMappings['user'] = (int) $userId; + try { $this->db->delete( $this->dbTablePrefix . 'users_remembered', - [ 'user' => $userId ] + $whereMappings ); } catch (Error $e) {