Merge branch 'master' of feistymeow.org:feisty_meow
[feisty_meow.git] / production / example_apps / shared_calendar / src / Controller / AppController.php
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     0.2.9
13  * @license   http://www.opensource.org/licenses/mit-license.php MIT License
14  */
15 namespace App\Controller;
16
17 use Cake\Controller\Controller;
18 use Cake\Event\Event;
19
20 /**
21  * Application Controller
22  *
23  * Add your application-wide methods in the class below, your controllers
24  * will inherit them.
25  *
26  * @link http://book.cakephp.org/3.0/en/controllers.html#the-app-controller
27  */
28 class AppController extends Controller
29 {
30
31     /**
32      * Initialization hook method.
33      *
34      * Use this method to add common initialization code like loading components.
35      *
36      * e.g. `$this->loadComponent('Security');`
37      *
38      * @return void
39      */
40     public function initialize()
41     {
42         parent::initialize();
43
44         $this->loadComponent('RequestHandler');
45         $this->loadComponent('Flash');
46
47         /*
48          * Enable the following components for recommended CakePHP security settings.
49          * see http://book.cakephp.org/3.0/en/controllers/components/security.html
50          */
51         //$this->loadComponent('Security');
52         //$this->loadComponent('Csrf');
53
54 /* not necessarily what we want.
55 //CALCODE:
56         $this->loadComponent('Auth', [
57                 'loginAction' => [
58                     'controller' => 'Users',
59                     'action' => 'authorize',
60                 ],
61                 'authenticate'         => [
62                     'Form' => [
63                         'fields' => [
64                             'username' => 'email',
65                             'password' => 'password'
66                         ]
67                     ]
68                 ],
69                 'authError'            => __('You do not have permission to access this page'),
70                 'authorize'            => ['Controller'],
71                 'unauthorizedRedirect' => [
72                     'controller' => 'Users',
73                     'action'     => 'forbidden'
74                 ],
75                 'loginRedirect'        => [
76                     'controller' => 'Users',
77                     'action'     => 'show_calendar'
78                 ],
79                 'logoutRedirect'       => [
80                     'controller' => 'Users',
81                     'action'     => 'authorize'
82                 ]
83         ]);
84
85         $this->Auth->allow(['authorize', 'googleLogin']);
86 */
87     }
88
89     /**
90      * Before render callback.
91      *
92      * @param \Cake\Event\Event $event The beforeRender event.
93      * @return \Cake\Network\Response|null|void
94      */
95     public function beforeRender(Event $event)
96     {
97         if (!array_key_exists('_serialize', $this->viewVars) &&
98             in_array($this->response->type(), ['application/json', 'application/xml'])
99         ) {
100             $this->set('_serialize', true);
101         }
102     }
103 }