66 protected function end()
69 \CMain::finalActions();
83 if($this->request->isPost())
85 \CUtil::jSPostUnescape();
96 $this->sendJsonErrorResponse();
124 $event =
new Event(
'report', static::EVENT_ON_BEFORE_ACTION .
$action, array(
126 'controller' => $this,
130 if($event->getResults())
132 foreach($event->getResults() as $eventResult)
134 if($eventResult->getType() != EventResult::SUCCESS)
163 if(!defined(
'PUBLIC_AJAX_MODE'))
165 define(
'PUBLIC_AJAX_MODE',
true);
169 $APPLICATION->restartBuffer();
171 if(!empty($params[
'http_status']) && $params[
'http_status'] == 403)
173 header(
'HTTP/1.0 403 Forbidden',
true, 403);
175 if(!empty($params[
'http_status']) && $params[
'http_status'] == 500)
177 header(
'HTTP/1.0 500 Internal Server Error',
true, 500);
179 if(!empty($params[
'http_status']) && $params[
'http_status'] == 510)
181 header(
'HTTP/1.0 510 Not Extended',
true, 510);
184 header(
'Content-Type:application/json; charset=UTF-8');
185 echo Json::encode($response);
194 protected function sendJsonErrorResponse()
201 'message' => $error->getMessage(),
202 'code' => $error->getCode(),
206 $this->sendJsonResponse(array(
207 'status' => self::STATUS_ERROR,
220 'status' => self::STATUS_DENIED,
221 'message' => $message,
233 'status' => self::STATUS_INVALID_SIGN,
234 'message' => $message,
245 $response[
'status'] = self::STATUS_SUCCESS;
258 $APPLICATION->restartBuffer();
271 return $this->errorCollection->toArray();
281 return $this->errorCollection->getErrorByCode($code);
292 $action = mb_strtolower($this->action);
294 if(!isset($listOfActions[
$action]))
296 $this->errorCollection->add(array(
new Error(
Loc::getMessage(
'REPORT_CONTROLLER_ERROR_UNKNOWN_ACTION',
297 array(
'#ACTION#' => $action)), self::ERROR_UNKNOWN_ACTION)));
301 $this->realActionName = $action;
302 $description = $listOfActions[$this->realActionName];
303 $this->
setAction($description[
'name'], $description);
317 $normalized = array();
318 foreach($listOfActions as
$action => $description)
331 return array_change_key_case($normalized, CASE_LOWER);
352 if(!is_array($description))
354 $description = array(
355 'method' => array(
'GET'),
356 'name' => $description,
357 'check_csrf_token' =>
false,
358 'redirect_on_auth' =>
true,
359 'close_session' =>
false,
362 if(empty($description[
'name']))
364 $description[
'name'] =
$action;
366 if(!isset($description[
'redirect_on_auth']))
368 $description[
'redirect_on_auth'] =
false;
370 if(!isset($description[
'close_session']))
372 $description[
'close_session'] =
false;
385 if($this->errorCollection->count())
387 $this->sendJsonErrorResponse();
393 if($description[
'redirect_on_auth'])
395 LocalRedirect(SITE_DIR .
'auth/?backurl=' .
406 (isset($description[
'check_csrf_token']) && $description[
'check_csrf_token'] ===
true) ||
407 ($this->request->isPost() && !isset($description[
'check_csrf_token'])))
410 if(!check_bitrix_sessid() && !check_bitrix_sessid(
'token_sid'))
416 if(!in_array($this->request->getRequestMethod(), $description[
'method']))
465 return $this->action;
474 return $this->actionDescription;
486 $this->actionDescription = $description;
531 if($description[
'close_session'] ===
true)
534 session_write_close();
536 $actionMethod =
'processAction' . $this->
getAction();
538 return $this->$actionMethod();
549 $this->errorCollection->add(array(
new Error($e->getMessage())));
550 $this->sendJsonErrorResponse();
590 foreach ($required as $item)
592 if(!isset($inputParams[$item]) || (!$inputParams[$item] &&
593 !(is_string($inputParams[$item]) && mb_strlen($inputParams[$item]))))
595 $this->errorCollection->add(array(
new Error(
597 array(
'#PARAM#' => $item)), self::ERROR_REQUIRED_PARAMETER)));
614 foreach($required as $item)
616 $params[$item] = $this->request->getPost($item);
632 foreach($required as $item)
634 $params[$item] = $this->request->getQuery($item);
650 foreach($required as $item)
652 $params[$item] = $this->request->getFile($item);
665 return $this->request->isAjaxRequest();
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
sendJsonSuccessResponse(array $response=array())
const STATUS_INVALID_SIGN
runProcessingIfUserNotAuthorized()
const EVENT_ON_BEFORE_ACTION
sendJsonInvalidSignResponse($message='')
triggerOnBeforeAction($action)
const ERROR_REQUIRED_PARAMETER
processBeforeAction($actionName)
checkRequiredFilesParams(array $required)
setAction($action, array $description)
const ERROR_UNKNOWN_ACTION
runProcessingException(\Exception $e)
sendJsonResponse($response, $params=null)
normalizeActionDescription($action, $description)
checkRequiredPostParams(array $required)
checkRequiredGetParams(array $required)
runProcessingIfInvalidCsrfToken()
normalizeListOfAction(array $listOfActions)
checkRequiredInputParams(array $inputParams, array $required)
sendJsonAccessDeniedResponse($message='')