Skip to content

Commit 864276c

Browse files
committed
новые методы,
небольшие исправления и дополнения
1 parent 5ff6301 commit 864276c

27 files changed

+1054
-51
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414

1515
## Ссылки
1616

17-
* [Официальный сайт InstantCMS](http://www.instantcms.ru/)
18-
* [Документация компонента](http://docs.instantcms.ru/manual/components/api)
17+
* [Официальный сайт InstantCMS](https://instantcms.ru/)
18+
* [Документация компонента](https://docs.instantcms.ru/manual/components/api)
1919
* [English README](https://github.com/instantsoft/icms2-json-api-component/blob/master/README.en.md)

manifest.en.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ addon_id = "600"
55

66
[version]
77
major = "2"
8-
minor = "0"
9-
build = "1"
10-
date = "20180105"
8+
minor = "1"
9+
build = "0"
10+
date = "20180913"
1111

1212
[depends]
1313
core = "2.5.0"
1414

1515
[author]
1616
name = "InstantCMS Team"
17-
url = "http://instantcms.ru"
17+
url = "https://instantcms.ru"
1818

1919
[install]
2020
type = "component"

manifest.ru.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ addon_id = "600"
55

66
[version]
77
major = "2"
8-
minor = "0"
9-
build = "1"
10-
date = "20180105"
8+
minor = "1"
9+
build = "0"
10+
date = "20180913"
1111

1212
[depends]
1313
core = "2.5.0"
1414

1515
[author]
1616
name = "InstantCMS Team"
17-
url = "http://instantcms.ru"
17+
url = "https://instantcms.ru"
1818

1919
[install]
2020
type = "component"

package/system/controllers/api/actions/method.php

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/******************************************************************************/
33
// //
4-
// InstantMedia 2017 //
4+
// InstantMedia //
55
// http://instantmedia.ru/, support@instantmedia.ru //
66
// written by Fuze //
77
// //
@@ -105,7 +105,7 @@ public function run($method_name = null){
105105

106106
// проверяем сначала экшен
107107
// Важно! Болокируйте экшен от прямого выполнения свойством lock_explicit_call
108-
// http://docs.instantcms.ru/dev/controllers/actions#действия-во-внешних-файлах
108+
// https://docs.instantcms.ru/dev/controllers/actions#действия-во-внешних-файлах
109109

110110
$api_dir_action_file = $this->root_path.'api_actions/'.$this->method_controller->current_action.'.php';
111111
$action_file = $this->method_controller->root_path.'actions/'.$this->method_controller->current_action.'.php';
@@ -117,6 +117,10 @@ public function run($method_name = null){
117117

118118
include_once $action_file;
119119

120+
if(!class_exists($class_name, false)){
121+
cmsCore::error(sprintf(ERR_CLASS_NOT_DEFINED, str_replace(PATH, '', $action_file), $class_name));
122+
}
123+
120124
$this->method_action = new $class_name($this->method_controller);
121125

122126
} else {
@@ -128,10 +132,14 @@ public function run($method_name = null){
128132

129133
if (is_readable($hook_file)){
130134

131-
if (!class_exists($class_name)){
135+
if (!class_exists($class_name, false)){
132136
include_once $hook_file;
133137
}
134138

139+
if(!class_exists($class_name, false)){
140+
cmsCore::error(sprintf(ERR_CLASS_NOT_DEFINED, str_replace(PATH, '', $hook_file), $class_name));
141+
}
142+
135143
$this->method_action = new $class_name($this->method_controller);
136144

137145
}
@@ -162,7 +170,10 @@ public function run($method_name = null){
162170
return $this->error(777);
163171
}
164172

165-
cmsUser::setIp($ip);
173+
// совместимость
174+
if(method_exists('cmsUser', 'setIp')){
175+
cmsUser::setIp($ip);
176+
}
166177

167178
}
168179

@@ -180,6 +191,18 @@ public function run($method_name = null){
180191
}
181192
}
182193

194+
// проверяем админ доступ, если метод этого требует
195+
if(!empty($this->method_action->admin_required)){
196+
if(!$this->cms_user->is_logged){
197+
return $this->error(71);
198+
}
199+
if(!$this->cms_user->is_admin){
200+
return $this->error(710);
201+
}
202+
// грузим язык админки
203+
cmsCore::loadControllerLanguage('admin');
204+
}
205+
183206
// ставим ключ API в свойство
184207
$this->method_action->key = $this->key;
185208
$this->method_action->method_name = $this->method_name;
@@ -289,29 +312,37 @@ private function validateMethodParams() {
289312
$this->request->set($param_name, $value);
290313

291314
} elseif(!is_null($value) && isset($rules['default'])){
315+
292316
$value = $this->request->get($param_name, $rules['default']);
317+
318+
// для применения типизации переменной
319+
$this->request->set($param_name, $value);
320+
293321
}
294322

295-
foreach ($rules['rules'] as $rule) {
323+
if(!empty($rules['rules'])){
324+
foreach ($rules['rules'] as $rule) {
296325

297-
if (!$rule) { continue; }
326+
if (!$rule) { continue; }
298327

299-
$validate_function = "validate_{$rule[0]}";
328+
$validate_function = "validate_{$rule[0]}";
300329

301-
$rule[] = $value;
330+
$rule[] = $value;
302331

303-
unset($rule[0]);
332+
unset($rule[0]);
304333

305-
$result = call_user_func_array(array($this, $validate_function), $rule);
334+
$result = call_user_func_array(array($this, $validate_function), $rule);
306335

307-
// если получилось false, то дальше не проверяем, т.к.
308-
// ошибка уже найдена
309-
if ($result !== true) {
310-
$errors[$param_name] = $result;
311-
break;
312-
}
336+
// если получилось false, то дальше не проверяем, т.к.
337+
// ошибка уже найдена
338+
if ($result !== true) {
339+
$errors[$param_name] = $result;
340+
break;
341+
}
313342

343+
}
314344
}
345+
315346
}
316347

317348
if (!sizeof($errors)) { return false; }
@@ -343,8 +374,8 @@ public function checkRequest() {
343374
return $this->error(23);
344375
}
345376

346-
$is_view = !$this->key['methods_access']['allow'] || in_array($this->method_name, $this->key['methods_access']['allow']);
347-
$is_hide = $this->key['methods_access']['disallow'] && in_array($this->method_name, $this->key['methods_access']['disallow']);
377+
$is_view = !$this->key['key_methods']['allow'] || in_array($this->method_name, $this->key['key_methods']['allow']);
378+
$is_hide = $this->key['key_methods']['disallow'] && in_array($this->method_name, $this->key['key_methods']['disallow']);
348379

349380
// проверяем доступ к методу
350381
if (!$is_view || $is_hide) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
class actionAuthApiAuthLogout extends cmsAction {
4+
5+
public $lock_explicit_call = true;
6+
7+
public $result;
8+
9+
public $auth_required = true;
10+
11+
public function run(){
12+
13+
$user_id = $this->cms_user->id;
14+
15+
cmsEventsManager::hook('auth_logout', $this->cms_user->id);
16+
17+
cmsUser::logout();
18+
19+
$this->result = array(
20+
'user_id' => $user_id
21+
);
22+
23+
}
24+
25+
}

0 commit comments

Comments
 (0)