TestAuthenticate.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  10. * @link http://cakephp.org CakePHP(tm) Project
  11. * @since 3.0.0
  12. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace TestApp\Auth;
  15. use Cake\Auth\BaseAuthenticate;
  16. use Cake\Event\Event;
  17. use Cake\Network\Request;
  18. use Cake\Network\Response;
  19. /**
  20. * TestAuthenticate class
  21. *
  22. */
  23. class TestAuthenticate extends BaseAuthenticate
  24. {
  25. public $callStack = [];
  26. public $authenticationProvider;
  27. public function implementedEvents()
  28. {
  29. return [
  30. 'Auth.afterIdentify' => 'afterIdentify',
  31. 'Auth.logout' => 'logout'
  32. ];
  33. }
  34. public function authenticate(Request $request, Response $response)
  35. {
  36. return ['id' => 1, 'username' => 'admad'];
  37. }
  38. public function afterIdentify(Event $event, array $user)
  39. {
  40. $this->callStack[] = __FUNCTION__;
  41. $this->authenticationProvider = $event->data[1];
  42. if (!empty($this->modifiedUser)) {
  43. return $user + ['extra' => 'foo'];
  44. }
  45. }
  46. public function logout(Event $event, array $user)
  47. {
  48. $this->callStack[] = __FUNCTION__;
  49. }
  50. }