Skip to content

Commit 5ac96c4

Browse files
committed
Initial commit
1 parent d4fb66c commit 5ac96c4

39 files changed

+3154
-1
lines changed

README.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1-
# cakephp-cakeadmin
1+
# CakeAdmin plugin for CakePHP
2+
3+
> Note: This is a non-stable plugin for CakePHP 3.x at this time. It is currently under development and should be considered experimental.
4+
5+
## Installation
6+
7+
You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).
8+
9+
The recommended way to install composer packages is:
10+
11+
```
12+
composer require cakemanager/cakephp-cakeadmin
13+
```
14+
15+
## Strategy
16+
17+
We are working on this version. Wanna read more about our strategy? Read the following post: http://cakemanager.org/new-cakeadmin-plugin-announced/
18+
219

320
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cakemanager/cakephp-cakeadmin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

composer.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "cakemanager/cakephp-cakeadmin",
3+
"description": "CakeAdmin plugin for CakePHP",
4+
"type": "cakephp-plugin",
5+
"require": {
6+
"php": ">=5.4.16",
7+
"cakephp/cakephp": "~3.0"
8+
},
9+
"require-dev": {
10+
"phpunit/phpunit": "*"
11+
},
12+
"autoload": {
13+
"psr-4": {
14+
"CakeAdmin\\": "src"
15+
}
16+
},
17+
"autoload-dev": {
18+
"psr-4": {
19+
"CakeAdmin\\Test\\": "tests",
20+
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests"
21+
}
22+
}
23+
}

config/bootstrap.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
16+
use Cake\Core\Configure;
17+
18+
19+
Configure::write('CA.Models', [
20+
'administrators' => 'CakeAdmin.Administrators'
21+
]);
22+
23+
Configure::write('CA.PostTypes', [
24+
25+
]);
26+
27+
Configure::write('CA.RegisterPostType.administrators', 'CakeAdmin.Administrators');
28+
29+

config/routes.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
use Cake\Routing\Router;
3+
4+
Router::plugin('CakeAdmin', ['path' => '/admin'], function ($routes) {
5+
6+
$routes->connect(
7+
'/posttypes/:type/:action/*', ['controller' => 'PostTypes'], ['pass' => ['type']]
8+
);
9+
10+
$routes->connect(
11+
'/', ['controller' => 'Users', 'action' => 'login']
12+
);
13+
14+
$routes->fallbacks('InflectedRoute');
15+
});

phpunit.xml.dist

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
colors="true"
4+
processIsolation="false"
5+
stopOnFailure="false"
6+
syntaxCheck="false"
7+
bootstrap="./tests/bootstrap.php"
8+
>
9+
<php>
10+
<ini name="memory_limit" value="-1"/>
11+
<ini name="apc.enable_cli" value="1"/>
12+
</php>
13+
14+
<!-- Add any additional test suites you want to run here -->
15+
<testsuites>
16+
<testsuite name="CakeAdmin Test Suite">
17+
<directory>./tests/TestCase</directory>
18+
</testsuite>
19+
</testsuites>
20+
21+
<!-- Setup a listener for fixtures -->
22+
<listeners>
23+
<listener
24+
class="\Cake\TestSuite\Fixture\FixtureInjector"
25+
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php">
26+
<arguments>
27+
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
28+
</arguments>
29+
</listener>
30+
</listeners>
31+
32+
<!-- Prevent coverage reports from looking in tests and vendors -->
33+
<filter>
34+
<blacklist>
35+
<directory suffix=".php">./vendor/</directory>
36+
<directory suffix=".ctp">./vendor/</directory>
37+
38+
<directory suffix=".php">./tests/</directory>
39+
<directory suffix=".ctp">./tests/</directory>
40+
</blacklist>
41+
</filter>
42+
43+
</phpunit>

src/Controller/AppController.php

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
namespace CakeAdmin\Controller\Component;
3+
4+
use Cake\Controller\Component;
5+
use Cake\Controller\ComponentRegistry;
6+
use Cake\ORM\TableRegistry;
7+
8+
/**
9+
* CakeAdmin component
10+
*/
11+
class CakeAdminComponent extends Component
12+
{
13+
14+
/**
15+
* Default configuration.
16+
*
17+
* @var array
18+
*/
19+
protected $_defaultConfig = [];
20+
21+
public function administrators($field = null)
22+
{
23+
$model = TableRegistry::get('CakeAdmin.Administrators');
24+
25+
$query = $model->find('all');
26+
27+
if($field) {
28+
$model->displayField($field);
29+
$query->find('list');
30+
}
31+
32+
$result = $query->toArray();
33+
34+
return $result;
35+
}
36+
}

0 commit comments

Comments
 (0)