|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* A Magento 2 module named Rossmitchell/Twofactor |
|
4
|
|
|
* Copyright (C) 2017 |
|
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\Model\Api\Requests; |
|
23
|
|
|
|
|
24
|
|
|
use Magento\Framework\Exception\AuthenticationException; |
|
25
|
|
|
use Rossmitchell\Twofactor\Api\Request\GetQrCodeManagementInterface; |
|
26
|
|
|
use Rossmitchell\Twofactor\Api\Response\GetQrCodeInterface; |
|
27
|
|
|
use Rossmitchell\Twofactor\Model\Api\ResponseBuilder\GetQrCode; |
|
28
|
|
|
use Rossmitchell\Twofactor\Model\Customer\Customer; |
|
29
|
|
|
|
|
30
|
|
|
class GetQrCodeManagement implements GetQrCodeManagementInterface |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @var GetQrCode |
|
34
|
|
|
*/ |
|
35
|
|
|
private $responseBuilder; |
|
36
|
|
|
/** |
|
37
|
|
|
* @var Customer |
|
38
|
|
|
*/ |
|
39
|
|
|
private $customer; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* GetQrCodeManagement constructor. |
|
43
|
|
|
* |
|
44
|
|
|
* @param Customer $customer |
|
45
|
|
|
* @param GetQrCode $responseBuilder |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct( |
|
48
|
|
|
Customer $customer, |
|
49
|
|
|
GetQrCode $responseBuilder |
|
50
|
|
|
) { |
|
51
|
|
|
$this->responseBuilder = $responseBuilder; |
|
52
|
|
|
$this->customer = $customer; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* GET for getQrCode api |
|
57
|
|
|
* @return GetQrCodeInterface |
|
58
|
|
|
* @throws AuthenticationException |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getQrCode() |
|
61
|
|
|
{ |
|
62
|
|
|
$customer = $this->customer->getCustomer(); |
|
63
|
|
|
if ($customer === false) { |
|
64
|
|
|
throw new AuthenticationException(__('Could not find a customer')); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $this->responseBuilder->buildResponseForCustomer($customer); |
|
68
|
|
|
|
|
69
|
|
|
$hasTwoFactor = $this->isUsingTwoFactor->hasValue($customer); |
|
|
|
|
|
|
70
|
|
|
$response->setEmail($customer->getEmail()); |
|
71
|
|
|
if ($hasTwoFactor === false) { |
|
72
|
|
|
$response->setIsUsingTwoFactor(false); |
|
73
|
|
|
|
|
74
|
|
|
return $response; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$isUsingTwoFactor = $this->isUsingTwoFactor->getValue($customer); |
|
78
|
|
|
$response->setIsUsingTwoFactor($isUsingTwoFactor); |
|
79
|
|
|
if ($isUsingTwoFactor === true) { |
|
80
|
|
|
$secret = $this->twoFactorSecret->getValue($customer); |
|
81
|
|
|
$response->setQrCode($this->qrCode->displayCurrentCode($secret)); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return $response; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return,dieorexitstatements that have been added for debug purposes.In the above example, the last
return falsewill never be executed, because a return statement has already been met in every possible execution path.