1
|
|
|
<?php namespace Myth\Auth; |
2
|
|
|
/** |
3
|
|
|
* Sprint |
4
|
|
|
* |
5
|
|
|
* A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
6
|
|
|
* |
7
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
8
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
9
|
|
|
* in the Software without restriction, including without limitation the rights |
10
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
12
|
|
|
* furnished to do so, subject to the following conditions: |
13
|
|
|
* |
14
|
|
|
* The above copyright notice and this permission notice shall be included in |
15
|
|
|
* all copies or substantial portions of the Software. |
16
|
|
|
* |
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
23
|
|
|
* THE SOFTWARE. |
24
|
|
|
* |
25
|
|
|
* @package Sprint |
26
|
|
|
* @author Lonnie Ezell |
27
|
|
|
* @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
28
|
|
|
* @license http://opensource.org/licenses/MIT (MIT) |
29
|
|
|
* @link http://sprintphp.com |
30
|
|
|
* @since Version 1.0 |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
interface AuthorizeInterface { |
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Returns the latest error string. |
37
|
|
|
* |
38
|
|
|
* @return mixed |
39
|
|
|
*/ |
40
|
|
|
public function error(); |
41
|
|
|
|
42
|
|
|
//-------------------------------------------------------------------- |
43
|
|
|
|
44
|
|
|
//-------------------------------------------------------------------- |
45
|
|
|
// Actions |
46
|
|
|
//-------------------------------------------------------------------- |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Checks to see if a user is in a group. |
50
|
|
|
* |
51
|
|
|
* Groups can be either a string, with the name of the group, an INT |
52
|
|
|
* with the ID of the group, or an array of strings/ids that the |
53
|
|
|
* user must belong to ONE of. (It's an OR check not an AND check) |
54
|
|
|
* |
55
|
|
|
* @param $groups |
56
|
|
|
* |
57
|
|
|
* @return bool |
58
|
|
|
*/ |
59
|
|
|
public function inGroup($groups, $user_id); |
60
|
|
|
|
61
|
|
|
//-------------------------------------------------------------------- |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Checks a user's groups to see if they have the specified permission. |
65
|
|
|
* |
66
|
|
|
* @param int|string $permission |
67
|
|
|
* @param int|string $user_id |
68
|
|
|
* |
69
|
|
|
* @return mixed |
70
|
|
|
*/ |
71
|
|
|
public function hasPermission($permission, $user_id); |
72
|
|
|
|
73
|
|
|
//-------------------------------------------------------------------- |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Makes a member a part of a group. |
77
|
|
|
* |
78
|
|
|
* @param $user_id |
79
|
|
|
* @param $group // Either ID or name |
80
|
|
|
* |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
|
|
public function addUserToGroup($user_id, $group); |
84
|
|
|
|
85
|
|
|
//-------------------------------------------------------------------- |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Removes a single user from a group. |
89
|
|
|
* |
90
|
|
|
* @param $user_id |
91
|
|
|
* @param $group |
92
|
|
|
* |
93
|
|
|
* @return mixed |
94
|
|
|
*/ |
95
|
|
|
public function removeUserFromGroup($user_id, $group); |
96
|
|
|
|
97
|
|
|
//-------------------------------------------------------------------- |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Adds a single permission to a single group. |
101
|
|
|
* |
102
|
|
|
* @param int|string $permission |
103
|
|
|
* @param int|string $group |
104
|
|
|
* |
105
|
|
|
* @return mixed |
106
|
|
|
*/ |
107
|
|
|
public function addPermissionToGroup($permission, $group); |
108
|
|
|
|
109
|
|
|
//-------------------------------------------------------------------- |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Removes a single permission from a group. |
113
|
|
|
* |
114
|
|
|
* @param int|string $permission |
115
|
|
|
* @param int|string $group |
116
|
|
|
* |
117
|
|
|
* @return mixed |
118
|
|
|
*/ |
119
|
|
|
public function removePermissionFromGroup($permission, $group); |
120
|
|
|
|
121
|
|
|
//-------------------------------------------------------------------- |
122
|
|
|
|
123
|
|
|
//-------------------------------------------------------------------- |
124
|
|
|
// Groups |
125
|
|
|
//-------------------------------------------------------------------- |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Grabs the details about a single group. |
129
|
|
|
* |
130
|
|
|
* @param $group |
131
|
|
|
* |
132
|
|
|
* @return object|null |
133
|
|
|
*/ |
134
|
|
|
public function group($group); |
135
|
|
|
|
136
|
|
|
//-------------------------------------------------------------------- |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Grabs an array of all groups. |
140
|
|
|
* |
141
|
|
|
* @return array of objects |
142
|
|
|
*/ |
143
|
|
|
public function groups(); |
144
|
|
|
|
145
|
|
|
//-------------------------------------------------------------------- |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param $name |
149
|
|
|
* @param string $description |
150
|
|
|
* |
151
|
|
|
* @return mixed |
152
|
|
|
*/ |
153
|
|
|
public function createGroup($name, $description=''); |
154
|
|
|
|
155
|
|
|
//-------------------------------------------------------------------- |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Deletes a single group. |
159
|
|
|
* |
160
|
|
|
* @param int $group_id |
161
|
|
|
* |
162
|
|
|
* @return bool |
163
|
|
|
*/ |
164
|
|
|
public function deleteGroup($group_id); |
165
|
|
|
|
166
|
|
|
//-------------------------------------------------------------------- |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Updates a single group's information. |
170
|
|
|
* |
171
|
|
|
* @param $id |
172
|
|
|
* @param $name |
173
|
|
|
* @param string $description |
174
|
|
|
* |
175
|
|
|
* @return mixed |
176
|
|
|
*/ |
177
|
|
|
public function updateGroup($id, $name, $description=''); |
178
|
|
|
|
179
|
|
|
//-------------------------------------------------------------------- |
180
|
|
|
|
181
|
|
|
//-------------------------------------------------------------------- |
182
|
|
|
// Permissions |
183
|
|
|
//-------------------------------------------------------------------- |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Returns the details about a single permission. |
187
|
|
|
* |
188
|
|
|
* @param int|string $permission |
189
|
|
|
* |
190
|
|
|
* @return object|null |
191
|
|
|
*/ |
192
|
|
|
public function permission($permission); |
193
|
|
|
|
194
|
|
|
//-------------------------------------------------------------------- |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Returns an array of all permissions in the system. |
198
|
|
|
* |
199
|
|
|
* @return mixed |
200
|
|
|
*/ |
201
|
|
|
public function permissions(); |
202
|
|
|
|
203
|
|
|
//-------------------------------------------------------------------- |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Creates a single permission. |
207
|
|
|
* |
208
|
|
|
* @param $name |
209
|
|
|
* @param string $description |
210
|
|
|
* |
211
|
|
|
* @return mixed |
212
|
|
|
*/ |
213
|
|
|
public function createPermission($name, $description=''); |
214
|
|
|
|
215
|
|
|
//-------------------------------------------------------------------- |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Deletes a single permission and removes that permission from all groups. |
219
|
|
|
* |
220
|
|
|
* @param $permission |
221
|
|
|
* |
222
|
|
|
* @return mixed |
223
|
|
|
*/ |
224
|
|
|
public function deletePermission($permission); |
225
|
|
|
|
226
|
|
|
//-------------------------------------------------------------------- |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Updates the details for a single permission. |
230
|
|
|
* |
231
|
|
|
* @param int $id |
232
|
|
|
* @param string $name |
233
|
|
|
* @param string $description |
234
|
|
|
* |
235
|
|
|
* @return bool |
236
|
|
|
*/ |
237
|
|
|
public function updatePermission($id, $name, $description=''); |
238
|
|
|
|
239
|
|
|
//-------------------------------------------------------------------- |
240
|
|
|
|
241
|
|
|
} |
242
|
|
|
|