Web Interfaces of PROSUME

AppController.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://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. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 0.2.9
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace App\Controller;
  16. use Cake\Controller\Controller;
  17. use Cake\Event\Event;
  18. /**
  19. * Application Controller
  20. *
  21. * Add your application-wide methods in the class below, your controllers
  22. * will inherit them.
  23. *
  24. * @link https://book.cakephp.org/3.0/en/controllers.html#the-app-controller
  25. */
  26. class AppController extends Controller
  27. {
  28. /**
  29. * Initialization hook method.
  30. *
  31. * Use this method to add common initialization code like loading components.
  32. *
  33. * e.g. `$this->loadComponent('Security');`
  34. *
  35. * @return void
  36. */
  37. public function initialize()
  38. {
  39. parent::initialize();
  40. $this->loadComponent('RequestHandler', [
  41. 'enableBeforeRedirect' => false,
  42. ]);
  43. $this->loadComponent('Flash');
  44. $this->loadComponent('Auth', [
  45. 'authorize' => [
  46. 'Controller',
  47. ],
  48. 'loginRedirect' => [
  49. 'controller' => 'Main',
  50. 'action' => 'history'
  51. ],
  52. 'logoutRedirect' => [
  53. 'controller' => 'Users',
  54. 'action' => 'login'
  55. ]
  56. ]);
  57. $conf = parse_ini_file(dirname(__FILE__).'/../../client.ini', true);
  58. $this->set('app_charts', ((bool)$conf['app']['charts'] ?? false));
  59. $this->set('app_logotype', ($conf['app']['logotype'] ?? null));
  60. $this->set('app_name', ($conf['app']['name'] ?? null));
  61. $this->set('app_short', ($conf['app']['short'] ?? null));
  62. $this->set('utility_account', ($conf['app']['utility_account'] ?? null));
  63. /*
  64. * Enable the following component for recommended CakePHP security settings.
  65. * see https://book.cakephp.org/3.0/en/controllers/components/security.html
  66. */
  67. //$this->loadComponent('Security');
  68. }
  69. public function beforeFilter(Event $event)
  70. {
  71. $this->Auth->allow(['login', 'logout']);
  72. }
  73. public function beforeRender(Event $event)
  74. {
  75. $this->set('role', $this->Auth->user()['role'] ?? false);
  76. $this->set('user_meter_id', $this->Auth->user()['meter_id'] ?? 0);
  77. }
  78. public function isAuthorized($user)
  79. {
  80. return isset($user['role']);
  81. }
  82. }