Compare and store the login name via the event

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-12-18 14:46:41 +01:00
parent 0c7f0a7d89
commit 85781d8d36
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
3 changed files with 19 additions and 5 deletions

View File

@ -51,11 +51,14 @@ class StorePasswordListener implements IEventListener {
}
$stored = $this->credentialsManager->retrieve($event->getUser()->getUID(), LoginCredentials::CREDENTIALS_IDENTIFIER);
$update = $stored['password'] !== $event->getPassword();
if (!$update && $event instanceof UserLoggedInEvent) {
$update = $stored['user'] !== $event->getLoginName();
}
if ($stored && ($stored['user'] !== $event->getUser()->getUID()
|| $stored['password'] !== $event->getPassword())) {
if ($stored && $update) {
$credentials = [
'user' => $event->getUser()->getUID(),
'user' => $event->getLoginName(),
'password' => $event->getPassword()
];

View File

@ -569,7 +569,7 @@ class Server extends ServerContainer implements IServerContainer {
/** @var IEventDispatcher $dispatcher */
$dispatcher = $this->query(IEventDispatcher::class);
$dispatcher->dispatchTyped(new UserLoggedInEvent($user, $password, $isTokenLogin));
$dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin));
});
$userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
/** @var IEventDispatcher $dispatcher */

View File

@ -43,14 +43,18 @@ class UserLoggedInEvent extends Event {
/** @var bool */
private $isTokenLogin;
/** @var string */
private $loginName;
/**
* @since 18.0.0
*/
public function __construct(IUser $user, string $password, bool $isTokenLogin) {
public function __construct(IUser $user, string $loginName, string $password, bool $isTokenLogin) {
parent::__construct();
$this->user = $user;
$this->password = $password;
$this->isTokenLogin = $isTokenLogin;
$this->loginName = $loginName;
}
/**
@ -60,6 +64,13 @@ class UserLoggedInEvent extends Event {
return $this->user;
}
/**
* @since 21.0.0
*/
public function getLoginName(): string {
return $this->loginName;
}
/**
* @since 18.0.0
*/