|
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\Traits; |
|
23
|
|
|
|
|
24
|
|
|
use Magento\Framework\Exception\InputException; |
|
25
|
|
|
|
|
26
|
|
|
trait SessionTrait |
|
27
|
|
|
{ |
|
28
|
|
|
|
|
29
|
6 |
|
public function setData($key, $value) |
|
30
|
|
|
{ |
|
31
|
6 |
|
$methodName = $this->convertKeyToMethodName('set', $key); |
|
32
|
6 |
|
$session = $this->getSession(); |
|
33
|
6 |
|
$session->$methodName($value); |
|
34
|
6 |
|
} |
|
35
|
|
|
|
|
36
|
33 |
|
public function getData($key) |
|
37
|
|
|
{ |
|
38
|
33 |
|
$methodName = $this->convertKeyToMethodName('get', $key); |
|
39
|
33 |
|
$session = $this->getSession(); |
|
40
|
33 |
|
return $session->$methodName(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
2 |
|
public function unsetData($key) |
|
44
|
|
|
{ |
|
45
|
2 |
|
$methodName = $this->convertKeyToMethodName('uns', $key); |
|
46
|
2 |
|
$session = $this->getSession(); |
|
47
|
2 |
|
$session->$methodName($key); |
|
48
|
2 |
|
} |
|
49
|
|
|
|
|
50
|
18 |
|
public function hasData($key) |
|
51
|
|
|
{ |
|
52
|
18 |
|
$methodName = $this->convertKeyToMethodName('has', $key); |
|
53
|
18 |
|
$session = $this->getSession(); |
|
54
|
|
|
|
|
55
|
18 |
|
return $session->$methodName(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
34 |
|
private function convertKeyToMethodName($type, $key) |
|
59
|
|
|
{ |
|
60
|
34 |
|
$allowedMethods = ['get', 'set', 'uns', 'has']; |
|
61
|
34 |
|
if (!in_array($type, $allowedMethods)) { |
|
62
|
|
|
InputException::invalidFieldValue('type', $type); |
|
63
|
|
|
} |
|
64
|
34 |
|
$methodName = $type.str_replace(' ', '', ucwords(str_replace('_', ' ', $key))); |
|
65
|
|
|
|
|
66
|
34 |
|
return $methodName; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
abstract public function getSession(); |
|
70
|
|
|
} |
|
71
|
|
|
|