From d808f9c053fb80b0ec042f12e39f7387ca7821ca Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 11 Dec 2019 09:38:23 +0100 Subject: [PATCH] Add typed events for all user hooks and legacy events Signed-off-by: Christoph Wurst --- lib/composer/composer/autoload_classmap.php | 12 +++ lib/composer/composer/autoload_static.php | 12 +++ lib/private/Server.php | 76 ++++++++++++++- lib/private/User/Session.php | 6 +- .../Events/BeforePasswordUpdatedEvent.php | 82 ++++++++++++++++ .../User/Events/BeforeUserCreatedEvent.php | 66 +++++++++++++ .../User/Events/BeforeUserDeletedEvent.php | 54 +++++++++++ .../User/Events/BeforeUserLoggedInEvent.php | 66 +++++++++++++ .../BeforeUserLoggedInWithCookieEvent.php | 55 +++++++++++ .../User/Events/BeforeUserLoggedOutEvent.php | 55 +++++++++++ .../User/Events/PasswordUpdatedEvent.php | 82 ++++++++++++++++ lib/public/User/Events/UserChangedEvent.php | 93 +++++++++++++++++++ lib/public/User/Events/UserDeletedEvent.php | 54 +++++++++++ lib/public/User/Events/UserLoggedInEvent.php | 77 +++++++++++++++ .../Events/UserLoggedInWithCookieEvent.php | 66 +++++++++++++ lib/public/User/Events/UserLoggedOutEvent.php | 55 +++++++++++ 16 files changed, 903 insertions(+), 8 deletions(-) create mode 100644 lib/public/User/Events/BeforePasswordUpdatedEvent.php create mode 100644 lib/public/User/Events/BeforeUserCreatedEvent.php create mode 100644 lib/public/User/Events/BeforeUserDeletedEvent.php create mode 100644 lib/public/User/Events/BeforeUserLoggedInEvent.php create mode 100644 lib/public/User/Events/BeforeUserLoggedInWithCookieEvent.php create mode 100644 lib/public/User/Events/BeforeUserLoggedOutEvent.php create mode 100644 lib/public/User/Events/PasswordUpdatedEvent.php create mode 100644 lib/public/User/Events/UserChangedEvent.php create mode 100644 lib/public/User/Events/UserDeletedEvent.php create mode 100644 lib/public/User/Events/UserLoggedInEvent.php create mode 100644 lib/public/User/Events/UserLoggedInWithCookieEvent.php create mode 100644 lib/public/User/Events/UserLoggedOutEvent.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 563d7cf7c7..b3e12e557d 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -452,9 +452,21 @@ 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\\BeforePasswordUpdatedEvent' => $baseDir . '/lib/public/User/Events/BeforePasswordUpdatedEvent.php', + 'OCP\\User\\Events\\BeforeUserCreatedEvent' => $baseDir . '/lib/public/User/Events/BeforeUserCreatedEvent.php', + 'OCP\\User\\Events\\BeforeUserDeletedEvent' => $baseDir . '/lib/public/User/Events/BeforeUserDeletedEvent.php', + 'OCP\\User\\Events\\BeforeUserLoggedInEvent' => $baseDir . '/lib/public/User/Events/BeforeUserLoggedInEvent.php', + 'OCP\\User\\Events\\BeforeUserLoggedInWithCookieEvent' => $baseDir . '/lib/public/User/Events/BeforeUserLoggedInWithCookieEvent.php', + 'OCP\\User\\Events\\BeforeUserLoggedOutEvent' => $baseDir . '/lib/public/User/Events/BeforeUserLoggedOutEvent.php', 'OCP\\User\\Events\\CreateUserEvent' => $baseDir . '/lib/public/User/Events/CreateUserEvent.php', + 'OCP\\User\\Events\\PasswordUpdatedEvent' => $baseDir . '/lib/public/User/Events/PasswordUpdatedEvent.php', 'OCP\\User\\Events\\PostLoginEvent' => $baseDir . '/lib/public/User/Events/PostLoginEvent.php', + 'OCP\\User\\Events\\UserChangedEvent' => $baseDir . '/lib/public/User/Events/UserChangedEvent.php', 'OCP\\User\\Events\\UserCreatedEvent' => $baseDir . '/lib/public/User/Events/UserCreatedEvent.php', + 'OCP\\User\\Events\\UserDeletedEvent' => $baseDir . '/lib/public/User/Events/UserDeletedEvent.php', + 'OCP\\User\\Events\\UserLoggedInEvent' => $baseDir . '/lib/public/User/Events/UserLoggedInEvent.php', + 'OCP\\User\\Events\\UserLoggedInWithCookieEvent' => $baseDir . '/lib/public/User/Events/UserLoggedInWithCookieEvent.php', + 'OCP\\User\\Events\\UserLoggedOutEvent' => $baseDir . '/lib/public/User/Events/UserLoggedOutEvent.php', 'OCP\\Util' => $baseDir . '/lib/public/Util.php', 'OCP\\WorkflowEngine\\EntityContext\\IDisplayName' => $baseDir . '/lib/public/WorkflowEngine/EntityContext/IDisplayName.php', 'OCP\\WorkflowEngine\\EntityContext\\IDisplayText' => $baseDir . '/lib/public/WorkflowEngine/EntityContext/IDisplayText.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 140ec46185..6ca4763440 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -481,9 +481,21 @@ 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\\BeforePasswordUpdatedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/BeforePasswordUpdatedEvent.php', + 'OCP\\User\\Events\\BeforeUserCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/BeforeUserCreatedEvent.php', + 'OCP\\User\\Events\\BeforeUserDeletedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/BeforeUserDeletedEvent.php', + 'OCP\\User\\Events\\BeforeUserLoggedInEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/BeforeUserLoggedInEvent.php', + 'OCP\\User\\Events\\BeforeUserLoggedInWithCookieEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/BeforeUserLoggedInWithCookieEvent.php', + 'OCP\\User\\Events\\BeforeUserLoggedOutEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/BeforeUserLoggedOutEvent.php', 'OCP\\User\\Events\\CreateUserEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/CreateUserEvent.php', + 'OCP\\User\\Events\\PasswordUpdatedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/PasswordUpdatedEvent.php', 'OCP\\User\\Events\\PostLoginEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/PostLoginEvent.php', + 'OCP\\User\\Events\\UserChangedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserChangedEvent.php', 'OCP\\User\\Events\\UserCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserCreatedEvent.php', + 'OCP\\User\\Events\\UserDeletedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserDeletedEvent.php', + 'OCP\\User\\Events\\UserLoggedInEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserLoggedInEvent.php', + 'OCP\\User\\Events\\UserLoggedInWithCookieEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserLoggedInWithCookieEvent.php', + 'OCP\\User\\Events\\UserLoggedOutEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserLoggedOutEvent.php', 'OCP\\Util' => __DIR__ . '/../../..' . '/lib/public/Util.php', 'OCP\\WorkflowEngine\\EntityContext\\IDisplayName' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/EntityContext/IDisplayName.php', 'OCP\\WorkflowEngine\\EntityContext\\IDisplayText' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/EntityContext/IDisplayText.php', diff --git a/lib/private/Server.php b/lib/private/Server.php index dcac72369e..c6ff669199 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -113,7 +113,6 @@ use OC\Security\Bruteforce\Throttler; use OC\Security\CertificateManager; use OC\Security\CredentialsManager; use OC\Security\Crypto; -use OC\Security\CSP\ContentSecurityPolicyManager; use OC\Security\CSP\ContentSecurityPolicyNonceManager; use OC\Security\CSRF\CsrfTokenGenerator; use OC\Security\CSRF\CsrfTokenManager; @@ -163,6 +162,19 @@ use OCP\Remote\IInstanceFactory; use OCP\RichObjectStrings\IValidator; use OCP\Security\IContentSecurityPolicyManager; use OCP\Share\IShareHelper; +use OCP\User\Events\BeforePasswordUpdatedEvent; +use OCP\User\Events\BeforeUserCreatedEvent; +use OCP\User\Events\BeforeUserDeletedEvent; +use OCP\User\Events\BeforeUserLoggedInEvent; +use OCP\User\Events\BeforeUserLoggedInWithCookieEvent; +use OCP\User\Events\BeforeUserLoggedOutEvent; +use OCP\User\Events\PasswordUpdatedEvent; +use OCP\User\Events\UserChangedEvent; +use OCP\User\Events\UserCreatedEvent; +use OCP\User\Events\UserDeletedEvent; +use OCP\User\Events\UserLoggedInEvent; +use OCP\User\Events\UserLoggedInWithCookieEvent; +use OCP\User\Events\UserLoggedOutEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; @@ -380,7 +392,7 @@ class Server extends ServerContainer implements IServerContainer { $defaultTokenProvider = null; } - $dispatcher = $c->getEventDispatcher(); + $legacyDispatcher = $c->getEventDispatcher(); $userSession = new \OC\User\Session( $manager, @@ -395,45 +407,99 @@ class Server extends ServerContainer implements IServerContainer { ); $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); + + /** @var IEventDispatcher $dispatcher */ + $dispatcher = $this->query(IEventDispatcher::class); + $dispatcher->dispatchTyped(new BeforeUserCreatedEvent($uid, $password)); }); $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); + + /** @var IEventDispatcher $dispatcher */ + $dispatcher = $this->query(IEventDispatcher::class); + $dispatcher->dispatchTyped(new UserCreatedEvent($user, $password)); }); - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); - $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); + $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); + + /** @var IEventDispatcher $dispatcher */ + $dispatcher = $this->query(IEventDispatcher::class); + $dispatcher->dispatchTyped(new BeforeUserDeletedEvent($user)); }); $userSession->listen('\OC\User', 'postDelete', function ($user) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); + + /** @var IEventDispatcher $dispatcher */ + $dispatcher = $this->query(IEventDispatcher::class); + $dispatcher->dispatchTyped(new UserDeletedEvent($user)); }); $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); + + /** @var IEventDispatcher $dispatcher */ + $dispatcher = $this->query(IEventDispatcher::class); + $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); }); $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); + + /** @var IEventDispatcher $dispatcher */ + $dispatcher = $this->query(IEventDispatcher::class); + $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); }); $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); + + /** @var IEventDispatcher $dispatcher */ + $dispatcher = $this->query(IEventDispatcher::class); + $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); }); $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin)); + + /** @var IEventDispatcher $dispatcher */ + $dispatcher = $this->query(IEventDispatcher::class); + $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $password, $isTokenLogin)); + }); + $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { + /** @var IEventDispatcher $dispatcher */ + $dispatcher = $this->query(IEventDispatcher::class); + $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); }); $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); + + /** @var IEventDispatcher $dispatcher */ + $dispatcher = $this->query(IEventDispatcher::class); + $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); }); - $userSession->listen('\OC\User', 'logout', function () { + $userSession->listen('\OC\User', 'logout', function ($user) { \OC_Hook::emit('OC_User', 'logout', array()); + + /** @var IEventDispatcher $dispatcher */ + $dispatcher = $this->query(IEventDispatcher::class); + $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); + }); + $userSession->listen('\OC\User', 'postLogout', function ($user) { + /** @var IEventDispatcher $dispatcher */ + $dispatcher = $this->query(IEventDispatcher::class); + $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); }); $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { /** @var $user \OC\User\User */ \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); + + /** @var IEventDispatcher $dispatcher */ + $dispatcher = $this->query(IEventDispatcher::class); + $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); }); return $userSession; }); diff --git a/lib/private/User/Session.php b/lib/private/User/Session.php index 16d3b13cba..4aa9074b4a 100644 --- a/lib/private/User/Session.php +++ b/lib/private/User/Session.php @@ -900,9 +900,9 @@ class Session implements IUserSession, Emitter { * logout the user from the session */ public function logout() { - $this->manager->emit('\OC\User', 'logout'); $user = $this->getUser(); - if (!is_null($user)) { + $this->manager->emit('\OC\User', 'logout', [$user]); + if ($user !== null) { try { $this->tokenProvider->invalidateToken($this->session->getId()); } catch (SessionNotAvailableException $ex) { @@ -914,7 +914,7 @@ class Session implements IUserSession, Emitter { $this->setToken(null); $this->unsetMagicInCookie(); $this->session->clear(); - $this->manager->emit('\OC\User', 'postLogout'); + $this->manager->emit('\OC\User', 'postLogout', [$user]); } /** diff --git a/lib/public/User/Events/BeforePasswordUpdatedEvent.php b/lib/public/User/Events/BeforePasswordUpdatedEvent.php new file mode 100644 index 0000000000..c40bd92b61 --- /dev/null +++ b/lib/public/User/Events/BeforePasswordUpdatedEvent.php @@ -0,0 +1,82 @@ + + * + * @author 2019 Christoph Wurst + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace OCP\User\Events; + +use OCP\EventDispatcher\Event; +use OCP\IUser; + +/** + * @since 18.0.0 + */ +class BeforePasswordUpdatedEvent extends Event { + + /** @var IUser */ + private $user; + + /** @var string */ + private $password; + + /** @var string|null */ + private $recoveryPassword; + + /** + * @param IUser $user + * @param string $password + * @param string|null $recoveryPassword + * @since 18.0.0 + */ + public function __construct(IUser $user, + string $password, + string $recoveryPassword = null) { + parent::__construct(); + $this->user = $user; + $this->password = $password; + $this->recoveryPassword = $recoveryPassword; + } + + /** + * @return IUser + * @since 18.0.0 + */ + public function getUser(): IUser { + return $this->user; + } + + /** + * @return string + * @since 18.0.0 + */ + public function getPassword(): string { + return $this->password; + } + + /** + * @return string|null + * @since 18.0.0 + */ + public function getRecoveryPassword(): ?string { + return $this->recoveryPassword; + } + +} diff --git a/lib/public/User/Events/BeforeUserCreatedEvent.php b/lib/public/User/Events/BeforeUserCreatedEvent.php new file mode 100644 index 0000000000..1a00a167db --- /dev/null +++ b/lib/public/User/Events/BeforeUserCreatedEvent.php @@ -0,0 +1,66 @@ + + * + * @author Christoph Wurst + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\User\Events; + +use OCP\EventDispatcher\Event; + +/** + * @since 18.0.0 + */ +class BeforeUserCreatedEvent extends Event { + + /** @var string */ + private $uid; + + /** @var string */ + private $password; + + /** + * @since 18.0.0 + */ + public function __construct(string $uid, + string $password) { + parent::__construct(); + $this->uid = $uid; + $this->password = $password; + } + + /** + * @since 18.0.0 + */ + public function getUid(): string { + return $this->uid; + } + + /** + * @since 18.0.0 + */ + public function getPassword(): string { + return $this->password; + } + +} diff --git a/lib/public/User/Events/BeforeUserDeletedEvent.php b/lib/public/User/Events/BeforeUserDeletedEvent.php new file mode 100644 index 0000000000..b40c498350 --- /dev/null +++ b/lib/public/User/Events/BeforeUserDeletedEvent.php @@ -0,0 +1,54 @@ + + * + * @author 2019 Christoph Wurst + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace OCP\User\Events; + +use OCP\EventDispatcher\Event; +use OCP\IUser; + +/** + * @since 18.0.0 + */ +class BeforeUserDeletedEvent extends Event { + + /** @var IUser */ + private $user; + + /** + * @param IUser $user + * @since 18.0.0 + */ + public function __construct(IUser $user) { + parent::__construct(); + $this->user = $user; + } + + /** + * @return IUser + * @since 18.0.0 + */ + public function getUser(): IUser { + return $this->user; + } + +} diff --git a/lib/public/User/Events/BeforeUserLoggedInEvent.php b/lib/public/User/Events/BeforeUserLoggedInEvent.php new file mode 100644 index 0000000000..8b81947873 --- /dev/null +++ b/lib/public/User/Events/BeforeUserLoggedInEvent.php @@ -0,0 +1,66 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\User\Events; + +use OCP\EventDispatcher\Event; +use OCP\IUser; + +/** + * @since 18.0.0 + */ +class BeforeUserLoggedInEvent extends Event { + + /** @var IUser */ + private $username; + + /** @var string */ + private $password; + + /** + * @since 18.0.0 + */ + public function __construct(string $username, string $password) { + parent::__construct(); + $this->username = $username; + $this->password = $password; + } + + /** + * @since 18.0.0 + */ + public function getUsername(): IUser { + return $this->username; + } + + /** + * @since 18.0.0 + */ + public function getPassword(): string { + return $this->password; + } + +} diff --git a/lib/public/User/Events/BeforeUserLoggedInWithCookieEvent.php b/lib/public/User/Events/BeforeUserLoggedInWithCookieEvent.php new file mode 100644 index 0000000000..35f9715516 --- /dev/null +++ b/lib/public/User/Events/BeforeUserLoggedInWithCookieEvent.php @@ -0,0 +1,55 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\User\Events; + +use OCP\EventDispatcher\Event; +use OCP\IUser; + +/** + * @since 18.0.0 + */ +class BeforeUserLoggedInWithCookieEvent extends Event { + + /** @var string */ + private $username; + + /** + * @since 18.0.0 + */ + public function __construct(string $username) { + parent::__construct(); + $this->username = $username; + } + + /** + * @since 18.0.0 + */ + public function getUsername(): string { + return $this->username; + } + +} diff --git a/lib/public/User/Events/BeforeUserLoggedOutEvent.php b/lib/public/User/Events/BeforeUserLoggedOutEvent.php new file mode 100644 index 0000000000..a5d617089f --- /dev/null +++ b/lib/public/User/Events/BeforeUserLoggedOutEvent.php @@ -0,0 +1,55 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\User\Events; + +use OCP\EventDispatcher\Event; +use OCP\IUser; + +/** + * @since 18.0.0 + */ +class BeforeUserLoggedOutEvent extends Event { + + /** @var IUser|null */ + private $user; + + /** + * @since 18.0.0 + */ + public function __construct(IUser $user = null) { + parent::__construct(); + $this->user = $user; + } + + /** + * @since 18.0.0 + */ + public function getUser(): ?IUser { + return $this->user; + } + +} diff --git a/lib/public/User/Events/PasswordUpdatedEvent.php b/lib/public/User/Events/PasswordUpdatedEvent.php new file mode 100644 index 0000000000..83b5b0a7bf --- /dev/null +++ b/lib/public/User/Events/PasswordUpdatedEvent.php @@ -0,0 +1,82 @@ + + * + * @author 2019 Christoph Wurst + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace OCP\User\Events; + +use OCP\EventDispatcher\Event; +use OCP\IUser; + +/** + * @since 18.0.0 + */ +class PasswordUpdatedEvent extends Event { + + /** @var IUser */ + private $user; + + /** @var string */ + private $password; + + /** @var string|null */ + private $recoveryPassword; + + /** + * @param IUser $user + * @param string $password + * @param string|null $recoveryPassword + * @since 18.0.0 + */ + public function __construct(IUser $user, + string $password, + string $recoveryPassword = null) { + parent::__construct(); + $this->user = $user; + $this->password = $password; + $this->recoveryPassword = $recoveryPassword; + } + + /** + * @return IUser + * @since 18.0.0 + */ + public function getUser(): IUser { + return $this->user; + } + + /** + * @return string + * @since 18.0.0 + */ + public function getPassword(): string { + return $this->password; + } + + /** + * @return string|null + * @since 18.0.0 + */ + public function getRecoveryPassword(): ?string { + return $this->recoveryPassword; + } + +} diff --git a/lib/public/User/Events/UserChangedEvent.php b/lib/public/User/Events/UserChangedEvent.php new file mode 100644 index 0000000000..86b2f439bf --- /dev/null +++ b/lib/public/User/Events/UserChangedEvent.php @@ -0,0 +1,93 @@ + + * + * @author 2019 Christoph Wurst + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace OCP\User\Events; + +use OCP\EventDispatcher\Event; +use OCP\IUser; + +/** + * @since 18.0.0 + */ +class UserChangedEvent extends Event { + + /** @var IUser */ + private $user; + + /** @var string */ + private $feature; + + /** @var mixed */ + private $value; + + /** @var mixed */ + private $oldValue; + + /** + * @since 18.0.0 + */ + public function __construct(IUser $user, + string $feature, + $value, + $oldValue = null) { + parent::__construct(); + $this->user = $user; + $this->feature = $feature; + $this->value = $value; + $this->oldValue = $oldValue; + } + + /** + * @return IUser + * @since 18.0.0 + */ + public function getUser(): IUser { + return $this->user; + } + + /** + * @return string + * @since 18.0.0 + */ + public function getFeature(): string { + return $this->feature; + } + + /** + * @return mixed + * @since 18.0.0 + */ + public function getValue() { + return $this->value; + } + + /** + * @return mixed + * @since 18.0.0 + */ + public function getOldValue() { + return $this->oldValue; + } + + +} diff --git a/lib/public/User/Events/UserDeletedEvent.php b/lib/public/User/Events/UserDeletedEvent.php new file mode 100644 index 0000000000..284ee35a24 --- /dev/null +++ b/lib/public/User/Events/UserDeletedEvent.php @@ -0,0 +1,54 @@ + + * + * @author 2019 Christoph Wurst + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace OCP\User\Events; + +use OCP\EventDispatcher\Event; +use OCP\IUser; + +/** + * @since 18.0.0 + */ +class UserDeletedEvent extends Event { + + /** @var IUser */ + private $user; + + /** + * @param IUser $user + * @since 18.0.0 + */ + public function __construct(IUser $user) { + parent::__construct(); + $this->user = $user; + } + + /** + * @return IUser + * @since 18.0.0 + */ + public function getUser(): IUser { + return $this->user; + } + +} diff --git a/lib/public/User/Events/UserLoggedInEvent.php b/lib/public/User/Events/UserLoggedInEvent.php new file mode 100644 index 0000000000..8ce83f4230 --- /dev/null +++ b/lib/public/User/Events/UserLoggedInEvent.php @@ -0,0 +1,77 @@ + + * + * @author Christoph Wurst + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\User\Events; + +use OCP\EventDispatcher\Event; +use OCP\IUser; + +/** + * @since 18.0.0 + */ +class UserLoggedInEvent 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; + } + + /** + * @since 18.0.0 + */ + public function getPassword(): string { + return $this->password; + } + + /** + * @since 18.0.0 + */ + public function isTokenLogin(): bool { + return $this->isTokenLogin; + } +} diff --git a/lib/public/User/Events/UserLoggedInWithCookieEvent.php b/lib/public/User/Events/UserLoggedInWithCookieEvent.php new file mode 100644 index 0000000000..c9848e1cc7 --- /dev/null +++ b/lib/public/User/Events/UserLoggedInWithCookieEvent.php @@ -0,0 +1,66 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\User\Events; + +use OCP\EventDispatcher\Event; +use OCP\IUser; + +/** + * @since 18.0.0 + */ +class UserLoggedInWithCookieEvent extends Event { + + /** @var IUser */ + private $user; + + /** @var string|null */ + private $password; + + /** + * @since 18.0.0 + */ + public function __construct(IUser $user, ?string $password) { + parent::__construct(); + $this->user = $user; + $this->password = $password; + } + + /** + * @since 18.0.0 + */ + public function getUser(): IUser { + return $this->user; + } + + /** + * @since 18.0.0 + */ + public function getPassword(): ?string { + return $this->password; + } + +} diff --git a/lib/public/User/Events/UserLoggedOutEvent.php b/lib/public/User/Events/UserLoggedOutEvent.php new file mode 100644 index 0000000000..1425914953 --- /dev/null +++ b/lib/public/User/Events/UserLoggedOutEvent.php @@ -0,0 +1,55 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\User\Events; + +use OCP\EventDispatcher\Event; +use OCP\IUser; + +/** + * @since 18.0.0 + */ +class UserLoggedOutEvent extends Event { + + /** @var IUser|null */ + private $user; + + /** + * @since 18.0.0 + */ + public function __construct(IUser $user = null) { + parent::__construct(); + $this->user = $user; + } + + /** + * @since 18.0.0 + */ + public function getUser(): ?IUser { + return $this->user; + } + +}