Web Interfaces of PROSUME

routes.php 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * Routes configuration
  4. *
  5. * In this file, you set up routes to your controllers and their actions.
  6. * Routes are very important mechanism that allows you to freely connect
  7. * different URLs to chosen controllers and their actions (functions).
  8. *
  9. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  10. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. *
  12. * Licensed under The MIT License
  13. * For full copyright and license information, please see the LICENSE.txt
  14. * Redistributions of files must retain the above copyright notice.
  15. *
  16. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  17. * @link https://cakephp.org CakePHP(tm) Project
  18. * @license https://opensource.org/licenses/mit-license.php MIT License
  19. */
  20. use Cake\Http\Middleware\CsrfProtectionMiddleware;
  21. use Cake\Routing\RouteBuilder;
  22. use Cake\Routing\Router;
  23. use Cake\Routing\Route\DashedRoute;
  24. /**
  25. * The default class to use for all routes
  26. *
  27. * The following route classes are supplied with CakePHP and are appropriate
  28. * to set as the default:
  29. *
  30. * - Route
  31. * - InflectedRoute
  32. * - DashedRoute
  33. *
  34. * If no call is made to `Router::defaultRouteClass()`, the class used is
  35. * `Route` (`Cake\Routing\Route\Route`)
  36. *
  37. * Note that `Route` does not do any inflections on URLs which will result in
  38. * inconsistently cased URLs when used with `:plugin`, `:controller` and
  39. * `:action` markers.
  40. *
  41. * Cache: Routes are cached to improve performance, check the RoutingMiddleware
  42. * constructor in your `src/Application.php` file to change this behavior.
  43. *
  44. */
  45. Router::defaultRouteClass(DashedRoute::class);
  46. Router::scope('/', function (RouteBuilder $routes) {
  47. // Register scoped middleware for in scopes.
  48. $routes->registerMiddleware('csrf', new CsrfProtectionMiddleware([
  49. 'httpOnly' => true
  50. ]));
  51. /**
  52. * Here, we are connecting '/' (base path) to a controller called 'Pages',
  53. * its action called 'display', and we pass a param to select the view file
  54. * to use (in this case, src/Template/Pages/home.ctp)...
  55. */
  56. // $routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
  57. $routes->connect('/', ['controller' => 'Main', 'action' => 'history']);
  58. $routes->scope('/web', function ($routes) {
  59. $routes->applyMiddleware('csrf');
  60. $routes->connect('/', ['controller' => 'Main', 'action' => 'history']);
  61. $routes->connect('/history', ['controller' => 'Main', 'action' => 'history']);
  62. $routes->connect('/history/:meter_id', ['controller' => 'Main', 'action' => 'historyMeter']
  63. ,['pass' =>['meter_id']]);
  64. $routes->connect('/history/daily', ['controller' => 'Main', 'action' => 'historyDaily']);
  65. $routes->connect('/history/daily/:meter_id', ['controller' => 'Main', 'action' => 'historyMeterDaily']
  66. ,['pass' =>['meter_id']]);
  67. $routes->connect('/history/monthly', ['controller' => 'Main', 'action' => 'historyMonthly']);
  68. $routes->connect('/history/monthly/:meter_id', ['controller' => 'Main', 'action' => 'historyMeterMonthly']
  69. ,['pass' =>['meter_id']]);
  70. $routes->connect('/meter', ['controller' => 'Main', 'action' => 'meter']);
  71. $routes->connect('/meter/:meter_id', ['controller' => 'Main', 'action' => 'meterID']
  72. ,['pass' =>['meter_id']]);
  73. $routes->connect('/block/:block_id', ['controller' => 'Main', 'action' => 'blockID']
  74. ,['pass' =>['block_id']]);
  75. $routes->connect('/history/price', ['controller' => 'Main', 'action' => 'priceHistory']);
  76. $routes->connect('/history/price/:meter_id', ['controller' => 'Main', 'action' => 'priceHistoryMeter'],['pass' =>['meter_id']]);
  77. $routes->connect('/payment', ['controller' => 'Main', 'action' => 'payment']);
  78. $routes->connect('/setprice', ['controller' => 'Main', 'action' => 'setPrice']);
  79. $routes->connect('/transfer', ['controller' => 'Main', 'action' => 'transfer']);
  80. $routes->connect('/profile', ['controller' => 'Main', 'action' => 'profile']);
  81. });
  82. $routes->scope('/xhr/', function ($routes) {
  83. $routes->applyMiddleware('csrf');
  84. $routes->connect('setprice', ['controller' => 'Xhr', 'action' => 'setPrice']);
  85. $routes->connect('transfer', ['controller' => 'Xhr', 'action' => 'transfer']);
  86. $routes->connect('history', ['controller' => 'Xhr', 'action' => 'history']);
  87. $routes->connect('historyTransfer', ['controller' => 'Xhr', 'action' => 'historyTransfer']);
  88. $routes->connect('payment', ['controller' => 'Xhr', 'action' => 'payment']);
  89. $routes->connect('price/history', ['controller' => 'Xhr', 'action' => 'priceHistory']);
  90. $routes->connect('block', ['controller' => 'Xhr', 'action' => 'blocks']);
  91. $routes->connect('balances', ['controller' => 'Xhr', 'action' => 'balances']);
  92. $routes->connect('charts/payments/:meter_name', ['controller' => 'Xhr', 'action' => 'chartsPayments']
  93. ,['pass' =>['meter_name']]);
  94. });
  95. $routes->scope('/api/', function ($routes) {
  96. $routes->connect('transfer', ['controller' => 'Api', 'action' => 'transfer']);
  97. $routes->connect('history', ['controller' => 'Api', 'action' => 'history']);
  98. $routes->connect('payment', ['controller' => 'Api', 'action' => 'payment']);
  99. $routes->connect('price', ['controller' => 'Api', 'action' => 'price']);
  100. $routes->connect('block', ['controller' => 'Api', 'action' => 'blocks']);
  101. $routes->connect('/block/:block_id', ['controller' => 'Api', 'action' => 'blockID']
  102. ,['pass' =>['block_id']]);
  103. $routes->connect('meter', ['controller' => 'Api', 'action' => 'meter']);
  104. $routes->connect('meter/:meter_id', ['controller' => 'Api', 'action' => 'meterID']
  105. ,['pass' =>['meter_id']]);
  106. $routes->connect('balances', ['controller' => 'Api', 'action' => 'balances']);
  107. });
  108. /**
  109. * ...and connect the rest of 'Pages' controller's URLs.
  110. */
  111. // $routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
  112. /**
  113. * Connect catchall routes for all controllers.
  114. *
  115. * Using the argument `DashedRoute`, the `fallbacks` method is a shortcut for
  116. *
  117. * ```
  118. * $routes->connect('/:controller', ['action' => 'index'], ['routeClass' => 'DashedRoute']);
  119. * $routes->connect('/:controller/:action/*', [], ['routeClass' => 'DashedRoute']);
  120. * ```
  121. *
  122. * Any route class can be used with this method, such as:
  123. * - DashedRoute
  124. * - InflectedRoute
  125. * - Route
  126. * - Or your own route class
  127. *
  128. * You can remove these routes once you've connected the
  129. * routes you want in your application.
  130. */
  131. $routes->fallbacks(DashedRoute::class);
  132. });
  133. /**
  134. * If you need a different set of middleware or none at all,
  135. * open new scope and define routes there.
  136. *
  137. * ```
  138. * Router::scope('/api', function (RouteBuilder $routes) {
  139. * // No $routes->applyMiddleware() here.
  140. * // Connect API actions here.
  141. * });
  142. * ```
  143. */