-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.php
80 lines (72 loc) · 1.75 KB
/
User.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
declare(strict_types=1);
namespace DataCenter\Model\Entity;
use Authentication\IdentityInterface;
use Authentication\PasswordHasher\DefaultPasswordHasher;
use Cake\ORM\Entity;
/**
* User Entity
*
* @property int $id
* @property string $email
* @property string $password
* @property string $token
* @property \Cake\I18n\FrozenTime $token_expires
*/
class User extends Entity implements IdentityInterface
{
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
* be mass assigned. For security purposes, it is advised to set '*' to false
* (or remove it), and explicitly make individual fields accessible as needed.
*
* @var array
*/
protected $_accessible = [
'email' => true,
'password' => true,
'created' => true,
'modified' => true,
];
/**
* Fields that are excluded from JSON versions of the entity.
*
* @var array
*/
protected $_hidden = [
'password',
];
/**
* Automatically hash non-blank passwords
*
* @param string $password Password
* @return string|null
*/
protected function _setPassword(string $password): ?string
{
if (strlen($password) > 0) {
return (new DefaultPasswordHasher())->hash($password);
}
return null;
}
/**
* Authentication\IdentityInterface method
*
* @return int
*/
public function getIdentifier(): int
{
return $this->id;
}
/**
* Authentication\IdentityInterface method
*
* @return \ArrayAccess|array
*/
public function getOriginalData()
{
return $this;
}
}