LoggedInCheckCommand.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Authentication\Login;
  8. use OC\Authentication\Events\LoginFailed;
  9. use OC\Core\Controller\LoginController;
  10. use OCP\EventDispatcher\IEventDispatcher;
  11. use Psr\Log\LoggerInterface;
  12. class LoggedInCheckCommand extends ALoginCommand {
  13. /** @var LoggerInterface */
  14. private $logger;
  15. /** @var IEventDispatcher */
  16. private $dispatcher;
  17. public function __construct(LoggerInterface $logger,
  18. IEventDispatcher $dispatcher) {
  19. $this->logger = $logger;
  20. $this->dispatcher = $dispatcher;
  21. }
  22. public function process(LoginData $loginData): LoginResult {
  23. if ($loginData->getUser() === false) {
  24. $loginName = $loginData->getUsername();
  25. $password = $loginData->getPassword();
  26. $ip = $loginData->getRequest()->getRemoteAddress();
  27. $this->logger->warning("Login failed: $loginName (Remote IP: $ip)");
  28. $this->dispatcher->dispatchTyped(new LoginFailed($loginName, $password));
  29. return LoginResult::failure($loginData, LoginController::LOGIN_MSG_INVALIDPASSWORD);
  30. }
  31. return $this->processNextOrFinishSuccessfully($loginData);
  32. }
  33. }