Skip to content

Commit 218de59

Browse files
committed
Merge branch 'develop'
Conflicts: composer.json
2 parents 4941519 + f90ce43 commit 218de59

49 files changed

Lines changed: 1978 additions & 1055 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"email": "bobmulder@outlook.com"
1010
}
1111
],
12-
"require": {},
12+
"require": {
13+
"friendsofcake/crud": "dev-cake3"
14+
},
1315
"extra": {
1416
"installer-name": "CakeManager"
1517
},

config/Migrations/20141231074222_inital.php

Lines changed: 90 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -5,123 +5,98 @@
55
class Inital extends AbstractMigration
66
{
77

8-
/**
9-
* Change Method.
10-
*
11-
* More information on this method is available here:
12-
* http://docs.phinx.org/en/latest/migrations.html#the-change-method
13-
*
14-
* @return void
15-
*/
16-
public function change() {
17-
18-
$exists = $this->hasTable('metas');
19-
if (!$exists) {
20-
21-
$table = $this->table('metas');
22-
$table
23-
->addColumn('rel_model', 'string', [
24-
'limit' => '50',
25-
'null' => true,
26-
'default' => '',
27-
])
28-
->addColumn('rel_id', 'integer', [
29-
'limit' => '11',
30-
'signed' => '',
31-
'null' => true,
32-
])
33-
->addColumn('name', 'string', [
34-
'limit' => '256',
35-
'null' => true,
36-
'default' => '',
37-
])
38-
->addColumn('value', 'text', [
39-
'limit' => '',
40-
'null' => true,
41-
'default' => '',
42-
])
43-
->addColumn('created', 'datetime', [
44-
'limit' => '',
45-
'null' => true,
46-
])
47-
->addColumn('modified', 'datetime', [
48-
'limit' => '',
49-
'null' => true,
50-
])
51-
->save();
52-
}
53-
54-
$exists = $this->hasTable('roles');
55-
if (!$exists) {
56-
57-
58-
$table = $this->table('roles');
59-
$table
60-
->addColumn('name', 'string', [
61-
'limit' => '50',
62-
'null' => '',
63-
'default' => '0',
64-
])
65-
->addColumn('login_redirect', 'string', [
66-
'limit' => '256',
67-
'null' => true,
68-
'default' => '',
69-
])
70-
->addColumn('created', 'datetime', [
71-
'limit' => '',
72-
'null' => '',
73-
'default' => '0000-00-00 00:00:00',
74-
])
75-
->addColumn('modified', 'datetime', [
76-
'limit' => '',
77-
'null' => '',
78-
'default' => '0000-00-00 00:00:00',
79-
])
80-
->save();
81-
}
82-
83-
$exists = $this->hasTable('users');
84-
if (!$exists) {
85-
86-
87-
$table = $this->table('users');
88-
$table
89-
->addColumn('role_id', 'integer', [
90-
'limit' => '11',
91-
'signed' => '',
92-
'null' => true,
93-
])
94-
->addColumn('email', 'string', [
95-
'limit' => '255',
96-
'null' => '',
97-
'default' => '',
98-
])
99-
->addColumn('password', 'string', [
100-
'limit' => '255',
101-
'null' => '',
102-
'default' => '',
103-
])
104-
->addColumn('created', 'datetime', [
105-
'limit' => '',
106-
'null' => true,
107-
'default' => '0000-00-00 00:00:00',
108-
])
109-
->addColumn('modified', 'datetime', [
110-
'limit' => '',
111-
'null' => true,
112-
'default' => '0000-00-00 00:00:00',
113-
])
114-
->save();
115-
}
116-
}
117-
1188
/**
1199
* Migrate Up.
12010
*
12111
* @return void
12212
*/
12313
public function up() {
12414

15+
$table = $this->table('roles');
16+
$table
17+
->addColumn('name', 'string', [
18+
'limit' => '50',
19+
'null' => '',
20+
'default' => '0',
21+
])
22+
->addColumn('login_redirect', 'string', [
23+
'limit' => '256',
24+
'null' => true,
25+
'default' => '',
26+
])
27+
->addColumn('created', 'datetime', [
28+
'limit' => '',
29+
'null' => '',
30+
'default' => '0000-00-00 00:00:00',
31+
])
32+
->addColumn('modified', 'datetime', [
33+
'limit' => '',
34+
'null' => '',
35+
'default' => '0000-00-00 00:00:00',
36+
])
37+
->create();
38+
39+
40+
$table = $this->table('users');
41+
$table
42+
->addColumn('role_id', 'integer', [
43+
'limit' => '11',
44+
'signed' => '',
45+
'null' => true,
46+
])
47+
->addColumn('email', 'string', [
48+
'limit' => '255',
49+
'null' => '',
50+
'default' => '',
51+
])
52+
->addColumn('password', 'string', [
53+
'limit' => '255',
54+
'null' => '',
55+
'default' => '',
56+
])
57+
->addColumn('created', 'datetime', [
58+
'limit' => '',
59+
'null' => true,
60+
'default' => '0000-00-00 00:00:00',
61+
])
62+
->addColumn('modified', 'datetime', [
63+
'limit' => '',
64+
'null' => true,
65+
'default' => '0000-00-00 00:00:00',
66+
])
67+
->create();
68+
69+
$table = $this->table('metas');
70+
$table
71+
->addColumn('rel_model', 'string', [
72+
'limit' => '50',
73+
'null' => true,
74+
'default' => '',
75+
])
76+
->addColumn('rel_id', 'integer', [
77+
'limit' => '11',
78+
'signed' => '',
79+
'null' => true,
80+
])
81+
->addColumn('name', 'string', [
82+
'limit' => '256',
83+
'null' => true,
84+
'default' => '',
85+
])
86+
->addColumn('value', 'text', [
87+
'limit' => '',
88+
'null' => true,
89+
'default' => '',
90+
])
91+
->addColumn('created', 'datetime', [
92+
'limit' => '',
93+
'null' => true,
94+
])
95+
->addColumn('modified', 'datetime', [
96+
'limit' => '',
97+
'null' => true,
98+
])
99+
->create();
125100
}
126101

127102
/**
@@ -131,6 +106,11 @@ public function up() {
131106
*/
132107
public function down() {
133108

109+
$this->dropTable('users');
110+
111+
$this->dropTable('roles');
112+
113+
$this->dropTable('metas');
134114
}
135115

136116
}

