summaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2020-05-20 15:54:16 +0200
committerMorris Jobke <hey@morrisjobke.de>2020-07-30 11:43:15 +0200
commitd1bd3ba594e2ee949a29a0ce53aaa6ba78aaf354 (patch)
tree01df237c7705334982644df210c7e178b8d27150 /apps/files_external/lib
parentc864e5dfc245e1de1bed6b73e11e5b3a4cdf65b7 (diff)
downloadnextcloud-server-d1bd3ba594e2ee949a29a0ce53aaa6ba78aaf354.tar.gz
nextcloud-server-d1bd3ba594e2ee949a29a0ce53aaa6ba78aaf354.zip
update saved credentials on password change
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_external/lib')
-rw-r--r--apps/files_external/lib/Lib/Auth/Password/LoginCredentials.php28
1 files changed, 27 insertions, 1 deletions
diff --git a/apps/files_external/lib/Lib/Auth/Password/LoginCredentials.php b/apps/files_external/lib/Lib/Auth/Password/LoginCredentials.php
index b8dace8bf53..5ea4a698208 100644
--- a/apps/files_external/lib/Lib/Auth/Password/LoginCredentials.php
+++ b/apps/files_external/lib/Lib/Auth/Password/LoginCredentials.php
@@ -29,10 +29,13 @@ use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
use OCA\Files_External\Lib\StorageConfig;
use OCP\Authentication\Exceptions\CredentialsUnavailableException;
use OCP\Authentication\LoginCredentials\IStore as CredentialsStore;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IL10N;
use OCP\ISession;
use OCP\IUser;
use OCP\Security\ICredentialsManager;
+use OCP\User\Events\PasswordUpdatedEvent;
+use OCP\User\Events\UserLoggedInEvent;
/**
* Username and password from login credentials, saved in DB
@@ -49,7 +52,7 @@ class LoginCredentials extends AuthMechanism {
/** @var CredentialsStore */
private $credentialsStore;
- public function __construct(IL10N $l, ISession $session, ICredentialsManager $credentialsManager, CredentialsStore $credentialsStore) {
+ public function __construct(IL10N $l, ISession $session, ICredentialsManager $credentialsManager, CredentialsStore $credentialsStore, IEventDispatcher $eventDispatcher) {
$this->session = $session;
$this->credentialsManager = $credentialsManager;
$this->credentialsStore = $credentialsStore;
@@ -60,6 +63,29 @@ class LoginCredentials extends AuthMechanism {
->setText($l->t('Log-in credentials, save in database'))
->addParameters([
]);
+
+ $eventDispatcher->addListener(UserLoggedInEvent::class, [$this, 'updateCredentials']);
+ $eventDispatcher->addListener(PasswordUpdatedEvent::class, [$this, 'updateCredentials']);
+ }
+
+ /**
+ * @param UserLoggedInEvent | PasswordUpdatedEvent $event
+ */
+ public function updateCredentials($event) {
+ if ($event instanceof UserLoggedInEvent && $event->isTokenLogin()) {
+ return;
+ }
+
+ $stored = $this->credentialsManager->retrieve($event->getUser()->getUID(), self::CREDENTIALS_IDENTIFIER);
+
+ if ($stored && $stored['password'] != $event->getPassword()) {
+ $credentials = [
+ 'user' => $stored['user'],
+ 'password' => $event->getPassword()
+ ];
+
+ $this->credentialsManager->store($event->getUser()->getUID(), self::CREDENTIALS_IDENTIFIER, $credentials);
+ }
}
private function getCredentials(IUser $user): array {