| 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
User | 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 User extends ModelBase
6 | {
7 | public function install()
8 | {
9 | $dbPrefix = $this->getDbPrefix();
10 | $result = self::$dbo->exec("CREATE TABLE IF NOT EXISTS `{$dbPrefix}user` (
11 | `id` INTEGER(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
12 | `email` VARCHAR(128) NOT NULL UNIQUE,
13 | `password` VARCHAR(64),
14 | `sexe` ENUM('MALE', 'FEMALE') NULL,
15 | `optin` BOOLEAN DEFAULT FALSE,
16 | `register` DATETIME NOT NULL,
17 | `lastConnect` DATETIME NOT NULL,
18 | `lastVisit` DATETIME NOT NULL,
19 | `registerIp` VARCHAR(42) NOT NULL,
20 | `lastConnectIp` VARCHAR(42) NOT NULL,
21 | `lastVisitIp` VARCHAR(42) NOT NULL
22 | )");
23 | if ($result === false)
24 | throw new \Exception(get_class().": ".self::$dbo->errorInfo()[2]);
25 | return true;
26 | }
27 |
28 | public function __construct($id = null)
29 | {
30 | $this->register = $this->lastVisit = $this->lastConnect = new \DateTime();
31 | $this->registerIp = $this->lastVisitIp = $this->lastConnectIp = \Tools\Context::getContext()->ip;
32 | parent::__construct($id);
33 | }
34 |
35 | public function checkPassword($value)
36 | {
37 | return password_verify($value, $this->password);
38 | }
39 |
40 | public function setPassword($value)
41 | {
42 | parent::__set("password", password_hash($value, PASSWORD_BCRYPT));
43 | }
44 |
45 | public function __set($key, $value)
46 | {
47 | if ($key == "password")
48 | return $this->setPassword($value);
49 | return parent::__set($key, $value);
50 | }
51 | }
52 |