TestAuthenticate.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright 2005-2011, Cake Software Foundation, Inc. (https://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. (https://cakefoundation.org)
  10. * @link https://cakephp.org CakePHP(tm) Project
  11. * @since 3.0.0
  12. * @license https://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\Http\Response;
  18. use Cake\Http\ServerRequest;
  19. /**
  20. * TestAuthenticate class
  21. */
  22. class TestAuthenticate extends BaseAuthenticate
  23. {
  24. public $callStack = [];
  25. public $authenticationProvider;
  26. /**
  27. * @return array
  28. */
  29. public function implementedEvents()
  30. {
  31. return [
  32. 'Auth.afterIdentify' => 'afterIdentify',
  33. 'Auth.logout' => 'logout'
  34. ];
  35. }
  36. /**
  37. * @param \Cake\Http\ServerRequest $request
  38. * @param \Cake\Http\Response $response
  39. * @return array
  40. */
  41. public function authenticate(ServerRequest $request, Response $response)
  42. {
  43. return ['id' => 1, 'username' => 'admad'];
  44. }
  45. /**
  46. * @param \Cake\Event\Event $event
  47. * @param array $user
  48. * @return array
  49. */
  50. public function afterIdentify(Event $event, array $user)
  51. {
  52. $this->callStack[] = __FUNCTION__;
  53. $this->authenticationProvider = $event->getData(1);
  54. if (!empty($this->modifiedUser)) {
  55. return $user + ['extra' => 'foo'];
  56. }
  57. }
  58. /**
  59. * @param \Cake\Event\Event $event
  60. * @param array $user
  61. */
  62. public function logout(Event $event, array $user)
  63. {
  64. $this->callStack[] = __FUNCTION__;
  65. }
  66. }