Browse Source

begin controller update

tags/0.1.0
Robin Thoni 9 years ago
parent
commit
fb244fd612

+ 7
- 1
generate.php View File

@@ -40,12 +40,18 @@ $gen->setConfig(array("dbo" =>
40 40
             "namespace" => 'Luticate\Auth\Business',
41 41
             "folder" => 'src/Auth/Business'
42 42
         ),
43
+    "controller" =>
44
+        array(
45
+            "namespace" => 'Luticate\Auth\Controller',
46
+            "folder" => 'src/Auth/Controller'
47
+        ),
43 48
     "mode" => 0775,
44 49
     "ignore" => array(
45 50
         "tables" => array(
46 51
             "/luticate_users_groups/"
47 52
         ),
48
-        "sp" => array()
53
+        "sp" => array(),
54
+        "controllers" => array()
49 55
     )
50 56
 ));
51 57
 $gen->run();

+ 32
- 36
src/Auth/Business/LuticateBusiness.php View File

@@ -8,11 +8,8 @@
8 8
 
9 9
 namespace Luticate\Auth\Business;
10 10
 
11
-use Illuminate\Http\Request;
12 11
 use Luticate\Auth\DBO\LuticatePermissions;
13 12
 use Luticate\Auth\DBO\LuticateUsersDbo;
14
-use Luticate\Doc\Business\LuDocBusiness;
15
-use Luticate\Utils\LuController;
16 13
 use Luticate\Utils\LuRoute;
17 14
 
18 15
 class LuticateBusiness
@@ -43,13 +40,12 @@ class LuticateBusiness
43 40
      */
44 41
     public static function setupRoutes($prefix = "/luticate")