config/bootstrap.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,46 @@
11
<?php
22

33
use Cake\Core\Configure;
4-
use Cake\Network\Session;
54

5+
/**
6+
* Default Session-settings
7+
*/
68
Configure::write('Session', [
79
'defaults' => 'php',
810
'timeout' => 2880
911
]);
12+
13+
/**
14+
* The Role-definition for CM
15+
*/
16+
Configure::write('CM.Roles', [
17+
'Administrators' => [1],
18+
'Moderators' => [2],
19+
'Users' => [3],
20+
'Unregistered' => [4],
21+
]);
22+
23+
/**
24+
* The UserModel to use. Default 'CakeManager.Users'
25+
*/
26+
Configure::write('CM.UserModel', 'CakeManager.Users');
27+
28+
/**
29+
* The UserViews to use
30+
* Default for the CakeManager itself, you can change it for your own views
31+
*/
32+
Configure::write('CM.UserViews', [
33+
'login' => 'CakeManager./Users/index',
34+
]);
35+
36+
/**
37+
* The UserViews to use for admin-section
38+
* Default for the CakeManager itself, you can change it for your own views
39+
*/
40+
Configure::write('CM.AdminUserViews', [
41+
'index' => 'CakeManager./Admin/Users/index',
42+
'view' => 'CakeManager./Admin/Users/view',
43+
'add' => 'CakeManager./Admin/Users/add',
44+
'edit' => 'CakeManager./Admin/Users/edit',
45+
'new_password' => 'CakeManager./Admin/Users/new_password',
46+
]);

config/routes.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,25 @@
99
$routes->fallbacks('InflectedRoute');
1010
});
1111

12-
Router::plugin('CakeManager', ['path' => '/manager'], function ($routes) {
12+
Router::prefix('api', function($routes) {
13+
$routes->plugin('CakeManager', ['path' => '/'], function ($routes) {
14+
15+
$routes->extensions(['json']);
16+
$routes->resources('Roles');
17+
$routes->resources('Users');
18+
1319
$routes->fallbacks('InflectedRoute');
1420
});
21+
});
22+
23+
24+
Router::plugin('CakeManager', ['path' => '/manager'], function ($routes) {
25+
$routes->fallbacks('InflectedRoute');
26+
});
1527

1628

1729
Router::connect('/login', ['plugin' => 'CakeManager', 'prefix' => false, 'controller' => 'Users', 'action' => 'login']);
1830

19-
Router::connect('/logout', ['plugin' => 'CakeManager', 'prefix' => false, 'controller' => 'Users', 'action' => 'logout']);
31+
Router::connect('/admin', ['plugin' => 'CakeManager', 'prefix' => false, 'controller' => 'Users', 'action' => 'login']);
2032

33+
Router::connect('/logout', ['plugin' => 'CakeManager', 'prefix' => false, 'controller' => 'Users', 'action' => 'logout']);

src/Auth/RolesAuthorize.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace CakeManager\Auth;
4+
5+
use Cake\Network\Request;
6+
use Cake\Auth\ControllerAuthorize;
7+
8+
class RolesAuthorize extends ControllerAuthorize
9+
{
10+
11+
public function authorize($user, Request $request) {
12+
13+
// if you access an prefix
14+
if (key_exists('prefix', $request->params)) {
15+
16+
// if you are really admin, you can access
17+
if ($request->params['prefix'] == 'admin') {
18+
if ($this->Controller()->Manager->isAdmin($user)) {
19+
return true;
20+
}
21+
return false;
22+
}
23+
24+
}
25+
26+
// if you don't access the admin-area follow the ControllerAuthorize
27+
return parent::authorize($user, $request);
28+
}
29+
30+
}

0 commit comments

Comments
 (0)