2019-05-03 09:09:19 -04:00
|
|
|
<?php
|
2021-06-04 15:52:51 -04:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2019-05-03 09:09:19 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2019-05-03 09:09:19 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\Authentication\Login;
|
|
|
|
|
|
2020-03-07 10:18:21 -05:00
|
|
|
use OC\Authentication\Events\LoginFailed;
|
2019-05-03 09:09:19 -04:00
|
|
|
use OC\Core\Controller\LoginController;
|
2020-03-07 10:18:21 -05:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2020-10-12 11:14:25 -04:00
|
|
|
use Psr\Log\LoggerInterface;
|
2019-05-03 09:09:19 -04:00
|
|
|
|
|
|
|
|
class LoggedInCheckCommand extends ALoginCommand {
|
2025-11-17 09:32:54 -05:00
|
|
|
public function __construct(
|
|
|
|
|
private LoggerInterface $logger,
|
|
|
|
|
private IEventDispatcher $dispatcher,
|
|
|
|
|
) {
|
2019-05-03 09:09:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function process(LoginData $loginData): LoginResult {
|
|
|
|
|
if ($loginData->getUser() === false) {
|
2020-03-07 10:18:21 -05:00
|
|
|
$loginName = $loginData->getUsername();
|
2022-11-22 16:43:01 -05:00
|
|
|
$password = $loginData->getPassword();
|
2019-05-03 09:09:19 -04:00
|
|
|
$ip = $loginData->getRequest()->getRemoteAddress();
|
|
|
|
|
|
2020-03-07 10:18:21 -05:00
|
|
|
$this->logger->warning("Login failed: $loginName (Remote IP: $ip)");
|
|
|
|
|
|
2022-11-22 16:43:01 -05:00
|
|
|
$this->dispatcher->dispatchTyped(new LoginFailed($loginName, $password));
|
2019-05-03 09:09:19 -04:00
|
|
|
|
|
|
|
|
return LoginResult::failure($loginData, LoginController::LOGIN_MSG_INVALIDPASSWORD);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->processNextOrFinishSuccessfully($loginData);
|
|
|
|
|
}
|
|
|
|
|
}
|