@@ -34,14 +34,14 @@ class Key extends REST_Controller {
34
34
public function index_put ()
35
35
{
36
36
// Build a new key
37
- $ key = self :: _generate_key ();
37
+ $ key = $ this -> _generate_key ();
38
38
39
39
// If no key level provided, provide a generic key
40
40
$ level = $ this ->put ('level ' ) ? $ this ->put ('level ' ) : 1 ;
41
41
$ ignore_limits = ctype_digit ($ this ->put ('ignore_limits ' )) ? (int ) $ this ->put ('ignore_limits ' ) : 1 ;
42
42
43
43
// Insert the new key
44
- if (self :: _insert_key ($ key , ['level ' => $ level , 'ignore_limits ' => $ ignore_limits ]))
44
+ if ($ this -> _insert_key ($ key , ['level ' => $ level , 'ignore_limits ' => $ ignore_limits ]))
45
45
{
46
46
$ this ->response ([
47
47
'status ' => TRUE ,
@@ -68,7 +68,7 @@ public function index_delete()
68
68
$ key = $ this ->delete ('key ' );
69
69
70
70
// Does this key exist?
71
- if (!self :: _key_exists ($ key ))
71
+ if (!$ this -> _key_exists ($ key ))
72
72
{
73
73
// It doesn't appear the key exists
74
74
$ this ->response ([
@@ -78,7 +78,7 @@ public function index_delete()
78
78
}
79
79
80
80
// Destroy it
81
- self :: _delete_key ($ key );
81
+ $ this -> _delete_key ($ key );
82
82
83
83
// Respond that the key was destroyed
84
84
$ this ->response ([
@@ -99,7 +99,7 @@ public function level_post()
99
99
$ new_level = $ this ->post ('level ' );
100
100
101
101
// Does this key exist?
102
- if (!self :: _key_exists ($ key ))
102
+ if (!$ this -> _key_exists ($ key ))
103
103
{
104
104
// It doesn't appear the key exists
105
105
$ this ->response ([
@@ -109,7 +109,7 @@ public function level_post()
109
109
}
110
110
111
111
// Update the key level
112
- if (self :: _update_key ($ key , ['level ' => $ new_level ]))
112
+ if ($ this -> _update_key ($ key , ['level ' => $ new_level ]))
113
113
{
114
114
$ this ->response ([
115
115
'status ' => TRUE ,
@@ -126,7 +126,7 @@ public function level_post()
126
126
}
127
127
128
128
/**
129
- * Change the level
129
+ * Suspend a key
130
130
*
131
131
* @access public
132
132
* @return void
@@ -136,7 +136,7 @@ public function suspend_post()
136
136
$ key = $ this ->post ('key ' );
137
137
138
138
// Does this key exist?
139
- if (!self :: _key_exists ($ key ))
139
+ if (!$ this -> _key_exists ($ key ))
140
140
{
141
141
// It doesn't appear the key exists
142
142
$ this ->response ([
@@ -146,7 +146,7 @@ public function suspend_post()
146
146
}
147
147
148
148
// Update the key level
149
- if (self :: _update_key ($ key , ['level ' => 0 ]))
149
+ if ($ this -> _update_key ($ key , ['level ' => 0 ]))
150
150
{
151
151
$ this ->response ([
152
152
'status ' => TRUE ,
@@ -163,15 +163,15 @@ public function suspend_post()
163
163
}
164
164
165
165
/**
166
- * Remove a key from the database to stop it working
166
+ * Regenerate a key
167
167
*
168
168
* @access public
169
169
* @return void
170
170
*/
171
171
public function regenerate_post ()
172
172
{
173
173
$ old_key = $ this ->post ('key ' );
174
- $ key_details = self :: _get_key ($ old_key );
174
+ $ key_details = $ this -> _get_key ($ old_key );
175
175
176
176
// Does this key exist?
177
177
if (!$ key_details )
@@ -184,13 +184,13 @@ public function regenerate_post()
184
184
}
185
185
186
186
// Build a new key
187
- $ new_key = self :: _generate_key ();
187
+ $ new_key = $ this -> _generate_key ();
188
188
189
189
// Insert the new key
190
- if (self :: _insert_key ($ new_key , ['level ' => $ key_details ->level , 'ignore_limits ' => $ key_details ->ignore_limits ]))
190
+ if ($ this -> _insert_key ($ new_key , ['level ' => $ key_details ->level , 'ignore_limits ' => $ key_details ->ignore_limits ]))
191
191
{
192
192
// Suspend old key
193
- self :: _update_key ($ old_key , ['level ' => 0 ]);
193
+ $ this -> _update_key ($ old_key , ['level ' => 0 ]);
194
194
195
195
$ this ->response ([
196
196
'status ' => TRUE ,
@@ -218,12 +218,12 @@ private function _generate_key()
218
218
// If an error occurred, then fall back to the previous method
219
219
if ($ salt === FALSE )
220
220
{
221
- $ salt = hash ('sha256 ' , time () . mt_rand ());
221
+ $ salt = hash ('sha256 ' , time () . mt_rand ());
222
222
}
223
+
223
224
$ new_key = substr ($ salt , 0 , config_item ('rest_key_length ' ));
224
225
}
225
- while (self ::_key_exists ($ new_key ));
226
- // Already in the DB? Fail. Try again
226
+ while ($ this ->_key_exists ($ new_key ));
227
227
228
228
return $ new_key ;
229
229
}
@@ -233,16 +233,16 @@ private function _generate_key()
233
233
private function _get_key ($ key )
234
234
{
235
235
return $ this ->db
236
- ->where (config_item ('rest_key_column ' ), $ key )
237
- ->get (config_item ('rest_keys_table ' ))
238
- ->row ();
236
+ ->where (config_item ('rest_key_column ' ), $ key )
237
+ ->get (config_item ('rest_keys_table ' ))
238
+ ->row ();
239
239
}
240
240
241
241
private function _key_exists ($ key )
242
242
{
243
243
return $ this ->db
244
- ->where (config_item ('rest_key_column ' ), $ key )
245
- ->count_all_results (config_item ('rest_keys_table ' )) > 0 ;
244
+ ->where (config_item ('rest_key_column ' ), $ key )
245
+ ->count_all_results (config_item ('rest_keys_table ' )) > 0 ;
246
246
}
247
247
248
248
private function _insert_key ($ key , $ data )
0 commit comments