Chain.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OC\Authentication\Login;
  25. class Chain {
  26. /** @var PreLoginHookCommand */
  27. private $preLoginHookCommand;
  28. /** @var UserDisabledCheckCommand */
  29. private $userDisabledCheckCommand;
  30. /** @var UidLoginCommand */
  31. private $uidLoginCommand;
  32. /** @var EmailLoginCommand */
  33. private $emailLoginCommand;
  34. /** @var LoggedInCheckCommand */
  35. private $loggedInCheckCommand;
  36. /** @var CompleteLoginCommand */
  37. private $completeLoginCommand;
  38. /** @var CreateSessionTokenCommand */
  39. private $createSessionTokenCommand;
  40. /** @var ClearLostPasswordTokensCommand */
  41. private $clearLostPasswordTokensCommand;
  42. /** @var UpdateLastPasswordConfirmCommand */
  43. private $updateLastPasswordConfirmCommand;
  44. /** @var SetUserTimezoneCommand */
  45. private $setUserTimezoneCommand;
  46. /** @var TwoFactorCommand */
  47. private $twoFactorCommand;
  48. /** @var FinishRememberedLoginCommand */
  49. private $finishRememberedLoginCommand;
  50. public function __construct(PreLoginHookCommand $preLoginHookCommand,
  51. UserDisabledCheckCommand $userDisabledCheckCommand,
  52. UidLoginCommand $uidLoginCommand,
  53. EmailLoginCommand $emailLoginCommand,
  54. LoggedInCheckCommand $loggedInCheckCommand,
  55. CompleteLoginCommand $completeLoginCommand,
  56. CreateSessionTokenCommand $createSessionTokenCommand,
  57. ClearLostPasswordTokensCommand $clearLostPasswordTokensCommand,
  58. UpdateLastPasswordConfirmCommand $updateLastPasswordConfirmCommand,
  59. SetUserTimezoneCommand $setUserTimezoneCommand,
  60. TwoFactorCommand $twoFactorCommand,
  61. FinishRememberedLoginCommand $finishRememberedLoginCommand
  62. ) {
  63. $this->preLoginHookCommand = $preLoginHookCommand;
  64. $this->userDisabledCheckCommand = $userDisabledCheckCommand;
  65. $this->uidLoginCommand = $uidLoginCommand;
  66. $this->emailLoginCommand = $emailLoginCommand;
  67. $this->loggedInCheckCommand = $loggedInCheckCommand;
  68. $this->completeLoginCommand = $completeLoginCommand;
  69. $this->createSessionTokenCommand = $createSessionTokenCommand;
  70. $this->clearLostPasswordTokensCommand = $clearLostPasswordTokensCommand;
  71. $this->updateLastPasswordConfirmCommand = $updateLastPasswordConfirmCommand;
  72. $this->setUserTimezoneCommand = $setUserTimezoneCommand;
  73. $this->twoFactorCommand = $twoFactorCommand;
  74. $this->finishRememberedLoginCommand = $finishRememberedLoginCommand;
  75. }
  76. public function process(LoginData $loginData): LoginResult {
  77. $chain = $this->preLoginHookCommand;
  78. $chain
  79. ->setNext($this->userDisabledCheckCommand)
  80. ->setNext($this->uidLoginCommand)
  81. ->setNext($this->emailLoginCommand)
  82. ->setNext($this->loggedInCheckCommand)
  83. ->setNext($this->completeLoginCommand)
  84. ->setNext($this->createSessionTokenCommand)
  85. ->setNext($this->clearLostPasswordTokensCommand)
  86. ->setNext($this->updateLastPasswordConfirmCommand)
  87. ->setNext($this->setUserTimezoneCommand)
  88. ->setNext($this->twoFactorCommand)
  89. ->setNext($this->finishRememberedLoginCommand);
  90. return $chain->process($loginData);
  91. }
  92. }