AccountConfirmation.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Model;
  7. use Magento\Store\Model\ScopeInterface;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. use Magento\Framework\Registry;
  10. /**
  11. * Class AccountConfirmation. Checks if email confirmation required for customer.
  12. */
  13. class AccountConfirmation
  14. {
  15. /**
  16. * Configuration path for email confirmation.
  17. */
  18. const XML_PATH_IS_CONFIRM = 'customer/create_account/confirm';
  19. /**
  20. * @var ScopeConfigInterface
  21. */
  22. private $scopeConfig;
  23. /**
  24. * @var Registry
  25. */
  26. private $registry;
  27. /**
  28. * AccountConfirmation constructor.
  29. *
  30. * @param ScopeConfigInterface $scopeConfig
  31. * @param Registry $registry
  32. */
  33. public function __construct(
  34. ScopeConfigInterface $scopeConfig,
  35. Registry $registry
  36. ) {
  37. $this->scopeConfig = $scopeConfig;
  38. $this->registry = $registry;
  39. }
  40. /**
  41. * Check if accounts confirmation is required.
  42. *
  43. * @param int|null $websiteId
  44. * @param int|null $customerId
  45. * @param string $customerEmail
  46. * @return bool
  47. */
  48. public function isConfirmationRequired($websiteId, $customerId, $customerEmail): bool
  49. {
  50. if ($this->canSkipConfirmation($customerId, $customerEmail)) {
  51. return false;
  52. }
  53. return $this->scopeConfig->isSetFlag(
  54. self::XML_PATH_IS_CONFIRM,
  55. ScopeInterface::SCOPE_WEBSITES,
  56. $websiteId
  57. );
  58. }
  59. /**
  60. * Check whether confirmation may be skipped when registering using certain email address.
  61. *
  62. * @param int|null $customerId
  63. * @param string $customerEmail
  64. * @return bool
  65. */
  66. private function canSkipConfirmation($customerId, $customerEmail): bool
  67. {
  68. if (!$customerId) {
  69. return false;
  70. }
  71. /* If an email was used to start the registration process and it is the same email as the one
  72. used to register, then this can skip confirmation.
  73. */
  74. $skipConfirmationIfEmail = $this->registry->registry("skip_confirmation_if_email");
  75. if (!$skipConfirmationIfEmail) {
  76. return false;
  77. }
  78. return strtolower($skipConfirmationIfEmail) === strtolower($customerEmail);
  79. }
  80. }