diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php
index 7a3f2a9316f..f2e6036af43 100644
--- a/apps/settings/lib/AppInfo/Application.php
+++ b/apps/settings/lib/AppInfo/Application.php
@@ -85,7 +85,6 @@ use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\IAppContainer;
-use OCP\AppFramework\QueryException;
use OCP\Defaults;
use OCP\Group\Events\GroupDeletedEvent;
use OCP\Group\Events\UserAddedEvent;
@@ -94,6 +93,8 @@ use OCP\IServerContainer;
use OCP\Settings\Events\DeclarativeSettingsGetValueEvent;
use OCP\Settings\Events\DeclarativeSettingsSetValueEvent;
use OCP\Settings\IManager;
+use OCP\User\Events\PasswordUpdatedEvent;
+use OCP\User\Events\UserChangedEvent;
use OCP\Util;
class Application extends App implements IBootstrap {
@@ -121,6 +122,8 @@ class Application extends App implements IBootstrap {
$context->registerEventListener(UserAddedEvent::class, UserAddedToGroupActivityListener::class);
$context->registerEventListener(UserRemovedEvent::class, UserRemovedFromGroupActivityListener::class);
$context->registerEventListener(GroupDeletedEvent::class, GroupRemovedListener::class);
+ $context->registerEventListener(PasswordUpdatedEvent::class, Hooks::class);
+ $context->registerEventListener(UserChangedEvent::class, Hooks::class);
// Register Mail Provider listeners
$context->registerEventListener(DeclarativeSettingsGetValueEvent::class, MailProviderListener::class);
@@ -223,37 +226,5 @@ class Application extends App implements IBootstrap {
}
public function boot(IBootContext $context): void {
- Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword');
- Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo');
- }
-
- /**
- * @param array $parameters
- * @throws \InvalidArgumentException
- * @throws \BadMethodCallException
- * @throws \Exception
- * @throws QueryException
- */
- public function onChangePassword(array $parameters) {
- /** @var Hooks $hooks */
- $hooks = $this->getContainer()->query(Hooks::class);
- $hooks->onChangePassword($parameters['uid']);
- }
-
- /**
- * @param array $parameters
- * @throws \InvalidArgumentException
- * @throws \BadMethodCallException
- * @throws \Exception
- * @throws QueryException
- */
- public function onChangeInfo(array $parameters) {
- if ($parameters['feature'] !== 'eMailAddress') {
- return;
- }
-
- /** @var Hooks $hooks */
- $hooks = $this->getContainer()->query(Hooks::class);
- $hooks->onChangeEmail($parameters['user'], $parameters['old_value']);
}
}
diff --git a/apps/settings/lib/Hooks.php b/apps/settings/lib/Hooks.php
index f59013ca5e1..3ff3a8b1190 100644
--- a/apps/settings/lib/Hooks.php
+++ b/apps/settings/lib/Hooks.php
@@ -1,5 +1,7 @@
+ */
+class Hooks implements IEventListener {
public function __construct(
protected IActivityManager $activityManager,
@@ -33,16 +42,19 @@ class Hooks {
) {
}
- /**
- * @param string $uid
- * @throws \InvalidArgumentException
- * @throws \BadMethodCallException
- * @throws \Exception
- */
- public function onChangePassword($uid) {
- $user = $this->userManager->get($uid);
+ public function handle(Event $event): void {
+ if ($event instanceof PasswordUpdatedEvent) {
+ $this->onChangePassword($event);
+ }
+ if ($event instanceof UserChangedEvent) {
+ $this->onChangeEmail($event);
+ }
+ }
- if (!$user instanceof IUser || $user->getLastLogin() === 0) {
+ public function onChangePassword(PasswordUpdatedEvent $handle): void {
+ $user = $handle->getUser();
+
+ if ($user->getLastLogin() === 0) {
// User didn't login, so don't create activities and emails.
return;
}
@@ -89,6 +101,7 @@ class Hooks {
'displayname' => $user->getDisplayName(),
'emailAddress' => $user->getEMailAddress(),
'instanceUrl' => $instanceUrl,
+ 'event' => $handle,
]);
$template->setSubject($l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceName]));
@@ -105,13 +118,14 @@ class Hooks {
}
}
- /**
- * @param IUser $user
- * @param string|null $oldMailAddress
- * @throws \InvalidArgumentException
- * @throws \BadMethodCallException
- */
- public function onChangeEmail(IUser $user, $oldMailAddress) {
+ public function onChangeEmail(UserChangedEvent $handle): void {
+ if ($handle->getFeature() !== 'eMailAddress') {
+ return;
+ }
+
+ $oldMailAddress = $handle->getOldValue();
+ $user = $handle->getUser();
+
if ($oldMailAddress === $user->getEMailAddress()
|| $user->getLastLogin() === 0) {
// Email didn't really change or user didn't login,
diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml
index da97acda4e4..d8e42dff4da 100644
--- a/build/psalm-baseline.xml
+++ b/build/psalm-baseline.xml
@@ -2274,8 +2274,6 @@
-
-