|
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\Setup; |
|
23
|
|
|
|
|
24
|
|
|
use Magento\Framework\Setup\InstallSchemaInterface; |
|
25
|
|
|
use Magento\Framework\Setup\ModuleContextInterface; |
|
26
|
|
|
use Magento\Framework\Setup\SchemaSetupInterface; |
|
27
|
|
|
use Rossmitchell\Twofactor\Model\Admin\Attribute\IsUsingTwoFactor; |
|
28
|
|
|
use Rossmitchell\Twofactor\Model\Admin\Attribute\TwoFactorSecret; |
|
29
|
|
|
|
|
30
|
|
|
class InstallSchema implements InstallSchemaInterface |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* Installs DB schema for a module |
|
34
|
|
|
* |
|
35
|
|
|
* @param SchemaSetupInterface $setup |
|
36
|
|
|
* @param ModuleContextInterface $context |
|
37
|
|
|
* |
|
38
|
|
|
* @return void |
|
39
|
|
|
*/ |
|
40
|
|
|
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) |
|
41
|
|
|
{ |
|
42
|
|
|
$installer = $setup; |
|
43
|
|
|
$installer->startSetup(); |
|
44
|
|
|
$version = $context->getVersion(); |
|
45
|
|
|
|
|
46
|
|
|
if (version_compare($version, '0.0.1') < 0) { |
|
47
|
|
|
$adminTable = $installer->getTable('admin_user'); |
|
48
|
|
|
$this->addUseTwoFactorColumn($installer, $adminTable); |
|
49
|
|
|
$this->addTwoFactorSecretColumn($installer, $adminTable); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$installer->endSetup(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
private function addUseTwoFactorColumn(SchemaSetupInterface $installer, $table) |
|
56
|
|
|
{ |
|
57
|
|
|
$installer->getConnection()->addColumn( |
|
58
|
|
|
$table, |
|
59
|
|
|
IsUsingTwoFactor::ATTRIBUTE_CODE, |
|
60
|
|
|
[ |
|
61
|
|
|
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, |
|
62
|
|
|
'nullable' => true, |
|
63
|
|
|
'default' => 0, |
|
64
|
|
|
'comment' => 'Use Two Factor Authentication', |
|
65
|
|
|
] |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
private function addTwoFactorSecretColumn(SchemaSetupInterface $installer, $table) |
|
70
|
|
|
{ |
|
71
|
|
|
$installer->getConnection()->addColumn( |
|
72
|
|
|
$table, |
|
73
|
|
|
TwoFactorSecret::ATTRIBUTE_CODE, |
|
74
|
|
|
[ |
|
75
|
|
|
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, |
|
76
|
|
|
'nullable' => true, |
|
77
|
|
|
'comment' => 'Two Factor Secret', |
|
78
|
|
|
] |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|