diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-12-11 09:38:23 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-12-11 10:00:24 +0100 |
commit | d808f9c053fb80b0ec042f12e39f7387ca7821ca (patch) | |
tree | 16fb70e64dc046adc8319646efb9d31533ba92f4 /lib/private/Server.php | |
parent | 68d59915d6084c92799c22196012e32f7bb12be4 (diff) | |
download | nextcloud-server-d808f9c053fb80b0ec042f12e39f7387ca7821ca.tar.gz nextcloud-server-d808f9c053fb80b0ec042f12e39f7387ca7821ca.zip |
Add typed events for all user hooks and legacy events
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/Server.php')
-rw-r--r-- | lib/private/Server.php | 76 |
1 files changed, 71 insertions, 5 deletions
diff --git a/lib/private/Server.php b/lib/private/Server.php index dcac72369e4..c6ff6691998 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; }); |