update saved credentials on password change
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
c864e5dfc2
commit
d1bd3ba594
|
@ -29,10 +29,13 @@ use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
|
||||||
use OCA\Files_External\Lib\StorageConfig;
|
use OCA\Files_External\Lib\StorageConfig;
|
||||||
use OCP\Authentication\Exceptions\CredentialsUnavailableException;
|
use OCP\Authentication\Exceptions\CredentialsUnavailableException;
|
||||||
use OCP\Authentication\LoginCredentials\IStore as CredentialsStore;
|
use OCP\Authentication\LoginCredentials\IStore as CredentialsStore;
|
||||||
|
use OCP\EventDispatcher\IEventDispatcher;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\ISession;
|
use OCP\ISession;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\Security\ICredentialsManager;
|
use OCP\Security\ICredentialsManager;
|
||||||
|
use OCP\User\Events\PasswordUpdatedEvent;
|
||||||
|
use OCP\User\Events\UserLoggedInEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Username and password from login credentials, saved in DB
|
* Username and password from login credentials, saved in DB
|
||||||
|
@ -49,7 +52,7 @@ class LoginCredentials extends AuthMechanism {
|
||||||
/** @var CredentialsStore */
|
/** @var CredentialsStore */
|
||||||
private $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->session = $session;
|
||||||
$this->credentialsManager = $credentialsManager;
|
$this->credentialsManager = $credentialsManager;
|
||||||
$this->credentialsStore = $credentialsStore;
|
$this->credentialsStore = $credentialsStore;
|
||||||
|
@ -60,6 +63,29 @@ class LoginCredentials extends AuthMechanism {
|
||||||
->setText($l->t('Log-in credentials, save in database'))
|
->setText($l->t('Log-in credentials, save in database'))
|
||||||
->addParameters([
|
->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 {
|
private function getCredentials(IUser $user): array {
|
||||||
|
|
Loading…
Reference in New Issue