Login.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Block\Form;
  7. /**
  8. * Customer login form block
  9. *
  10. * @api
  11. * @author Magento Core Team <core@magentocommerce.com>
  12. * @since 100.0.2
  13. */
  14. class Login extends \Magento\Framework\View\Element\Template
  15. {
  16. /**
  17. * @var int
  18. */
  19. private $_username = -1;
  20. /**
  21. * @var \Magento\Customer\Model\Session
  22. */
  23. protected $_customerSession;
  24. /**
  25. * @var \Magento\Customer\Model\Url
  26. */
  27. protected $_customerUrl;
  28. /**
  29. * @param \Magento\Framework\View\Element\Template\Context $context
  30. * @param \Magento\Customer\Model\Session $customerSession
  31. * @param \Magento\Customer\Model\Url $customerUrl
  32. * @param array $data
  33. */
  34. public function __construct(
  35. \Magento\Framework\View\Element\Template\Context $context,
  36. \Magento\Customer\Model\Session $customerSession,
  37. \Magento\Customer\Model\Url $customerUrl,
  38. array $data = []
  39. ) {
  40. parent::__construct($context, $data);
  41. $this->_isScopePrivate = false;
  42. $this->_customerUrl = $customerUrl;
  43. $this->_customerSession = $customerSession;
  44. }
  45. /**
  46. * @return $this
  47. */
  48. protected function _prepareLayout()
  49. {
  50. $this->pageConfig->getTitle()->set(__('Customer Login'));
  51. return parent::_prepareLayout();
  52. }
  53. /**
  54. * Retrieve form posting url
  55. *
  56. * @return string
  57. */
  58. public function getPostActionUrl()
  59. {
  60. return $this->_customerUrl->getLoginPostUrl();
  61. }
  62. /**
  63. * Retrieve password forgotten url
  64. *
  65. * @return string
  66. */
  67. public function getForgotPasswordUrl()
  68. {
  69. return $this->_customerUrl->getForgotPasswordUrl();
  70. }
  71. /**
  72. * Retrieve username for form field
  73. *
  74. * @return string
  75. */
  76. public function getUsername()
  77. {
  78. if (-1 === $this->_username) {
  79. $this->_username = $this->_customerSession->getUsername(true);
  80. }
  81. return $this->_username;
  82. }
  83. /**
  84. * Check if autocomplete is disabled on storefront
  85. *
  86. * @return bool
  87. */
  88. public function isAutocompleteDisabled()
  89. {
  90. return (bool)!$this->_scopeConfig->getValue(
  91. \Magento\Customer\Model\Form::XML_PATH_ENABLE_AUTOCOMPLETE,
  92. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  93. );
  94. }
  95. }