|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * CakeManager (http://cakemanager.org) |
| 4 | + * Copyright (c) http://cakemanager.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) http://cakemanager.org |
| 11 | + * @link http://cakemanager.org CakeManager Project |
| 12 | + * @since 1.0 |
| 13 | + * @license http://www.opensource.org/licenses/mit-license.php MIT License |
| 14 | + */ |
| 15 | +namespace CakeAdmin\Controller; |
| 16 | + |
| 17 | +use Cake\Controller\Controller; |
| 18 | +use Cake\Core\Configure; |
| 19 | +use Cake\Event\Event; |
| 20 | + |
| 21 | +class AppController extends Controller |
| 22 | +{ |
| 23 | + |
| 24 | + public function initialize() |
| 25 | + { |
| 26 | + parent::initialize(); |
| 27 | + |
| 28 | + $this->loadComponent('Flash'); |
| 29 | + |
| 30 | + $this->loadComponent('CakeAdmin.CakeAdmin'); |
| 31 | + |
| 32 | + $this->loadComponent('Auth', [ |
| 33 | + 'authorize' => ['Controller'], |
| 34 | + 'authenticate' => [ |
| 35 | + 'Basic' => [ |
| 36 | + 'userModel' => 'CakeAdmin.Administrators' |
| 37 | + ], |
| 38 | + 'Form' => [ |
| 39 | + 'userModel' => 'CakeAdmin.Administrators', |
| 40 | + 'fields' => [ |
| 41 | + 'username' => 'email', |
| 42 | + 'password' => 'password' |
| 43 | + ], |
| 44 | + 'scope' => ['Administrators.cakeadmin' => true] |
| 45 | + ], |
| 46 | + ], |
| 47 | + 'loginAction' => [ |
| 48 | + 'plugin' => 'CakeAdmin', |
| 49 | + 'controller' => 'Users', |
| 50 | + 'action' => 'login' |
| 51 | + ], |
| 52 | + 'loginRedirect' => [ |
| 53 | + 'plugin' => 'CakeAdmin', |
| 54 | + 'controller' => 'Dashboard', |
| 55 | + 'action' => 'index' |
| 56 | + ], |
| 57 | + 'logoutRedirect' => [ |
| 58 | + 'plugin' => 'CakeAdmin', |
| 59 | + 'controller' => 'Users', |
| 60 | + 'action' => 'login' |
| 61 | + ], |
| 62 | + ]); |
| 63 | + |
| 64 | + $this->Auth->sessionKey = 'Auth.CakeAdmin'; |
| 65 | + $this->authUser = $this->Auth->user(); |
| 66 | + |
| 67 | + $this->loadComponent('Utils.Menu'); |
| 68 | + |
| 69 | + $this->loadComponent('CakeAdmin.PostTypes'); |
| 70 | + |
| 71 | + $this->loadComponent('Notifier.Notifier'); |
| 72 | + } |
| 73 | + |
| 74 | + public function beforeFilter(Event $event) |
| 75 | + { |
| 76 | + if ($this->authUser) { |
| 77 | + $this->layout = 'CakeAdmin.default'; |
| 78 | + } else { |
| 79 | + $this->layout = 'CakeAdmin.login'; |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + public function beforeRender(Event $event) |
| 84 | + { |
| 85 | + $this->set('authUser', $this->authUser); |
| 86 | + $this->set('title', $this->name); |
| 87 | + } |
| 88 | + |
| 89 | + public function isAuthorized($user = null) |
| 90 | + { |
| 91 | + return true; |
| 92 | + } |
| 93 | + |
| 94 | + public function initMenuItems() |
| 95 | + { |
| 96 | + $this->Menu->area('headerLeft'); |
| 97 | + |
| 98 | + $this->Menu->add('ca.dashboard', [ |
| 99 | + 'title' => $this->authUser['email'], |
| 100 | + 'url' => [ |
| 101 | + 'prefix' => false, |
| 102 | + 'plugin' => 'CakeAdmin', |
| 103 | + 'controller' => 'Dashboard', |
| 104 | + 'action' => 'index', |
| 105 | + ] |
| 106 | + ]); |
| 107 | + |
| 108 | + $this->Menu->add('notifier.notifications', [ |
| 109 | + 'title' => 'Notifications (' . $this->Notifier->notificationCount() . ')', |
| 110 | + 'url' => [ |
| 111 | + 'prefix' => false, |
| 112 | + 'plugin' => 'CakeAdmin', |
| 113 | + 'controller' => 'Notifications', |
| 114 | + 'action' => 'index', |
| 115 | + ] |
| 116 | + ]); |
| 117 | + |
| 118 | + $this->Menu->add('ca.logout', [ |
| 119 | + 'title' => __('Logout'), |
| 120 | + 'url' => [ |
| 121 | + 'prefix' => false, |
| 122 | + 'plugin' => 'CakeAdmin', |
| 123 | + 'controller' => 'Users', |
| 124 | + 'action' => 'logout', |
| 125 | + ] |
| 126 | + ]); |
| 127 | + |
| 128 | + $this->Menu->area('main'); |
| 129 | + |
| 130 | + $this->Menu->add('ca.dashboard', [ |
| 131 | + 'title' => __('Dashboard'), |
| 132 | + 'url' => [ |
| 133 | + 'prefix' => false, |
| 134 | + 'plugin' => 'CakeAdmin', |
| 135 | + 'controller' => 'Dashboard', |
| 136 | + 'action' => 'index', |
| 137 | + ] |
| 138 | + ]); |
| 139 | + } |
| 140 | + |
| 141 | +} |
0 commit comments