Skip to content

Commit f79a2e6

Browse files
committed
Исправлено неверное приведение к типам в параметрах списка id,
дополнены разные мелочи close #3
1 parent 14d2557 commit f79a2e6

File tree

13 files changed

+62
-10
lines changed

13 files changed

+62
-10
lines changed

clientExamples/instantcms/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
## Использование
1010

11+
Заполнить константы api_key, api_point, api_point_execute своими данными.
12+
Создать директорию /cache/api/. В ней будут кэшироваться ответы.
13+
1114
Вызовы можно осуществлять из любого места кода InstantCMS
1215

1316
Обычные методы

clientExamples/instantcms/api.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,31 @@ public static function getExecute($params, $cacheable = false, $is_upload = fals
191191
return self::getMethod('execute', ['code' => json_encode($params)], $cacheable, $is_upload, self::getApiExecutePoint());
192192
}
193193

194+
public static function arrayToForm($data) {
195+
196+
$form = new cmsForm();
197+
198+
$form->addFieldset('', 'basic');
199+
200+
foreach ($data as $fsets) {
201+
foreach ($fsets['fields'] as $field) {
202+
203+
if($field['name'] == 'csrf_token'){
204+
cmsUser::sessionSet('csrf_token', $field['default']);
205+
continue;
206+
}
207+
208+
$field_class = 'field' . string_to_camel('_', $field['field_type'] );
209+
210+
$form->addField('basic',
211+
new $field_class($field['name'], $field)
212+
);
213+
214+
}
215+
}
216+
217+
return $form;
218+
219+
}
220+
194221
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ public function run($method_name = null){
177177

178178
}
179179

180+
// проверяем csrf, если включена проверка
181+
if(!empty($this->method_action->check_csrf)){
182+
if (!cmsForm::validateCSRFToken($this->request->get('csrf_token', ''))){
183+
return $this->error(0, LANG_API_ERROR_CSRF_TOKEN);
184+
}
185+
}
186+
180187
// проверяем sig, если включена проверка
181188
if(!empty($this->method_action->check_sig)){
182189
if(!check_sig($this->request->get('sig', ''))){

package/system/controllers/api/api_actions/api_auth_login.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,22 @@ public function validateApiRequest() {
197197

198198
public function run(){
199199

200+
$is_first_auth = null;
201+
202+
if(!empty($this->user['id'])){
203+
if(cmsUser::getUPS('first_auth', $this->user['id'])){
204+
cmsUser::deleteUPS('first_auth', $this->user['id']);
205+
$is_first_auth = true;
206+
} else {
207+
$is_first_auth = false;
208+
}
209+
}
210+
200211
$this->result = array(
201212
'wait_2fa' => $this->wait_2fa,
202213
'2fa_type' => $this->twofa_type,
203214
'2fa_params' => $this->twofa_params,
215+
'is_first_auth' => $is_first_auth,
204216
'remember_token' => (isset(cmsUser::$auth_token) ? cmsUser::$auth_token : false),
205217
'session_name' => session_name(),
206218
'session_id' => session_id(),
@@ -212,3 +224,4 @@ public function run(){
212224
}
213225

214226
}
227+

package/system/controllers/api/api_actions/api_content_get.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class actionContentApiContentGet extends cmsAction {
6666
)
6767
),
6868
'ids' => array(
69-
'default' => 0,
69+
'default' => '',
7070
'rules' => array(
7171
array('regexp', '/^([0-9,]+)$/i')
7272
)

package/system/controllers/api/api_actions/api_content_get_categories.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class actionContentApiContentGetCategories extends cmsAction {
2424
*/
2525
public $request_params = array(
2626
'cat_ids' => array(
27-
'default' => 0,
27+
'default' => '',
2828
'rules' => array(
2929
array('regexp', '/^([0-9,]+)$/i')
3030
)

package/system/controllers/api/api_actions/api_content_get_fields.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class actionContentApiContentGetFields extends cmsAction {
4848
)
4949
),
5050
'ids' => array(
51-
'default' => 0,
51+
'default' => '',
5252
'rules' => array(
5353
array('regexp', '/^([0-9,]+)$/i')
5454
)

package/system/controllers/api/api_actions/api_content_get_folders.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class actionContentApiContentGetFolders extends cmsAction {
3030
)
3131
),
3232
'ids' => array(
33-
'default' => 0,
33+
'default' => '',
3434
'rules' => array(
3535
array('regexp', '/^([0-9,]+)$/i')
3636
)

package/system/controllers/api/api_actions/api_content_get_props.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class actionContentApiContentGetProps extends cmsAction {
3636
)
3737
),
3838
'ids' => array(
39-
'default' => 0,
39+
'default' => '',
4040
'rules' => array(
4141
array('regexp', '/^([0-9,]+)$/i')
4242
)

package/system/controllers/api/api_actions/api_messages_readed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class actionMessagesApiMessagesReaded extends cmsAction {
1212

1313
public $request_params = array(
1414
'ids' => array(
15-
'default' => 0,
15+
'default' => '',
1616
'rules' => array(
1717
array('required'),
1818
array('regexp', '/^([0-9]{1}[0-9,]*)$/')

0 commit comments

Comments
 (0)