45 42
     {
46
-        $ns = 'Luticate\Auth\Business\\';
43
+        $ns = 'Luticate\Auth\Controller\\';
47 44
 
48 45
         $int = "[0-9]+";
49 46
         $name = "[A-Z0-9_]+";
50 47
         $bool = "true|false";
51 48
 
52
-        $id = "{id:$int}";
53 49
         $group_id = "{group_id:$int}";
54 50
         $user_id = "{user_id:$int}";
55 51
         $permission_name = "{permission_name:$name}";
@@ -57,73 +53,73 @@ class LuticateBusiness
57 53
 
58 54
         $route = LuRoute::getInstance();
59 55
 
60
-        $route->post("$prefix/users/login", "${ns}LuticateUsersBusiness", "login");
61
-        $route->post("$prefix/users/logout", "${ns}LuticateUsersBusiness", "logout");
62
-        $route->post("$prefix/users/$id", "${ns}LuticateUsersBusiness", "getById", LuticatePermissions::USER_GET);
63
-        $route->post("$prefix/users", "${ns}LuticateUsersBusiness", "getAll", LuticatePermissions::USER_GET);
64
-        $route->post("$prefix/users/add", "${ns}LuticateUsersBusiness", "add",
56
+        $route->post("$prefix/users/login", "${ns}LuticateUsersController", "login");
57
+        $route->post("$prefix/users/logout", "${ns}LuticateUsersController", "logout");
58
+        $route->get("$prefix/users/$user_id", "${ns}LuticateUsersController", "getById", LuticatePermissions::USER_GET);
59
+        $route->get("$prefix/users", "${ns}LuticateUsersController", "getAll", LuticatePermissions::USER_GET);
60
+        $route->post("$prefix/users/add", "${ns}LuticateUsersController", "add",
65 61
             array(LuticatePermissions::USER_ADD, LuticatePermissions::USER_GET));
66
-        $route->post("$prefix/users/$user_id/del", "${ns}LuticateUsersBusiness", "del",
62
+        $route->post("$prefix/users/$user_id/del", "${ns}LuticateUsersController", "del",
67 63
             array(LuticatePermissions::USER_DEL, LuticatePermissions::USER_GET));
68
-        $route->post("$prefix/users/$user_id/edit", "${ns}LuticateUsersBusiness", "edit",
64
+        $route->post("$prefix/users/$user_id/edit", "${ns}LuticateUsersController", "edit",
69 65
             array(LuticatePermissions::USER_EDIT, LuticatePermissions::USER_GET));
70
-        $route->post("$prefix/users/me/edit", "${ns}LuticateUsersBusiness", "editMe",
66
+        $route->post("$prefix/users/me/edit", "${ns}LuticateUsersController", "editMe",
71 67
             LuticatePermissions::USER_EDIT_ME);
72
-        $route->post("$prefix/users/$user_id/setPassword", "${ns}LuticateUsersBusiness", "setPassword",
68
+        $route->post("$prefix/users/$user_id/setPassword", "${ns}LuticateUsersController", "setPassword",
73 69
             array(LuticatePermissions::USER_SET_PASSWORD, LuticatePermissions::USER_GET));
74
-        $route->post("$prefix/users/me/setPassword", "${ns}LuticateUsersBusiness", "setPasswordMe",
70
+        $route->post("$prefix/users/me/setPassword", "${ns}LuticateUsersController", "setPasswordMe",
75 71
             LuticatePermissions::USER_SET_PASSWORD_ME);
76 72
 
77 73
 
78
-        $route->post("$prefix/groups/$id", "${ns}LuticateGroupsBusiness", "getById", LuticatePermissions::GROUP_GET);
79
-        $route->post("$prefix/groups", "${ns}LuticateGroupsBusiness", "getAll", LuticatePermissions::GROUP_GET);
80
-        $route->post("$prefix/groups/add", "${ns}LuticateGroupsBusiness", "add",
74
+        $route->get("$prefix/groups/$group_id", "${ns}LuticateGroupsController", "getById", LuticatePermissions::GROUP_GET);
75
+        $route->get("$prefix/groups", "${ns}LuticateGroupsController", "getAll", LuticatePermissions::GROUP_GET);
76
+        $route->post("$prefix/groups/add", "${ns}LuticateGroupsController", "add",
81 77
             array(LuticatePermissions::GROUP_ADD, LuticatePermissions::GROUP_GET));
82
-        $route->post("$prefix/groups/$group_id/del", "${ns}LuticateGroupsBusiness", "del",
78
+        $route->post("$prefix/groups/$group_id/del", "${ns}LuticateGroupsController", "del",
83 79
             array(LuticatePermissions::GROUP_DEL, LuticatePermissions::GROUP_GET));
84
-        $route->post("$prefix/groups/$group_id/edit", "${ns}LuticateGroupsBusiness", "edit",
80
+        $route->post("$prefix/groups/$group_id/edit", "${ns}LuticateGroupsController", "edit",
85 81
             array(LuticatePermissions::GROUP_EDIT, LuticatePermissions::GROUP_GET));
86
-        $route->post("$prefix/groups/$group_id/addUser/$user_id", "${ns}LuticateGroupsBusiness", "addUser",
82
+        $route->post("$prefix/groups/$group_id/addUser/$user_id", "${ns}LuticateGroupsController", "addUser",
87 83
             array(LuticatePermissions::GROUP_ADD_USER, LuticatePermissions::GROUP_GET));
88
-        $route->post("$prefix/groups/$group_id/delUser/$user_id", "${ns}LuticateGroupsBusiness", "delUser",
84
+        $route->post("$prefix/groups/$group_id/delUser/$user_id", "${ns}LuticateGroupsController", "delUser",
89 85
             array(LuticatePermissions::GROUP_DEL_USER, LuticatePermissions::GROUP_GET));
90 86
 
91 87
 
92
-        $route->post("$prefix/permissions/effective/$user_id/$permission_name", "${ns}LuticatePermissionsBusiness",
88
+        $route->get("$prefix/permissions/effective/$user_id/$permission_name", "${ns}LuticatePermissionsController",
93 89
             "getEffectivePermission", LuticatePermissions::PERM_EFFECTIVE_GET);
94
-        $route->post("$prefix/permissions/effective/me/$permission_name", "${ns}LuticatePermissionsBusiness",
90
+        $route->get("$prefix/permissions/effective/me/$permission_name", "${ns}LuticatePermissionsController",
95 91
             "getEffectivePermissionMe");
96 92
 
97
-        $route->post("$prefix/permissions/$permission_name", "${ns}LuticatePermissionsBusiness", "get",
93
+        $route->get("$prefix/permissions/$permission_name", "${ns}LuticatePermissionsController", "get",
98 94
             LuticatePermissions::PERM_GET);
99
-        $route->post("$prefix/permissions/add/$permission_name/$permission_value", "${ns}LuticatePermissionsBusiness",
95
+        $route->post("$prefix/permissions/add/$permission_name/$permission_value", "${ns}LuticatePermissionsController",
100 96
             "add", array(LuticatePermissions::PERM_ADD, LuticatePermissions::PERM_GET));
101
-        $route->post("$prefix/permissions/$permission_name/del", "${ns}LuticatePermissionsBusiness", "del",
97
+        $route->post("$prefix/permissions/$permission_name/del", "${ns}LuticatePermissionsController", "del",
102 98
             array(LuticatePermissions::PERM_DEL, LuticatePermissions::PERM_GET));
103
-        $route->post("$prefix/permissions/$permission_name/edit/$permission_value", "${ns}LuticatePermissionsBusiness",
99
+        $route->post("$prefix/permissions/$permission_name/edit/$permission_value", "${ns}LuticatePermissionsController",
104 100
             "edit", array(LuticatePermissions::PERM_EDIT, LuticatePermissions::PERM_GET));
105 101
 
106
-        $route->post("$prefix/permissions/group/$group_id/$permission_name", "${ns}LuticatePermissionsGroupsBusiness",
102
+        $route->get("$prefix/permissions/group/$group_id/$permission_name", "${ns}LuticatePermissionsGroupsController",
107 103
             "get", LuticatePermissions::PERM_GROUP_GET);
108 104
         $route->post("$prefix/permissions/group/$group_id/add/$permission_name/$permission_value",
109
-            "${ns}LuticatePermissionsGroupsBusiness", "add", array(LuticatePermissions::PERM_GROUP_ADD,
105
+            "${ns}LuticatePermissionsGroupsController", "add", array(LuticatePermissions::PERM_GROUP_ADD,
110 106
                 LuticatePermissions::PERM_GROUP_GET));
111 107
         $route->post("$prefix/permissions/group/$group_id/$permission_name/del",
112
-            "${ns}LuticatePermissionsGroupsBusiness", "del", array(LuticatePermissions::PERM_GROUP_DEL,
108
+            "${ns}LuticatePermissionsGroupsController", "del", array(LuticatePermissions::PERM_GROUP_DEL,
113 109
                 LuticatePermissions::PERM_GROUP_GET));
114 110
         $route->post("$prefix/permissions/group/$group_id/$permission_name/edit/$permission_value",
115
-            "${ns}LuticatePermissionsGroupsBusiness", "edit", array(LuticatePermissions::PERM_GROUP_EDIT,
111
+            "${ns}LuticatePermissionsGroupsController", "edit", array(LuticatePermissions::PERM_GROUP_EDIT,
116 112
                 LuticatePermissions::PERM_GROUP_GET));
117 113
 
118
-        $route->post("$prefix/permissions/user/$user_id/$permission_name", "${ns}LuticatePermissionsUsersBusiness",
114
+        $route->post("$prefix/permissions/user/$user_id/$permission_name", "${ns}LuticatePermissionsUsersController",
119 115
             "get", LuticatePermissions::PERM_USER_GET);
120 116
         $route->post("$prefix/permissions/user/$user_id/add/$permission_name/$permission_value",
121
-            "${ns}LuticatePermissionsUsersBusiness", "add", array(LuticatePermissions::PERM_USER_ADD,
117
+            "${ns}LuticatePermissionsUsersController", "add", array(LuticatePermissions::PERM_USER_ADD,
122 118
                 LuticatePermissions::PERM_USER_GET));
123
-        $route->post("$prefix/permissions/user/$user_id/$permission_name/del", "${ns}LuticatePermissionsUsersBusiness",
119
+        $route->post("$prefix/permissions/user/$user_id/$permission_name/del", "${ns}LuticatePermissionsUsersController",
124 120
             "del", array(LuticatePermissions::PERM_USER_DEL, LuticatePermissions::PERM_USER_GET));
125 121
         $route->post("$prefix/permissions/user/$user_id/$permission_name/edit/$permission_value",
126
-            "${ns}LuticatePermissionsUsersBusiness", "edit", array(LuticatePermissions::PERM_USER_EDIT,
122
+            "${ns}LuticatePermissionsUsersController", "edit", array(LuticatePermissions::PERM_USER_EDIT,
127 123
                 LuticatePermissions::PERM_USER_GET));
128 124
     }
129 125
 }

+ 1
- 7
src/Auth/Business/LuticateGroupsBusiness.php View File

@@ -30,11 +30,6 @@ class LuticateGroupsBusiness extends LuBusiness {
30 30
         return LuticateGroupsDataAccess::getByName($group_name);
31 31
     }
32 32
 
33
-    public static function getAll($page = 0, $perPage = PHP_INT_MAX)
34
-    {
35
-        return self::search($page, $perPage, "name", "ASC");
36
-    }
37
-
38 33
     public static function hasUser($user_id, $group_id)
39 34
     {
40 35
         return LuticateGroupsDataAccess::hasUser($user_id, $group_id);
@@ -84,7 +79,6 @@ class LuticateGroupsBusiness extends LuBusiness {
84 79
 
85 80
     public static function del($group_id)
86 81
     {
87
-        LuticateGroupsDataAccess::deleteById($group_id);
88
-        return true;
82
+        return LuticateGroupsDataAccess::deleteById($group_id);
89 83
     }
90 84
 }

+ 0
- 20
src/Auth/Business/LuticateUsersBusiness.php View File

@@ -100,16 +100,6 @@ class LuticateUsersBusiness extends LuBusiness {
100 100
         return true;
101 101
     }
102 102
 
103
-    public static function getAll($page = 0, $perPage = PHP_INT_MAX)
104
-    {
105
-        $users = self::search($page, $perPage, "username", "ASC");
106
-        $usersLight = array();
107
-        foreach ($users as $user) {
108
-            $usersLight[] = LuticateUsersLightDbo::fromUserDbo($user);
109
-        }
110
-        return $usersLight;
111
-    }
112
-
113 103
     public static function add($username, $email, $password)
114 104
     {
115 105
         $hash = self::hashPassword($password);
@@ -152,11 +142,6 @@ class LuticateUsersBusiness extends LuBusiness {
152 142
         return true;
153 143
     }
154 144
 
155
-    public static function editMe($email, $user)
156
-    {
157
-        return self::edit($user->getId(), $email);
158
-    }
159
-
160 145
     public static function setPassword($user_id, $password)
161 146
     {
162 147
         if ($user_id != 0) {
@@ -173,9 +158,4 @@ class LuticateUsersBusiness extends LuBusiness {
173 158
         self::login($user->getUsername(), $oldPassword);
174 159
         return self::setPassword($user->getId(), $password);
175 160
     }
176
-
177
-    public static function del($user_id)
178
-    {
179
-        parent::deleteById($user_id);
180
-    }
181 161
 }

+ 44
- 0
src/Auth/Controller/LuticateGroupsController.php View File

@@ -0,0 +1,44 @@
1
+<?php
2
+
3
+namespace Luticate\Auth\Controller;
4
+
5
+use Luticate\Utils\LuController;
6
+use Luticate\Auth\Business\LuticateGroupsBusiness;
7
+use Luticate\Auth\DBO\LuticateGroupsDbo;
8
+
9
+class LuticateGroupsController extends LuController {
10
+    protected function getBusiness()
11
+    {
12
+        return new LuticateGroupsBusiness();
13
+    }
14
+
15
+    public function getById($group_id)
16
+    {
17
+        return LuticateGroupsBusiness::getById($group_id);
18
+    }
19
+
20
+    public function add($group_name)
21
+    {
22
+        return LuticateGroupsBusiness::add($group_name);
23
+    }
24
+
25
+    public function del($group_id)
26
+    {
27
+        return LuticateGroupsBusiness::del($group_id);
28
+    }
29
+
30
+    public function edit($group_id, $group_name)
31
+    {
32
+        return LuticateGroupsBusiness::edit($group_id, $group_name);
33
+    }
34
+
35
+    public function addUser($user_id, $group_id)
36
+    {
37
+        return LuticateGroupsBusiness::addUser($user_id, $group_id);
38
+    }
39
+
40
+    public static function delUser($user_id, $group_id)
41
+    {
42
+        return LuticateGroupsBusiness::delUser($user_id, $group_id);
43
+    }
44
+}

+ 14
- 0
src/Auth/Controller/LuticatePermissionsController.php View File

@@ -0,0 +1,14 @@
1
+<?php
2
+
3
+namespace Luticate\Auth\Controller;
4
+
5
+use Luticate\Utils\LuController;
6
+use Luticate\Auth\Business\LuticatePermissionsBusiness;
7
+use Luticate\Auth\DBO\LuticatePermissionsDbo;
8
+
9
+class LuticatePermissionsController extends LuController {
10
+    protected function getBusiness()
11
+    {
12
+        return new LuticatePermissionsBusiness();
13
+    }
14
+}

+ 14
- 0
src/Auth/Controller/LuticatePermissionsGroupsController.php View File

@@ -0,0 +1,14 @@
1
+<?php
2
+
3
+namespace Luticate\Auth\Controller;
4
+
5
+use Luticate\Utils\LuController;
6
+use Luticate\Auth\Business\LuticatePermissionsGroupsBusiness;
7
+use Luticate\Auth\DBO\LuticatePermissionsGroupsDbo;
8
+
9
+class LuticatePermissionsGroupsController extends LuController {
10
+    protected function getBusiness()
11
+    {
12
+        return new LuticatePermissionsGroupsBusiness();
13
+    }
14
+}

+ 14
- 0
src/Auth/Controller/LuticatePermissionsUsersController.php View File

@@ -0,0 +1,14 @@
1
+<?php
2
+
3
+namespace Luticate\Auth\Controller;
4
+
5
+use Luticate\Utils\LuController;
6
+use Luticate\Auth\Business\LuticatePermissionsUsersBusiness;
7
+use Luticate\Auth\DBO\LuticatePermissionsUsersDbo;
8
+
9
+class LuticatePermissionsUsersController extends LuController {
10
+    protected function getBusiness()
11
+    {
12
+        return new LuticatePermissionsUsersBusiness();
13
+    }
14
+}

+ 59
- 0
src/Auth/Controller/LuticateUsersController.php View File

@@ -0,0 +1,59 @@
1
+<?php
2
+
3
+namespace Luticate\Auth\Controller;
4
+
5
+use Luticate\Utils\LuController;
6
+use Luticate\Auth\Business\LuticateUsersBusiness;
7
+use Luticate\Auth\DBO\LuticateUsersDbo;
8
+
9
+class LuticateUsersController extends LuController {
10
+    protected function getBusiness()
11
+    {
12
+        return new LuticateUsersBusiness();
13
+    }
14
+
15
+    public function login($username, $password)
16
+    {
17
+        return LuticateUsersBusiness::login($username, $password);
18
+    }
19
+
20
+    public function logout($user)
21
+    {
22
+        return LuticateUsersBusiness::logout($user);
23
+    }
24
+
25
+    public function getById($user_id)
26
+    {
27
+        return LuticateUsersBusiness::getById($user_id);
28
+    }
29
+
30
+    public function add($username, $email, $password)
31
+    {
32
+        return LuticateUsersBusiness::add($username, $email, $password);
33
+    }
34
+
35
+    public function del($user_id)
36
+    {
37
+        return LuticateUsersBusiness::deleteById($user_id);
38
+    }
39
+
40
+    public function edit($email, $user_id)
41
+    {
42
+        return LuticateUsersBusiness::edit($user_id, $email);
43
+    }
44
+
45
+    public function editMe($email, $user)
46
+    {
47
+        return LuticateUsersBusiness::edit($user->getId(), $email);
48
+    }
49
+
50
+    public function setPassword($password, $user_id)
51
+    {
52
+        return LuticateUsersBusiness::setPassword($user_id, $password);
53
+    }
54
+
55
+    public function setPasswordMe($password, $oldPassword, $user)
56
+    {
57
+        return LuticateUsersBusiness::setPasswordMe($password, $oldPassword, $user);
58
+    }
59
+}

Loading…
Cancel
Save