Skip to content

Commit dcb7819

Browse files
committed
fix(files_external): Properly register event listeners in register method
This is the clean solution, LoginCredentials was the only auth class actually registering stuff in constructor. Signed-off-by: Côme Chilliet <[email protected]>
1 parent 4c8daea commit dcb7819

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

apps/files_external/lib/AppInfo/Application.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use OCA\Files_External\Lib\Config\IBackendProvider;
4343
use OCA\Files_External\Listener\GroupDeletedListener;
4444
use OCA\Files_External\Listener\LoadAdditionalListener;
45+
use OCA\Files_External\Listener\StorePasswordListener;
4546
use OCA\Files_External\Listener\UserDeletedListener;
4647
use OCA\Files_External\Service\BackendService;
4748
use OCP\AppFramework\App;
@@ -51,7 +52,9 @@
5152
use OCP\AppFramework\QueryException;
5253
use OCP\Files\Config\IMountProviderCollection;
5354
use OCP\Group\Events\GroupDeletedEvent;
55+
use OCP\User\Events\PasswordUpdatedEvent;
5456
use OCP\User\Events\UserDeletedEvent;
57+
use OCP\User\Events\UserLoggedInEvent;
5558

5659
/**
5760
* @package OCA\Files_External\AppInfo
@@ -72,6 +75,8 @@ public function register(IRegistrationContext $context): void {
7275
$context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
7376
$context->registerEventListener(GroupDeletedEvent::class, GroupDeletedListener::class);
7477
$context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);
78+
$context->registerEventListener(UserLoggedInEvent::class, StorePasswordListener::class);
79+
$context->registerEventListener(PasswordUpdatedEvent::class, StorePasswordListener::class);
7580
$context->registerConfigLexicon(ConfigLexicon::class);
7681
}
7782

@@ -86,14 +91,6 @@ public function boot(IBootContext $context): void {
8691
return $userConfigHandler;
8792
});
8893
});
89-
90-
// force-load auth mechanisms since some will register hooks
91-
// TODO: obsolete these and use the TokenProvider to get the user's password from the session
92-
$objects = $this->getAuthMechanisms();
93-
foreach ($objects as $object) {
94-
/* Use the object to trigger DI on PHP >= 8.4 */
95-
get_object_vars($object);
96-
}
9794
}
9895

9996
/**

apps/files_external/lib/Lib/Auth/Password/LoginCredentials.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@
1111
use OCA\Files_External\Lib\DefinitionParameter;
1212
use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
1313
use OCA\Files_External\Lib\StorageConfig;
14-
use OCA\Files_External\Listener\StorePasswordListener;
1514
use OCP\Authentication\Exceptions\CredentialsUnavailableException;
1615
use OCP\Authentication\LoginCredentials\IStore as CredentialsStore;
17-
use OCP\EventDispatcher\IEventDispatcher;
1816
use OCP\IL10N;
1917
use OCP\ISession;
2018
use OCP\IUser;
2119
use OCP\IUserBackend;
2220
use OCP\LDAP\ILDAPProviderFactory;
2321
use OCP\Security\ICredentialsManager;
24-
use OCP\User\Events\PasswordUpdatedEvent;
25-
use OCP\User\Events\UserLoggedInEvent;
2622

2723
/**
2824
* Username and password from login credentials, saved in DB
@@ -35,7 +31,6 @@ public function __construct(
3531
protected ISession $session,
3632
protected ICredentialsManager $credentialsManager,
3733
private CredentialsStore $credentialsStore,
38-
IEventDispatcher $eventDispatcher,
3934
private ILDAPProviderFactory $ldapFactory,
4035
) {
4136
$this
@@ -48,9 +43,6 @@ public function __construct(
4843
->setFlag(DefinitionParameter::FLAG_HIDDEN)
4944
->setFlag(DefinitionParameter::FLAG_OPTIONAL),
5045
]);
51-
52-
$eventDispatcher->addServiceListener(UserLoggedInEvent::class, StorePasswordListener::class);
53-
$eventDispatcher->addServiceListener(PasswordUpdatedEvent::class, StorePasswordListener::class);
5446
}
5547

5648
private function getCredentials(IUser $user): array {

0 commit comments

Comments
 (0)