1 | <?php |
||
23 | class SecurityUserDao implements UserDaoInterface, ForgotYourPasswordDao, UserListDao |
||
24 | { |
||
25 | /** |
||
26 | * @var TDBMService |
||
27 | */ |
||
28 | protected $tdbmService; |
||
29 | |||
30 | /** |
||
31 | * Sets the TDBM service used by this DAO. |
||
32 | * |
||
33 | * @param TDBMService $tdbmService |
||
34 | */ |
||
35 | public function __construct(TDBMService $tdbmService) |
||
36 | { |
||
37 | $this->tdbmService = $tdbmService; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Returns a user from its login and its password, or null if the login or credentials are false. |
||
42 | * |
||
43 | * @param string $login |
||
44 | * @param string $password |
||
45 | * |
||
46 | * @return UserInterface |
||
47 | */ |
||
48 | public function getUserByCredentials($login, $password) |
||
49 | { |
||
50 | $user = $this->findOne(['login' => $login]); |
||
51 | if ($user === null) { |
||
52 | return; |
||
53 | } |
||
54 | |||
55 | if (password_verify($password, $user->getPassword())) { |
||
56 | return $user; |
||
57 | } else { |
||
58 | return; |
||
59 | } |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Returns a user from its token. |
||
64 | * |
||
65 | * @param string $token |
||
66 | * |
||
67 | * @return UserInterface |
||
68 | */ |
||
69 | public function getUserByToken($token) |
||
70 | { |
||
71 | $user = $this->findOne(['token' => $token]); |
||
72 | if ($user === null) { |
||
73 | throw TokenNotFoundException::notFound($token); |
||
74 | } |
||
75 | |||
76 | return $user; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Discards a token. |
||
81 | * |
||
82 | * @param string $token |
||
83 | */ |
||
84 | public function discardToken($token) |
||
85 | { |
||
86 | $user = $this->getUserByToken($token); |
||
87 | $user->setToken(null); |
||
|
|||
88 | $this->tdbmService->save($user); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Returns a user from its ID. |
||
93 | * |
||
94 | * @param string $id |
||
95 | * |
||
96 | * @return UserInterface |
||
97 | */ |
||
98 | public function getUserById($id) |
||
99 | { |
||
100 | return $this->tdbmService->findObjectByPk('users', ['id' => $id], [], false); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * Returns a user from its login. |
||
105 | * |
||
106 | * @param string $login |
||
107 | * |
||
108 | * @return UserInterface |
||
109 | */ |
||
110 | public function getUserByLogin($login) |
||
111 | { |
||
112 | return $this->findOne(['login' => $login]); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Get a single UserBean specified by its filters. |
||
117 | * |
||
118 | * @param mixed $filter The filter bag (see TDBMService::findObjects for complete description) |
||
119 | * @param array $parameters The parameters associated with the filter |
||
120 | * |
||
121 | * @return UserInterface|null |
||
122 | */ |
||
123 | private function findOne($filter = null, array $parameters = []) |
||
124 | { |
||
125 | return $this->tdbmService->findObject('users', $filter, $parameters); |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * Sets $token for user whose mail is $email, stores the token in database. |
||
130 | * Throws an EmailNotFoundException if the email is not part of the database. |
||
131 | * |
||
132 | * @param string $email |
||
133 | * |
||
134 | * @throws \Mouf\Security\Password\Api\EmailNotFoundException |
||
135 | */ |
||
136 | public function setToken(string $email, string $token) |
||
137 | { |
||
138 | $user = $this->findOne(['email' => $email]); |
||
139 | |||
140 | if ($user === null) { |
||
141 | throw EmailNotFoundException::notFound($email); |
||
142 | } |
||
143 | |||
144 | $user->setToken($token); |
||
145 | |||
146 | $this->tdbmService->save($user); |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * Sets the password matching to $token and discards $token. |
||
151 | * Throws an TokenNotFoundException if the token is not part of the database. |
||
152 | * |
||
153 | * @param string $token |
||
154 | * @param string $password |
||
155 | * |
||
156 | * @throws \Mouf\Security\Password\Api\TokenNotFoundException |
||
157 | */ |
||
158 | public function setPasswordAndDiscardToken(string $token, string $password) |
||
159 | { |
||
160 | $user = $this->getUserByToken($token); |
||
161 | $user->setPassword($password); |
||
162 | $user->setToken(null); |
||
163 | $this->tdbmService->save($user); |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * Returns a list of users, as a Porpaginas result. |
||
168 | * This list can be filtered based on the $filters array, that can be really anything based on the filters you implement. |
||
169 | * |
||
170 | * @param array $filters |
||
171 | * @param $orderBy |
||
172 | * @param $direction |
||
173 | * @return Result |
||
174 | */ |
||
175 | public function search(array $filters, $orderBy, $direction) : Result |
||
188 | } |
||
189 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.