51 protected function end()
53 include($_SERVER[
"DOCUMENT_ROOT"].BX_ROOT.
"/modules/main/include/epilog_after.php");
61 if($this->request->isPost())
63 \CUtil::jSPostUnescape();
74 $this->sendJsonErrorResponse();
100 if(!defined(
'PUBLIC_AJAX_MODE'))
102 define(
'PUBLIC_AJAX_MODE',
true);
106 $APPLICATION->restartBuffer();
108 if(!empty($params[
'http_status']) && $params[
'http_status'] == 403)
110 header(
'HTTP/1.0 403 Forbidden',
true, 403);
112 if(!empty($params[
'http_status']) && $params[
'http_status'] == 500)
114 header(
'HTTP/1.0 500 Internal Server Error',
true, 500);
117 header(
'Content-Type:application/json; charset=UTF-8');
118 echo Json::encode($response);
123 protected function sendJsonErrorResponse()
130 'message' => $error->getMessage(),
131 'code' => $error->getCode(),
135 $this->sendJsonResponse(array(
136 'status' => self::STATUS_ERROR,
144 'status' => self::STATUS_DENIED,
145 'message' => $message,
152 'status' => self::STATUS_INVALID_SIGN,
153 'message' => $message,
159 $response[
'status'] = self::STATUS_SUCCESS;
165 $response[
'status'] = self::STATUS_PROCESSING;
171 $response[
'status'] = self::STATUS_COMPLETED;
178 $APPLICATION->restartBuffer();
190 return $this->errorCollection->toArray();
198 return $this->errorCollection->getErrorsByCode($code);
206 return $this->errorCollection->getErrorByCode($code);
212 $action = mb_strtolower($this->action);
214 if(!isset($listOfActions[
$action]))
216 $this->errorCollection->add(array(
new Error(
Loc::getMessage(
'LISTS_CONTROLLER_ERROR_UNKNOWN_ACTION', array(
'#ACTION#' => $action)), self::ERROR_UNKNOWN_ACTION)));
220 $this->realActionName = $action;
221 $description = $listOfActions[$this->realActionName];
222 $this->
setAction($description[
'name'], $description);
231 $normalized = array();
232 foreach($listOfActions as
$action => $description)
245 return array_change_key_case($normalized, CASE_LOWER);
250 if(!is_array($description))
252 $description = array(
253 'method' => array(
'GET'),
254 'name' => $description,
255 'check_csrf_token' =>
false,
256 'redirect_on_auth' =>
true,
257 'close_session' =>
false,
260 if(empty($description[
'name']))
262 $description[
'name'] =
$action;
264 if(!isset($description[
'redirect_on_auth']))
266 $description[
'redirect_on_auth'] =
false;
268 if(!isset($description[
'close_session']))
270 $description[
'close_session'] =
false;
278 if($this->errorCollection->hasErrors())
280 $this->sendJsonErrorResponse();
286 if($description[
'redirect_on_auth'])
288 LocalRedirect(SITE_DIR .
'auth/?backurl=' . urlencode(
Application::getInstance()->getContext()->getRequest()->getRequestUri()));
297 if(($description[
'check_csrf_token'] ??
false) ===
true || ($this->request->isPost() && !isset($description[
'check_csrf_token'])))
300 if(!check_bitrix_sessid() && !check_bitrix_sessid(
'token_sid'))
306 if(!in_array($this->request->getRequestMethod(), $description[
'method']))
322 return $this->action;
330 return $this->actionDescription;
341 $this->actionDescription = $description;
377 if($description[
'close_session'] ===
true)
380 session_write_close();
382 $actionMethod =
'processAction' . $this->
getAction();
384 return $this->$actionMethod();
390 $this->errorCollection->add(array(
new Error($e->getMessage())));
391 $this->sendJsonErrorResponse();
420 foreach ($required as $item)
422 if(!isset($inputParams[$item]) || (!$inputParams[$item] && !(is_string($inputParams[$item]) && mb_strlen($inputParams[$item]))))
424 $this->errorCollection->add(array(
new Error(
Loc::getMessage(
'LISTS_CONTROLLER_ERROR_REQUIRED_PARAMETER', array(
'#PARAM#' => $item)), self::ERROR_REQUIRED_PARAMETER)));
435 foreach($required as $item)
437 $params[$item] = $this->request->getPost($item);
447 foreach($required as $item)
449 $params[$item] = $this->request->getQuery($item);
459 foreach($required as $item)
461 $params[$item] = $this->request->getFile($item);
474 return isset($_SERVER[
'HTTP_X_REQUESTED_WITH']) && $_SERVER[
'HTTP_X_REQUESTED_WITH'] ===
'XMLHttpRequest';
sendJsonCompletedResponse(array $response=array())
sendJsonSuccessResponse(array $response=array())
const STATUS_INVALID_SIGN
runProcessingIfUserNotAuthorized()
sendJsonInvalidSignResponse($message='')
const ERROR_REQUIRED_PARAMETER
processBeforeAction($actionName)
checkRequiredFilesParams(array $required)
setAction($action, array $description)
const ERROR_UNKNOWN_ACTION
runProcessingException(\Exception $e)
sendJsonResponse($response, $params=null)
sendJsonProcessingResponse(array $response=array())
normalizeActionDescription($action, $description)
checkRequiredPostParams(array $required)
checkRequiredGetParams(array $required)
runProcessingIfInvalidCsrfToken()
normalizeListOfAction(array $listOfActions)
checkRequiredInputParams(array $inputParams, array $required)
sendJsonAccessDeniedResponse($message='')
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)