| Code Coverage
| Classes and Traits | Functions and Methods | Lines
Total | 100.00% covered (success) | 100.00% | 1 / 1 | 100.00% covered (success) | 100.00% | 5 / 5 | CRAP | 100.00% covered (success) | 100.00% | 16 / 16
Admin | 100.00% covered (success) | 100.00% | 1 / 1 | 100.00% covered (success) | 100.00% | 5 / 5 | 7 | 100.00% covered (success) | 100.00% | 16 / 16
install | 100.00% covered (success) | 100.00% | 1 / 1 | 2 | 100.00% covered (success) | 100.00% | 6 / 6
__construct | 100.00% covered (success) | 100.00% | 1 / 1 | 1 | 100.00% covered (success) | 100.00% | 4 / 4
checkPassword | 100.00% covered (success) | 100.00% | 1 / 1 | 1 | 100.00% covered (success) | 100.00% | 1 / 1
setPassword | 100.00% covered (success) | 100.00% | 1 / 1 | 1 | 100.00% covered (success) | 100.00% | 2 / 2
__set | 100.00% covered (success) | 100.00% | 1 / 1 | 2 | 100.00% covered (success) | 100.00% | 3 / 3

1 | <?php
2 |
3 | namespace Entity;
4 |
5 | class Admin extends ModelBase
6 | {
7 | /**
8 | * Role -> 0 : no access
9 | * -> 1 : read access
10 | * -> 2 : +write access
11 | * -> 3 : +delete /disable access
12 | *
13 | * [0] -> admin (add user, change site configuration)
14 | * [1] -> cms (add / modify / delete pages)
15 | * [2] -> products
16 | * [3] -> orders
17 | * [4] -> translations
18 | *
19 | * '*' Is the site admin, have all rights and no one can change this role
20 | **/
21 | public function install()
22 | {
23 | $dbPrefix = $this->getDbPrefix();
24 | $result = self::$dbo->exec("CREATE TABLE IF NOT EXISTS `{$dbPrefix}admin` (
25 | `id` INTEGER(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
26 | `email` VARCHAR(128) NOT NULL UNIQUE,
27 | `password` VARCHAR(64),
28 | `role` VARCHAR(8) NOT NULL DEFAULT '00000',
29 | `lastConnect` DATETIME NOT NULL,
30 | `lastConnectIp` VARCHAR(42) NOT NULL
31 | )");
32 | if ($result === false)
33 | throw new \Exception(get_class().": ".self::$dbo->errorInfo()[2]);
34 | return true;
35 | }
36 |
37 | public function __construct($id = null)
38 | {
39 | $this->lastConnect = new \DateTime();
40 | $this->lastConnectIp = \Tools\Context::getContext()->ip;
41 | parent::__construct($id);
42 | }
43 |
44 | public function checkPassword($value)
45 | {
46 | return password_verify($value, $this->password);
47 | }
48 |
49 | public function setPassword($value)
50 | {
51 | parent::__set("password", password_hash($value, PASSWORD_BCRYPT));
52 | }
53 |
54 | public function __set($key, $value)
55 | {
56 | if ($key == "password")
57 | return $this->setPassword($value);
58 | return parent::__set($key, $value);
59 | }
60 | }
61 |