Make the post login event public
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
parent
4ddea4bdfb
commit
535000aac6
|
@ -440,6 +440,7 @@ return array(
|
||||||
'OCP\\User\\Backend\\IProvideAvatarBackend' => $baseDir . '/lib/public/User/Backend/IProvideAvatarBackend.php',
|
'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\\ISetDisplayNameBackend' => $baseDir . '/lib/public/User/Backend/ISetDisplayNameBackend.php',
|
||||||
'OCP\\User\\Backend\\ISetPasswordBackend' => $baseDir . '/lib/public/User/Backend/ISetPasswordBackend.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\\Util' => $baseDir . '/lib/public/Util.php',
|
||||||
'OCP\\WorkflowEngine\\GenericEntityEvent' => $baseDir . '/lib/public/WorkflowEngine/GenericEntityEvent.php',
|
'OCP\\WorkflowEngine\\GenericEntityEvent' => $baseDir . '/lib/public/WorkflowEngine/GenericEntityEvent.php',
|
||||||
'OCP\\WorkflowEngine\\ICheck' => $baseDir . '/lib/public/WorkflowEngine/ICheck.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\\Updater\\VersionCheck' => $baseDir . '/lib/private/Updater/VersionCheck.php',
|
||||||
'OC\\User\\Backend' => $baseDir . '/lib/private/User/Backend.php',
|
'OC\\User\\Backend' => $baseDir . '/lib/private/User/Backend.php',
|
||||||
'OC\\User\\Database' => $baseDir . '/lib/private/User/Database.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\\LoginException' => $baseDir . '/lib/private/User/LoginException.php',
|
||||||
'OC\\User\\Manager' => $baseDir . '/lib/private/User/Manager.php',
|
'OC\\User\\Manager' => $baseDir . '/lib/private/User/Manager.php',
|
||||||
'OC\\User\\NoUserException' => $baseDir . '/lib/private/User/NoUserException.php',
|
'OC\\User\\NoUserException' => $baseDir . '/lib/private/User/NoUserException.php',
|
||||||
|
|
|
@ -469,6 +469,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
|
||||||
'OCP\\User\\Backend\\IProvideAvatarBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IProvideAvatarBackend.php',
|
'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\\ISetDisplayNameBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ISetDisplayNameBackend.php',
|
||||||
'OCP\\User\\Backend\\ISetPasswordBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ISetPasswordBackend.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\\Util' => __DIR__ . '/../../..' . '/lib/public/Util.php',
|
||||||
'OCP\\WorkflowEngine\\GenericEntityEvent' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/GenericEntityEvent.php',
|
'OCP\\WorkflowEngine\\GenericEntityEvent' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/GenericEntityEvent.php',
|
||||||
'OCP\\WorkflowEngine\\ICheck' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/ICheck.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\\Updater\\VersionCheck' => __DIR__ . '/../../..' . '/lib/private/Updater/VersionCheck.php',
|
||||||
'OC\\User\\Backend' => __DIR__ . '/../../..' . '/lib/private/User/Backend.php',
|
'OC\\User\\Backend' => __DIR__ . '/../../..' . '/lib/private/User/Backend.php',
|
||||||
'OC\\User\\Database' => __DIR__ . '/../../..' . '/lib/private/User/Database.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\\LoginException' => __DIR__ . '/../../..' . '/lib/private/User/LoginException.php',
|
||||||
'OC\\User\\Manager' => __DIR__ . '/../../..' . '/lib/private/User/Manager.php',
|
'OC\\User\\Manager' => __DIR__ . '/../../..' . '/lib/private/User/Manager.php',
|
||||||
'OC\\User\\NoUserException' => __DIR__ . '/../../..' . '/lib/private/User/NoUserException.php',
|
'OC\\User\\NoUserException' => __DIR__ . '/../../..' . '/lib/private/User/NoUserException.php',
|
||||||
|
|
|
@ -61,6 +61,7 @@ use OCP\IUserSession;
|
||||||
use OCP\Lockdown\ILockdownManager;
|
use OCP\Lockdown\ILockdownManager;
|
||||||
use OCP\Security\ISecureRandom;
|
use OCP\Security\ISecureRandom;
|
||||||
use OCP\Session\Exceptions\SessionNotAvailableException;
|
use OCP\Session\Exceptions\SessionNotAvailableException;
|
||||||
|
use OCP\User\Events\PostLoginEvent;
|
||||||
use OCP\Util;
|
use OCP\Util;
|
||||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
|
|
||||||
|
@ -398,13 +399,11 @@ class Session implements IUserSession, Emitter {
|
||||||
$firstTimeLogin = $user->updateLastLoginTimestamp();
|
$firstTimeLogin = $user->updateLastLoginTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
$postLoginEvent = new OC\User\Events\PostLoginEvent(
|
$this->dispatcher->dispatchTyped(new PostLoginEvent(
|
||||||
$user,
|
$user,
|
||||||
$loginDetails['password'],
|
$loginDetails['password'],
|
||||||
$isToken
|
$isToken
|
||||||
);
|
));
|
||||||
$this->dispatcher->dispatch(OC\User\Events\PostLoginEvent::class, $postLoginEvent);
|
|
||||||
|
|
||||||
$this->manager->emit('\OC\User', 'postLogin', [
|
$this->manager->emit('\OC\User', 'postLogin', [
|
||||||
$user,
|
$user,
|
||||||
$loginDetails['password'],
|
$loginDetails['password'],
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
|
* @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\EventDispatcher\Event;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 18.0.0
|
||||||
|
*/
|
||||||
class PostLoginEvent extends Event {
|
class PostLoginEvent extends Event {
|
||||||
|
|
||||||
/** @var IUser */
|
/** @var IUser */
|
||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $password;
|
private $password;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $isTokenLogin;
|
private $isTokenLogin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 18.0.0
|
||||||
|
*/
|
||||||
public function __construct(IUser $user, string $password, bool $isTokenLogin) {
|
public function __construct(IUser $user, string $password, bool $isTokenLogin) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->password = $password;
|
$this->password = $password;
|
||||||
$this->isTokenLogin = $isTokenLogin;
|
$this->isTokenLogin = $isTokenLogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 18.0.0
|
||||||
|
*/
|
||||||
public function getUser(): IUser {
|
public function getUser(): IUser {
|
||||||
return $this->user;
|
return $this->user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasPassword(): bool {
|
/**
|
||||||
return $this->password !== '';
|
* @since 18.0.0
|
||||||
}
|
*/
|
||||||
|
|
||||||
public function getPassword(): string {
|
public function getPassword(): string {
|
||||||
return $this->password;
|
return $this->password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIsTokenLogin(): bool {
|
/**
|
||||||
|
* @since 18.0.0
|
||||||
|
*/
|
||||||
|
public function isTokenLogin(): bool {
|
||||||
return $this->isTokenLogin;
|
return $this->isTokenLogin;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -15,7 +15,7 @@ use OC\Authentication\Token\IProvider;
|
||||||
use OC\Authentication\Token\IToken;
|
use OC\Authentication\Token\IToken;
|
||||||
use OC\Security\Bruteforce\Throttler;
|
use OC\Security\Bruteforce\Throttler;
|
||||||
use OC\Session\Memory;
|
use OC\Session\Memory;
|
||||||
use OC\User\Events\PostLoginEvent;
|
use OCP\User\Events\PostLoginEvent;
|
||||||
use OC\User\Manager;
|
use OC\User\Manager;
|
||||||
use OC\User\Session;
|
use OC\User\Session;
|
||||||
use OC\User\User;
|
use OC\User\User;
|
||||||
|
@ -264,7 +264,7 @@ class SessionTest extends \Test\TestCase {
|
||||||
$this->callback(function(PostLoginEvent $e) {
|
$this->callback(function(PostLoginEvent $e) {
|
||||||
return $e->getUser()->getUID() === 'foo' &&
|
return $e->getUser()->getUID() === 'foo' &&
|
||||||
$e->getPassword() === 'bar' &&
|
$e->getPassword() === 'bar' &&
|
||||||
$e->getIsTokenLogin() === false;
|
$e->isTokenLogin() === false;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue