|
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\Block\Adminhtml\Adminlogin; |
|
23
|
|
|
|
|
24
|
|
|
use Magento\Framework\Message\ManagerInterface; |
|
25
|
|
|
use Magento\Framework\View\Element\Template; |
|
26
|
|
|
use Rossmitchell\Twofactor\Model\TwoFactorUrls; |
|
27
|
|
|
|
|
28
|
|
|
class Index extends Template |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var TwoFactorUrls |
|
32
|
|
|
*/ |
|
33
|
|
|
private $twoFactorUrls; |
|
34
|
|
|
/** |
|
35
|
|
|
* @var ManagerInterface |
|
36
|
|
|
*/ |
|
37
|
|
|
private $messageManager; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Index constructor. |
|
41
|
|
|
* |
|
42
|
|
|
* @param Template\Context $context |
|
43
|
|
|
* @param TwoFactorUrls $twoFactorUrls |
|
44
|
|
|
* @param ManagerInterface $messageManager |
|
45
|
|
|
* @param array $data |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct( |
|
48
|
|
|
Template\Context $context, |
|
49
|
|
|
TwoFactorUrls $twoFactorUrls, |
|
50
|
|
|
ManagerInterface $messageManager, |
|
51
|
|
|
array $data = [] |
|
52
|
|
|
) { |
|
53
|
|
|
parent::__construct($context, $data); |
|
54
|
|
|
$this->twoFactorUrls = $twoFactorUrls; |
|
55
|
|
|
$this->messageManager = $messageManager; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function getVerificationUrl() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->twoFactorUrls->getAuthenticationUrl(true); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function getMessages() |
|
64
|
|
|
{ |
|
65
|
|
|
$messages = []; |
|
66
|
|
|
$collection = $this->messageManager->getMessages(true); |
|
67
|
|
|
if (null === $collection) { |
|
68
|
|
|
return $messages; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
foreach ($collection->getItems() as $message) { |
|
72
|
|
|
$messages[] = $message->getText(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $messages; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|