1 | <?php |
||
29 | class Authenticator implements LoggerAwareInterface |
||
30 | { |
||
31 | use LoggerAwareTrait; |
||
32 | |||
33 | /** |
||
34 | * The user object type. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | private $userType; |
||
39 | |||
40 | /** |
||
41 | * Store the user model factory instance for the current class. |
||
42 | * |
||
43 | * @var FactoryInterface |
||
44 | */ |
||
45 | private $userFactory; |
||
46 | |||
47 | /** |
||
48 | * The auth-token object type. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | private $tokenType; |
||
53 | |||
54 | /** |
||
55 | * Store the auth-token model factory instance for the current class. |
||
56 | * |
||
57 | * @var FactoryInterface |
||
58 | */ |
||
59 | private $tokenFactory; |
||
60 | |||
61 | /** |
||
62 | * @param array $data Class dependencies. |
||
63 | */ |
||
64 | public function __construct(array $data) |
||
72 | |||
73 | /** |
||
74 | * Determine if the current user is authenticated. |
||
75 | * |
||
76 | * The user is authenticated via _session ID_ or _auth token_. |
||
77 | * |
||
78 | * @return \Charcoal\User\UserInterface|null Returns the authenticated user object |
||
79 | * or NULL if not authenticated. |
||
80 | */ |
||
81 | public function authenticate() |
||
95 | |||
96 | /** |
||
97 | * Attempt to authenticate a user using the given credentials. |
||
98 | * |
||
99 | * @param string $email Email, part of necessary credentials. |
||
100 | * @param string $password Password, part of necessary credentials. |
||
101 | * @throws InvalidArgumentException If email or password are invalid or empty. |
||
102 | * @return \Charcoal\User\UserInterface|null Returns the authenticated user object |
||
103 | * or NULL if not authenticated. |
||
104 | */ |
||
105 | public function authenticateByPassword($email, $password) |
||
161 | |||
162 | /** |
||
163 | * Retrieve the user object type. |
||
164 | * |
||
165 | * @return string |
||
166 | */ |
||
167 | protected function userType() |
||
171 | |||
172 | |||
173 | /** |
||
174 | * Retrieve the user model factory. |
||
175 | * |
||
176 | * @throws RuntimeException If the model factory was not previously set. |
||
177 | * @return FactoryInterface |
||
178 | */ |
||
179 | protected function userFactory() |
||
183 | |||
184 | /** |
||
185 | * Retrieve the auth-token object type. |
||
186 | * |
||
187 | * @return string |
||
188 | */ |
||
189 | protected function tokenType() |
||
193 | |||
194 | /** |
||
195 | * Retrieve the auth-token model factory. |
||
196 | * |
||
197 | * @throws RuntimeException If the token factory was not previously set. |
||
198 | * @return FactoryInterface |
||
199 | */ |
||
200 | protected function tokenFactory() |
||
204 | |||
205 | /** |
||
206 | * Set the user object type (model). |
||
207 | * |
||
208 | * @param string $type The user object type. |
||
209 | * @throws InvalidArgumentException If the user object type parameter is not a string. |
||
210 | * @return void |
||
211 | */ |
||
212 | private function setUserType($type) |
||
222 | |||
223 | /** |
||
224 | * Set a user model factory. |
||
225 | * |
||
226 | * @param FactoryInterface $factory The factory used to create new user instances. |
||
227 | * @return void |
||
228 | */ |
||
229 | private function setUserFactory(FactoryInterface $factory) |
||
233 | |||
234 | /** |
||
235 | * Set the authorization token type (model). |
||
236 | * |
||
237 | * @param string $type The auth-token object type. |
||
238 | * @throws InvalidArgumentException If the token object type parameter is not a string. |
||
239 | * @return void |
||
240 | */ |
||
241 | private function setTokenType($type) |
||
251 | |||
252 | /** |
||
253 | * Set a model factory for token-based authentication. |
||
254 | * |
||
255 | * @param FactoryInterface $factory The factory used to create new auth-token instances. |
||
256 | * @return void |
||
257 | */ |
||
258 | private function setTokenFactory(FactoryInterface $factory) |
||
262 | |||
263 | /** |
||
264 | * Attempt to authenticate a user using their session ID. |
||
265 | * |
||
266 | * @return \Charcoal\User\UserInterface|null Returns the authenticated user object |
||
267 | * or NULL if not authenticated. |
||
268 | */ |
||
269 | private function authenticateBySession() |
||
283 | |||
284 | /** |
||
285 | * Attempt to authenticate a user using their auth token. |
||
286 | * |
||
287 | * @return \Charcoal\User\UserInterface|null Returns the authenticated user object |
||
288 | * or NULL if not authenticated. |
||
289 | */ |
||
290 | private function authenticateByToken() |
||
318 | } |
||
319 |