PostsController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace TestApp\Controller;
  16. use Cake\Event\Event;
  17. use TestApp\Controller\AppController;
  18. /**
  19. * PostsController class
  20. *
  21. */
  22. class PostsController extends AppController
  23. {
  24. /**
  25. * Components array
  26. *
  27. * @var array
  28. */
  29. public $components = [
  30. 'Flash',
  31. 'RequestHandler',
  32. 'Security',
  33. ];
  34. /**
  35. * beforeFilter
  36. *
  37. * @return void
  38. */
  39. public function beforeFilter(Event $event)
  40. {
  41. if ($this->request->param('action') !== 'securePost') {
  42. $this->eventManager()->off($this->Security);
  43. }
  44. }
  45. /**
  46. * Index method.
  47. *
  48. * @return void
  49. */
  50. public function index()
  51. {
  52. $this->Flash->error('An error message');
  53. $this->response->cookie([
  54. 'name' => 'remember_me',
  55. 'value' => 1
  56. ]);
  57. $this->set('test', 'value');
  58. }
  59. /**
  60. * Stub get method
  61. *
  62. * @return void
  63. */
  64. public function get()
  65. {
  66. // Do nothing.
  67. }
  68. /**
  69. * Post endpoint for integration testing with security component.
  70. *
  71. * @return void
  72. */
  73. public function securePost()
  74. {
  75. $this->response->body('Request was accepted');
  76. return $this->response;
  77. }
  78. public function file()
  79. {
  80. $this->response->file(__FILE__);
  81. return $this->response;
  82. }
  83. }