Add proper PostLoginEvent
This can be used by othr mechanisms to listen for this event in a lazy fashion. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
51197ac622
commit
ba60fafb9a
5 changed files with 82 additions and 2 deletions
|
@ -1212,6 +1212,7 @@ 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',
|
||||
|
|
|
@ -1246,6 +1246,7 @@ 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',
|
||||
|
|
|
@ -135,6 +135,7 @@ use OCP\Contacts\ContactsMenu\IActionFactory;
|
|||
use OCP\Contacts\ContactsMenu\IContactsStore;
|
||||
use OCP\Dashboard\IDashboardManager;
|
||||
use OCP\Defaults;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Federation\ICloudFederationFactory;
|
||||
use OCP\Federation\ICloudFederationProviderManager;
|
||||
use OCP\Federation\ICloudIdManager;
|
||||
|
@ -385,7 +386,8 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
$c->getConfig(),
|
||||
$c->getSecureRandom(),
|
||||
$c->getLockdownManager(),
|
||||
$c->getLogger()
|
||||
$c->getLogger(),
|
||||
$c->query(IEventDispatcher::class)
|
||||
);
|
||||
$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
|
||||
\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
|
||||
|
|
63
lib/private/User/Events/PostLoginEvent.php
Normal file
63
lib/private/User/Events/PostLoginEvent.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OC\User\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\IUser;
|
||||
|
||||
class PostLoginEvent extends Event {
|
||||
|
||||
/** @var IUser */
|
||||
private $user;
|
||||
/** @var string */
|
||||
private $password;
|
||||
/** @var bool */
|
||||
private $isTokenLogin;
|
||||
|
||||
|
||||
public function __construct(IUser $user, string $password, bool $isTokenLogin) {
|
||||
parent::__construct();
|
||||
|
||||
$this->user = $user;
|
||||
$this->password = $password;
|
||||
$this->isTokenLogin = $isTokenLogin;
|
||||
}
|
||||
|
||||
public function getUser(): IUser {
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function hasPassword(): bool {
|
||||
return $this->password !== '';
|
||||
}
|
||||
|
||||
public function getPassword(): string {
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function getIsTokenLogin(): bool {
|
||||
return $this->isTokenLogin;
|
||||
}
|
||||
}
|
|
@ -50,6 +50,7 @@ use OC_User;
|
|||
use OC_Util;
|
||||
use OCA\DAV\Connector\Sabre\Auth;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Files\NotPermittedException;
|
||||
use OCP\IConfig;
|
||||
use OCP\ILogger;
|
||||
|
@ -113,6 +114,8 @@ class Session implements IUserSession, Emitter {
|
|||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
/** @var IEventDispatcher */
|
||||
private $dispatcher;
|
||||
|
||||
/**
|
||||
* @param Manager $manager
|
||||
|
@ -131,7 +134,8 @@ class Session implements IUserSession, Emitter {
|
|||
IConfig $config,
|
||||
ISecureRandom $random,
|
||||
ILockdownManager $lockdownManager,
|
||||
ILogger $logger) {
|
||||
ILogger $logger,
|
||||
IEventDispatcher $dispatcher) {
|
||||
$this->manager = $manager;
|
||||
$this->session = $session;
|
||||
$this->timeFactory = $timeFactory;
|
||||
|
@ -140,6 +144,7 @@ class Session implements IUserSession, Emitter {
|
|||
$this->random = $random;
|
||||
$this->lockdownManager = $lockdownManager;
|
||||
$this->logger = $logger;
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -369,6 +374,14 @@ class Session implements IUserSession, Emitter {
|
|||
$this->setToken(null);
|
||||
$firstTimeLogin = $user->updateLastLoginTimestamp();
|
||||
}
|
||||
|
||||
$postLoginEvent = new OC\User\Events\PostLoginEvent(
|
||||
$user,
|
||||
$loginDetails['password'],
|
||||
$isToken
|
||||
);
|
||||
$this->dispatcher->dispatch(OC\User\Events\PostLoginEvent::class, $postLoginEvent);
|
||||
|
||||
$this->manager->emit('\OC\User', 'postLogin', [
|
||||
$user,
|
||||
$loginDetails['password'],
|
||||
|
|
Loading…
Reference in a new issue