|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* A two factor authentication module that protects both the admin and customer logins |
|
4
|
|
|
* Copyright (C) 2017 Ross Mitchell |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of Rossmitchell/Twofactor. |
|
7
|
|
|
* |
|
8
|
|
|
* Rossmitchell/Twofactor is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU General Public License as published by |
|
10
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
11
|
|
|
* (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU General Public License |
|
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace Rossmitchell\Twofactor\Controller\Customerlogin; |
|
23
|
|
|
|
|
24
|
|
|
use Magento\Framework\App\Action\Context; |
|
25
|
|
|
use Magento\Framework\Controller\ResultInterface; |
|
26
|
|
|
use Magento\Framework\View\Result\PageFactory; |
|
27
|
|
|
use Rossmitchell\Twofactor\Model\Config\Customer as CustomerAdmin; |
|
28
|
|
|
use Rossmitchell\Twofactor\Model\Customer\Attribute\IsUsingTwoFactor; |
|
29
|
|
|
use Rossmitchell\Twofactor\Model\Customer\Customer; |
|
30
|
|
|
use Rossmitchell\Twofactor\Model\TwoFactorUrls; |
|
31
|
|
|
use Rossmitchell\Twofactor\Model\Urls\Fetcher; |
|
32
|
|
|
|
|
33
|
|
View Code Duplication |
class Index extends AbstractController |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
|
|
/** @var PageFactory */ |
|
36
|
|
|
private $resultPageFactory; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Index constructor. |
|
40
|
|
|
* |
|
41
|
|
|
* @param Context $context |
|
42
|
|
|
* @param CustomerAdmin $customerAdmin |
|
43
|
|
|
* @param Customer $customerGetter |
|
44
|
|
|
* @param Fetcher $fetcher |
|
45
|
|
|
* @param IsUsingTwoFactor $isUsingTwoFactor |
|
46
|
|
|
* @param PageFactory $resultPageFactory |
|
47
|
|
|
*/ |
|
48
|
2 |
|
public function __construct( |
|
49
|
|
|
Context $context, |
|
50
|
|
|
CustomerAdmin $customerAdmin, |
|
51
|
|
|
Customer $customerGetter, |
|
52
|
|
|
Fetcher $fetcher, |
|
53
|
|
|
IsUsingTwoFactor $isUsingTwoFactor, |
|
54
|
|
|
PageFactory $resultPageFactory |
|
55
|
|
|
) { |
|
56
|
2 |
|
parent::__construct($context, $customerAdmin, $customerGetter, $fetcher, $isUsingTwoFactor); |
|
57
|
2 |
|
$this->resultPageFactory = $resultPageFactory; |
|
58
|
2 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Execute view action |
|
62
|
|
|
* |
|
63
|
|
|
* @return ResultInterface |
|
64
|
|
|
*/ |
|
65
|
2 |
|
public function execute() |
|
66
|
|
|
{ |
|
67
|
2 |
|
if ($this->shouldActionBeRun() === false) { |
|
68
|
1 |
|
return $this->getRedirectAction(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
return $this->resultPageFactory->create(); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.