aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2019-11-21 12:39:42 +0100
committerGitHub <noreply@github.com>2019-11-21 12:39:42 +0100
commit5c4b2a243642d2eb628515d5182a8e07e290bd2c (patch)
tree6d4bab33a452032e45b3dfe090b6ed01b1361957
parente7f225c013a6e55fdc84587b9103a75fc94eed1b (diff)
parent535000aac6ea0579e8f7468e4b7f6b822975ed86 (diff)
downloadnextcloud-server-5c4b2a243642d2eb628515d5182a8e07e290bd2c.tar.gz
nextcloud-server-5c4b2a243642d2eb628515d5182a8e07e290bd2c.zip
Merge pull request #18029 from nextcloud/feature/public-post-login-event
Make the post login event public
-rw-r--r--lib/composer/composer/autoload_classmap.php2
-rw-r--r--lib/composer/composer/autoload_static.php2
-rw-r--r--lib/private/User/Session.php7
-rw-r--r--lib/public/User/Events/PostLoginEvent.php (renamed from lib/private/User/Events/PostLoginEvent.php)29
-rw-r--r--tests/lib/User/SessionTest.php4
5 files changed, 28 insertions, 16 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index cf28f634cab..9a54c3bf3c6 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -440,6 +440,7 @@ return array(
'OCP\\User\\Backend\\IProvideAvatarBackend' => $baseDir . '/lib/public/User/Backend/IProvideAvatarBackend.php',
'OCP\\User\\Backend\\ISetDisplayNameBackend' => $baseDir . '/lib/public/User/Backend/ISetDisplayNameBackend.php',
'OCP\\User\\Backend\\ISetPasswordBackend' => $baseDir . '/lib/public/User/Backend/ISetPasswordBackend.php',
+ 'OCP\\User\\Events\\PostLoginEvent' => $baseDir . '/lib/public/User/Events/PostLoginEvent.php',
'OCP\\Util' => $baseDir . '/lib/public/Util.php',
'OCP\\WorkflowEngine\\GenericEntityEvent' => $baseDir . '/lib/public/WorkflowEngine/GenericEntityEvent.php',
'OCP\\WorkflowEngine\\ICheck' => $baseDir . '/lib/public/WorkflowEngine/ICheck.php',
@@ -1206,7 +1207,6 @@ return array(
'OC\\Updater\\VersionCheck' => $baseDir . '/lib/private/Updater/VersionCheck.php',
'OC\\User\\Backend' => $baseDir . '/lib/private/User/Backend.php',
'OC\\User\\Database' => $baseDir . '/lib/private/User/Database.php',
- 'OC\\User\\Events\\PostLoginEvent' => $baseDir . '/lib/private/User/Events/PostLoginEvent.php',
'OC\\User\\LoginException' => $baseDir . '/lib/private/User/LoginException.php',
'OC\\User\\Manager' => $baseDir . '/lib/private/User/Manager.php',
'OC\\User\\NoUserException' => $baseDir . '/lib/private/User/NoUserException.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index aa12c20ac13..e06489c4cc0 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -469,6 +469,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\User\\Backend\\IProvideAvatarBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IProvideAvatarBackend.php',
'OCP\\User\\Backend\\ISetDisplayNameBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ISetDisplayNameBackend.php',
'OCP\\User\\Backend\\ISetPasswordBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ISetPasswordBackend.php',
+ 'OCP\\User\\Events\\PostLoginEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/PostLoginEvent.php',
'OCP\\Util' => __DIR__ . '/../../..' . '/lib/public/Util.php',
'OCP\\WorkflowEngine\\GenericEntityEvent' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/GenericEntityEvent.php',
'OCP\\WorkflowEngine\\ICheck' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/ICheck.php',
@@ -1235,7 +1236,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Updater\\VersionCheck' => __DIR__ . '/../../..' . '/lib/private/Updater/VersionCheck.php',
'OC\\User\\Backend' => __DIR__ . '/../../..' . '/lib/private/User/Backend.php',
'OC\\User\\Database' => __DIR__ . '/../../..' . '/lib/private/User/Database.php',
- 'OC\\User\\Events\\PostLoginEvent' => __DIR__ . '/../../..' . '/lib/private/User/Events/PostLoginEvent.php',
'OC\\User\\LoginException' => __DIR__ . '/../../..' . '/lib/private/User/LoginException.php',
'OC\\User\\Manager' => __DIR__ . '/../../..' . '/lib/private/User/Manager.php',
'OC\\User\\NoUserException' => __DIR__ . '/../../..' . '/lib/private/User/NoUserException.php',
diff --git a/lib/private/User/Session.php b/lib/private/User/Session.php
index 842d19d8d54..3b0231aea03 100644
--- a/lib/private/User/Session.php
+++ b/lib/private/User/Session.php
@@ -61,6 +61,7 @@ use OCP\IUserSession;
use OCP\Lockdown\ILockdownManager;
use OCP\Security\ISecureRandom;
use OCP\Session\Exceptions\SessionNotAvailableException;
+use OCP\User\Events\PostLoginEvent;
use OCP\Util;
use Symfony\Component\EventDispatcher\GenericEvent;
@@ -398,13 +399,11 @@ class Session implements IUserSession, Emitter {
$firstTimeLogin = $user->updateLastLoginTimestamp();
}
- $postLoginEvent = new OC\User\Events\PostLoginEvent(
+ $this->dispatcher->dispatchTyped(new PostLoginEvent(
$user,
$loginDetails['password'],
$isToken
- );
- $this->dispatcher->dispatch(OC\User\Events\PostLoginEvent::class, $postLoginEvent);
-
+ ));
$this->manager->emit('\OC\User', 'postLogin', [
$user,
$loginDetails['password'],
diff --git a/lib/private/User/Events/PostLoginEvent.php b/lib/public/User/Events/PostLoginEvent.php
index d14030b5294..7cc7aab4cd3 100644
--- a/lib/private/User/Events/PostLoginEvent.php
+++ b/lib/public/User/Events/PostLoginEvent.php
@@ -1,5 +1,7 @@
<?php
+
declare(strict_types=1);
+
/**
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
*
@@ -22,42 +24,53 @@ declare(strict_types=1);
*
*/
-namespace OC\User\Events;
+namespace OCP\User\Events;
use OCP\EventDispatcher\Event;
use OCP\IUser;
+/**
+ * @since 18.0.0
+ */
class PostLoginEvent extends Event {
/** @var IUser */
private $user;
+
/** @var string */
private $password;
+
/** @var bool */
private $isTokenLogin;
-
+ /**
+ * @since 18.0.0
+ */
public function __construct(IUser $user, string $password, bool $isTokenLogin) {
parent::__construct();
-
$this->user = $user;
$this->password = $password;
$this->isTokenLogin = $isTokenLogin;
}
+ /**
+ * @since 18.0.0
+ */
public function getUser(): IUser {
return $this->user;
}
- public function hasPassword(): bool {
- return $this->password !== '';
- }
-
+ /**
+ * @since 18.0.0
+ */
public function getPassword(): string {
return $this->password;
}
- public function getIsTokenLogin(): bool {
+ /**
+ * @since 18.0.0
+ */
+ public function isTokenLogin(): bool {
return $this->isTokenLogin;
}
}
diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php
index d6e0263da52..4c79fe7942c 100644
--- a/tests/lib/User/SessionTest.php
+++ b/tests/lib/User/SessionTest.php
@@ -15,7 +15,7 @@ use OC\Authentication\Token\IProvider;
use OC\Authentication\Token\IToken;
use OC\Security\Bruteforce\Throttler;
use OC\Session\Memory;
-use OC\User\Events\PostLoginEvent;
+use OCP\User\Events\PostLoginEvent;
use OC\User\Manager;
use OC\User\Session;
use OC\User\User;
@@ -264,7 +264,7 @@ class SessionTest extends \Test\TestCase {
$this->callback(function(PostLoginEvent $e) {
return $e->getUser()->getUID() === 'foo' &&
$e->getPassword() === 'bar' &&
- $e->getIsTokenLogin() === false;
+ $e->isTokenLogin() === false;
})
);