|
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\Tests\Integration\FixtureLoader; |
|
23
|
|
|
|
|
24
|
|
|
use Magento\User\Model\UserFactory; |
|
25
|
|
|
|
|
26
|
|
|
class AdminUser extends AbstractLoader |
|
27
|
|
|
{ |
|
28
|
|
|
|
|
29
|
|
|
public function loadData() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->setSecureArea(); |
|
32
|
|
|
/** @var UserFactory $userFactory */ |
|
33
|
|
|
$userFactory = $this->createObject(UserFactory::class); |
|
34
|
|
|
foreach ($this->data as $userData) { |
|
35
|
|
|
$user = $userFactory->create(); |
|
36
|
|
|
foreach ($userData as $key => $value) { |
|
37
|
|
|
$user->setData($key, $value); |
|
38
|
|
|
} |
|
39
|
|
|
$user->save(); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function rollBackData() |
|
44
|
|
|
{ |
|
45
|
|
|
/** @var UserFactory $userFactory */ |
|
46
|
|
|
$userFactory = $this->createObject(UserFactory::class); |
|
47
|
|
|
foreach ($this->data as $userData) { |
|
48
|
|
|
$user = $userFactory->create(); |
|
49
|
|
|
$user->loadByUsername($userData['username']); |
|
50
|
|
|
$user->delete(); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function verifyData() |
|
55
|
|
|
{ |
|
56
|
|
|
foreach ($this->data as $userData) { |
|
57
|
|
|
if (isset($userData['user_id'])) { |
|
58
|
|
|
throw new \Exception('You can not set a user_id for an admin user - it prevents them saving'); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$requiredAttributes = ['username', 'password']; |
|
62
|
|
|
|
|
63
|
|
|
foreach ($requiredAttributes as $attribute) { |
|
64
|
|
|
if (!isset($userData[$attribute])) { |
|
65
|
|
|
throw new \Exception("You must set a value for $attribute"); |
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|