ecom
E-commerce cms
 All Data Structures Namespaces Files Functions Variables
User.php
Go to the documentation of this file.
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 
install()
Definition: User.php:7
static getContext()
Definition: Context.php:155
__set($key, $value)
Definition: User.php:45
setPassword($value)
Definition: User.php:40
checkPassword($value)
Definition: User.php:35
__construct($id=null)
Definition: User.php:28