diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index cf28f634ca..9a54c3bf3c 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 aa12c20ac1..e06489c4cc 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 842d19d8d5..3b0231aea0 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 similarity index 87% rename from lib/private/User/Events/PostLoginEvent.php rename to lib/public/User/Events/PostLoginEvent.php index d14030b529..7cc7aab4cd 100644 --- a/lib/private/User/Events/PostLoginEvent.php +++ b/lib/public/User/Events/PostLoginEvent.php @@ -1,5 +1,7 @@ * @@ -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 d6e0263da5..4c79fe7942 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; }) );