Make the post login event public

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2019-11-20 15:12:52 +01:00
parent 4ddea4bdfb
commit 535000aac6
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
5 changed files with 28 additions and 16 deletions

View File

@ -440,6 +440,7 @@ return array(
'OCP\\User\\Backend\\IProvideAvatarBackend' => $baseDir . '/lib/public/User/Backend/IProvideAvatarBackend.php',
'OCP\\User\\Backend\\ISetDisplayNameBackend' => $baseDir . '/lib/public/User/Backend/ISetDisplayNameBackend.php',
'OCP\\User\\Backend\\ISetPasswordBackend' => $baseDir . '/lib/public/User/Backend/ISetPasswordBackend.php',
'OCP\\User\\Events\\PostLoginEvent' => $baseDir . '/lib/public/User/Events/PostLoginEvent.php',
'OCP\\Util' => $baseDir . '/lib/public/Util.php',
'OCP\\WorkflowEngine\\GenericEntityEvent' => $baseDir . '/lib/public/WorkflowEngine/GenericEntityEvent.php',
'OCP\\WorkflowEngine\\ICheck' => $baseDir . '/lib/public/WorkflowEngine/ICheck.php',
@ -1206,7 +1207,6 @@ return array(
'OC\\Updater\\VersionCheck' => $baseDir . '/lib/private/Updater/VersionCheck.php',
'OC\\User\\Backend' => $baseDir . '/lib/private/User/Backend.php',
'OC\\User\\Database' => $baseDir . '/lib/private/User/Database.php',
'OC\\User\\Events\\PostLoginEvent' => $baseDir . '/lib/private/User/Events/PostLoginEvent.php',
'OC\\User\\LoginException' => $baseDir . '/lib/private/User/LoginException.php',
'OC\\User\\Manager' => $baseDir . '/lib/private/User/Manager.php',
'OC\\User\\NoUserException' => $baseDir . '/lib/private/User/NoUserException.php',

View File

@ -469,6 +469,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\User\\Backend\\IProvideAvatarBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IProvideAvatarBackend.php',
'OCP\\User\\Backend\\ISetDisplayNameBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ISetDisplayNameBackend.php',
'OCP\\User\\Backend\\ISetPasswordBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ISetPasswordBackend.php',
'OCP\\User\\Events\\PostLoginEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/PostLoginEvent.php',
'OCP\\Util' => __DIR__ . '/../../..' . '/lib/public/Util.php',
'OCP\\WorkflowEngine\\GenericEntityEvent' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/GenericEntityEvent.php',
'OCP\\WorkflowEngine\\ICheck' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/ICheck.php',
@ -1235,7 +1236,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Updater\\VersionCheck' => __DIR__ . '/../../..' . '/lib/private/Updater/VersionCheck.php',
'OC\\User\\Backend' => __DIR__ . '/../../..' . '/lib/private/User/Backend.php',
'OC\\User\\Database' => __DIR__ . '/../../..' . '/lib/private/User/Database.php',
'OC\\User\\Events\\PostLoginEvent' => __DIR__ . '/../../..' . '/lib/private/User/Events/PostLoginEvent.php',
'OC\\User\\LoginException' => __DIR__ . '/../../..' . '/lib/private/User/LoginException.php',
'OC\\User\\Manager' => __DIR__ . '/../../..' . '/lib/private/User/Manager.php',
'OC\\User\\NoUserException' => __DIR__ . '/../../..' . '/lib/private/User/NoUserException.php',

View File

@ -61,6 +61,7 @@ use OCP\IUserSession;
use OCP\Lockdown\ILockdownManager;
use OCP\Security\ISecureRandom;
use OCP\Session\Exceptions\SessionNotAvailableException;
use OCP\User\Events\PostLoginEvent;
use OCP\Util;
use Symfony\Component\EventDispatcher\GenericEvent;
@ -398,13 +399,11 @@ class Session implements IUserSession, Emitter {
$firstTimeLogin = $user->updateLastLoginTimestamp();
}
$postLoginEvent = new OC\User\Events\PostLoginEvent(
$this->dispatcher->dispatchTyped(new PostLoginEvent(
$user,
$loginDetails['password'],
$isToken
);
$this->dispatcher->dispatch(OC\User\Events\PostLoginEvent::class, $postLoginEvent);
));
$this->manager->emit('\OC\User', 'postLogin', [
$user,
$loginDetails['password'],

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
*
@ -22,42 +24,53 @@ declare(strict_types=1);
*
*/
namespace OC\User\Events;
namespace OCP\User\Events;
use OCP\EventDispatcher\Event;
use OCP\IUser;
/**
* @since 18.0.0
*/
class PostLoginEvent extends Event {
/** @var IUser */
private $user;
/** @var string */
private $password;
/** @var bool */
private $isTokenLogin;
/**
* @since 18.0.0
*/
public function __construct(IUser $user, string $password, bool $isTokenLogin) {
parent::__construct();
$this->user = $user;
$this->password = $password;
$this->isTokenLogin = $isTokenLogin;
}
/**
* @since 18.0.0
*/
public function getUser(): IUser {
return $this->user;
}
public function hasPassword(): bool {
return $this->password !== '';
}
/**
* @since 18.0.0
*/
public function getPassword(): string {
return $this->password;
}
public function getIsTokenLogin(): bool {
/**
* @since 18.0.0
*/
public function isTokenLogin(): bool {
return $this->isTokenLogin;
}
}

View File

@ -15,7 +15,7 @@ use OC\Authentication\Token\IProvider;
use OC\Authentication\Token\IToken;
use OC\Security\Bruteforce\Throttler;
use OC\Session\Memory;
use OC\User\Events\PostLoginEvent;
use OCP\User\Events\PostLoginEvent;
use OC\User\Manager;
use OC\User\Session;
use OC\User\User;
@ -264,7 +264,7 @@ class SessionTest extends \Test\TestCase {
$this->callback(function(PostLoginEvent $e) {
return $e->getUser()->getUID() === 'foo' &&
$e->getPassword() === 'bar' &&
$e->getIsTokenLogin() === false;
$e->isTokenLogin() === false;
})
);