Login.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Backend\Controller\Adminhtml\Auth;
  8. use Magento\Framework\App\Action\HttpGetActionInterface as HttpGet;
  9. use Magento\Framework\App\Action\HttpPostActionInterface as HttpPost;
  10. /**
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class Login extends \Magento\Backend\Controller\Adminhtml\Auth implements HttpGet, HttpPost
  15. {
  16. /**
  17. * @var \Magento\Framework\View\Result\PageFactory
  18. */
  19. protected $resultPageFactory;
  20. /**
  21. * Constructor
  22. *
  23. * @param \Magento\Backend\App\Action\Context $context
  24. * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
  25. */
  26. public function __construct(
  27. \Magento\Backend\App\Action\Context $context,
  28. \Magento\Framework\View\Result\PageFactory $resultPageFactory
  29. ) {
  30. $this->resultPageFactory = $resultPageFactory;
  31. parent::__construct($context);
  32. }
  33. /**
  34. * Administrator login action
  35. *
  36. * @return \Magento\Backend\Model\View\Result\Redirect
  37. */
  38. public function execute()
  39. {
  40. if ($this->_auth->isLoggedIn()) {
  41. if ($this->_auth->getAuthStorage()->isFirstPageAfterLogin()) {
  42. $this->_auth->getAuthStorage()->setIsFirstPageAfterLogin(true);
  43. }
  44. return $this->getRedirect($this->_backendUrl->getStartupPageUrl());
  45. }
  46. $requestUrl = $this->getRequest()->getUri();
  47. $backendUrl = $this->getUrl('*');
  48. // redirect according to rewrite rule
  49. if ($requestUrl != $backendUrl) {
  50. return $this->getRedirect($backendUrl);
  51. }
  52. return $this->resultPageFactory->create();
  53. }
  54. /**
  55. * Get redirect response
  56. *
  57. * @param string $path
  58. * @return \Magento\Backend\Model\View\Result\Redirect
  59. */
  60. private function getRedirect($path)
  61. {
  62. /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
  63. $resultRedirect = $this->resultRedirectFactory->create();
  64. $resultRedirect->setPath($path);
  65. return $resultRedirect;
  66. }
  67. }