ecom
E-commerce cms
 All Data Structures Namespaces Files Functions Variables
Admin.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Entity;
4 
5 class Admin extends ModelBase
6 {
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 
static getContext()
Definition: Context.php:155
__set($key, $value)
Definition: Admin.php:54
checkPassword($value)
Definition: Admin.php:44
__construct($id=null)
Definition: Admin.php:37
setPassword($value)
Definition: Admin.php:49