1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the CRUDlexUser package. |
5
|
|
|
* |
6
|
|
|
* (c) Philip Lehmann-Böhm <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace CRUDlex; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
15
|
|
|
use CRUDlex\Entity; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The UserInterface implementation for the UserProvider. |
19
|
|
|
*/ |
20
|
|
|
class User implements UserInterface { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Holds the actual user data. |
24
|
|
|
*/ |
25
|
|
|
private $userEntity; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The CRUDEntity fieldname of the username. |
29
|
|
|
*/ |
30
|
|
|
protected $usernameField; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The fieldname of the password (hash). |
34
|
|
|
*/ |
35
|
|
|
protected $passwordField; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The fieldname of the password hash salt. |
39
|
|
|
*/ |
40
|
|
|
protected $saltField; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Hold password hash salt. |
44
|
|
|
*/ |
45
|
|
|
private $roles; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Constructor. |
49
|
|
|
* |
50
|
|
|
* @param string $usernameField |
51
|
|
|
* the username |
52
|
|
|
* |
53
|
|
|
* @param string $passwordField |
54
|
|
|
* the password (hash) |
55
|
|
|
* |
56
|
|
|
* @param string $saltField |
57
|
|
|
* the password hash salt |
58
|
|
|
* |
59
|
|
|
* @param Entity $userEntity |
60
|
|
|
* the actual user data |
61
|
|
|
* |
62
|
|
|
* @param array $roles |
63
|
|
|
* the roles |
64
|
|
|
*/ |
65
|
|
|
public function __construct($usernameField, $passwordField, $saltField, Entity $userEntity, array $roles) { |
66
|
|
|
$this->usernameField = $usernameField; |
67
|
|
|
$this->passwordField = $passwordField; |
68
|
|
|
$this->saltField = $saltField; |
69
|
|
|
$this->userEntity = $userEntity; |
70
|
|
|
$this->roles = $roles; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Gets the roles. |
75
|
|
|
* |
76
|
|
|
* @return array |
77
|
|
|
* the roles |
78
|
|
|
*/ |
79
|
|
|
public function getRoles() { |
80
|
|
|
return $this->roles; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Gets the password (hash). |
85
|
|
|
* |
86
|
|
|
* @return string |
87
|
|
|
* the password |
88
|
|
|
*/ |
89
|
|
|
public function getPassword() { |
90
|
|
|
return $this->userEntity->get($this->passwordField); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Gets the password hash salt. |
95
|
|
|
* |
96
|
|
|
* @return string |
97
|
|
|
* the salt |
98
|
|
|
*/ |
99
|
|
|
public function getSalt() { |
100
|
|
|
return $this->userEntity->get($this->saltField); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Gets the username. |
105
|
|
|
* |
106
|
|
|
* @return string |
107
|
|
|
* the username |
108
|
|
|
*/ |
109
|
|
|
public function getUsername() { |
110
|
|
|
return $this->userEntity->get($this->usernameField); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Should erase some crucial data if needed. But nothing to do here in this |
115
|
|
|
* implementation. |
116
|
|
|
*/ |
117
|
|
|
public function eraseCredentials() { |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Gets the user entity holding all data. |
122
|
|
|
* |
123
|
|
|
* @return Entity |
124
|
|
|
* the user entity |
125
|
|
|
*/ |
126
|
|
|
public function getUserEntity() { |
127
|
|
|
return $this->userEntity; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
} |
131
|
|
|
|