mirror of
https://github.com/nextcloud/server.git
synced 2026-05-26 11:22:28 -04:00
Merge pull request #37479 from nextcloud/backport/37071/37071-stable25
[stable25] dispatch BeforeUserLoggedInEvent
This commit is contained in:
commit
ca80e7e709
2 changed files with 29 additions and 4 deletions
|
|
@ -40,6 +40,7 @@ use OC\User\LoginException;
|
|||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\ILogger;
|
||||
use OCP\IUserManager;
|
||||
use OCP\User\Events\BeforeUserLoggedInEvent;
|
||||
use OCP\User\Events\UserLoggedInEvent;
|
||||
|
||||
/**
|
||||
|
|
@ -172,6 +173,10 @@ class OC_User {
|
|||
if (self::getUser() !== $uid) {
|
||||
self::setUserId($uid);
|
||||
$userSession = \OC::$server->getUserSession();
|
||||
|
||||
/** @var IEventDispatcher $dispatcher */
|
||||
$dispatcher = \OC::$server->get(IEventDispatcher::class);
|
||||
|
||||
if ($userSession->getUser() && !$userSession->getUser()->isEnabled()) {
|
||||
$message = \OC::$server->getL10N('lib')->t('User disabled');
|
||||
throw new LoginException($message);
|
||||
|
|
@ -182,6 +187,10 @@ class OC_User {
|
|||
if ($backend instanceof \OCP\Authentication\IProvideUserSecretBackend) {
|
||||
$password = $backend->getCurrentUserSecret();
|
||||
}
|
||||
|
||||
/** @var IEventDispatcher $dispatcher */
|
||||
$dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password, $backend));
|
||||
|
||||
$userSession->createSessionToken($request, $uid, $uid, $password);
|
||||
$userSession->createRememberMeToken($userSession->getUser());
|
||||
// setup the filesystem
|
||||
|
|
@ -199,8 +208,6 @@ class OC_User {
|
|||
'isTokenLogin' => false,
|
||||
]
|
||||
);
|
||||
/** @var IEventDispatcher $dispatcher */
|
||||
$dispatcher = \OC::$server->get(IEventDispatcher::class);
|
||||
$dispatcher->dispatchTyped(new UserLoggedInEvent(
|
||||
\OC::$server->get(IUserManager::class)->get($uid),
|
||||
$uid,
|
||||
|
|
|
|||
|
|
@ -24,8 +24,10 @@ declare(strict_types=1);
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCP\User\Events;
|
||||
|
||||
use OCP\Authentication\IApacheBackend;
|
||||
use OCP\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
|
|
@ -39,13 +41,18 @@ class BeforeUserLoggedInEvent extends Event {
|
|||
/** @var string */
|
||||
private $password;
|
||||
|
||||
/** @var IApacheBackend|null */
|
||||
private $backend;
|
||||
|
||||
/**
|
||||
* @since 18.0.0
|
||||
* @since 26.0.0 password can be null
|
||||
*/
|
||||
public function __construct(string $username, string $password) {
|
||||
public function __construct(string $username, ?string $password, ?IApacheBackend $backend = null) {
|
||||
parent::__construct();
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
$this->backend = $backend;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -59,8 +66,19 @@ class BeforeUserLoggedInEvent extends Event {
|
|||
|
||||
/**
|
||||
* @since 18.0.0
|
||||
* @since 26.0.0 value can be null
|
||||
*/
|
||||
public function getPassword(): string {
|
||||
public function getPassword(): ?string {
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* return backend if available (or null)
|
||||
*
|
||||
* @return IApacheBackend|null
|
||||
* @since 26.0.0
|
||||
*/
|
||||
public function getBackend(): ?IApacheBackend {
|
||||
return $this->backend;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue