diff --git a/api/index.php b/api/index.php
index 61ccf54..fc63aeb 100644
--- a/api/index.php
+++ b/api/index.php
@@ -80,6 +80,16 @@ use Bitrix\Main\Context,
Bitrix\Main\Loader,
Bitrix\Iblock;
+function checkRequestIsLocal()
+{
+ if(strpos($_SERVER['HTTP_X_FORWARDED_FOR'], SELF_IP) > -1)
+ {
+ return true;
+ }
+
+ return false;
+}
+
if($_SERVER['REMOTE_USER'] && strpos($_SERVER['REMOTE_USER'], "Bearer") > -1)
{
$token = str_replace("Bearer ", "", $_SERVER['REMOTE_USER']);
@@ -281,7 +291,7 @@ switch($PARAM_1)
"error" => "wrong_user_uri",
"message" => "Empty user URI",
]);
-
+
die();
}
break;
@@ -298,6 +308,9 @@ switch($PARAM_1)
if(CModule::IncludeModule('iblock'))
{
$filter = [ "ACTIVE" => "Y", "IBLOCK_ID" => 1 ];
+
+ if(!empty($REQ['PROGRAM'])) { $filter['PROPERTY_LEASING_PROGRAMS'] = $REQ['PROGRAM']; }
+
if(!empty($REQ['BRAND_ID'])) { $filter["PROPERTY_BRAND"] = $REQ['BRAND_ID']; }
if(!empty($REQ['MODEL_ID'])) { $filter["PROPERTY_MODEL"] = $REQ['MODEL_ID']; }
if(!empty($REQ['MODIFICATION'])) { $filter["PROPERTY_MODIFICATION"] = $REQ['MODIFICATION']; }
@@ -422,6 +435,7 @@ switch($PARAM_1)
sort($ENGINE_POWER);
sort($ENGINE_VOLUME);
+ sort($BODY);
print json_encode([
"bodies" => $BODY,
"gears" => $GEAR,
@@ -530,22 +544,22 @@ switch($PARAM_1)
$ipAddress = GeoIp\Manager::getRealIp();
$result = GeoIp\Manager::getDataResult($ipAddress, "ru");
- $REQ['FORM_FIELD_REGION'] = $result->getGeoData()->regionName.", ".$result->getGeoData()->cityName;
+ $_REQUEST['FORM_FIELD_REGION'] = $result->getGeoData()->regionName.", ".$result->getGeoData()->cityName;
$error = "";
$arr = Array();
$form_errors = Array();
$arParams['request'] = $_REQUEST;
$attach = false;
-
+
$form_code = trim($_REQUEST['form']);
-
+
$form = CForm::GetBySID($form_code);
$form = $form->Fetch();
-
+
$formQuestions = Array();
$formAnswers = Array();
-
+
$sort = "s_sort";
$order = "asc";
$filtered = false;
@@ -554,11 +568,11 @@ switch($PARAM_1)
{
$rsAnswers = CFormAnswer::GetList($arFormQuestion['ID'], $$sort, $$order, Array(), $$filtered);
$arAnswer = $rsAnswers->Fetch();
-
+
$arFormQuestion['ANSWER'] = $arAnswer;
$formQuestions[] = $arFormQuestion;
}
-
+
$c = 1;
foreach($formQuestions AS $fq)
{
@@ -576,7 +590,7 @@ switch($PARAM_1)
}
}
}
-
+
if($fq['ANSWER']['FIELD_TYPE'] == "file")
{
if(is_array($_FILES[$fq['SID']]))
@@ -608,12 +622,12 @@ switch($PARAM_1)
{
$formAnswers["form_".$fq['ANSWER']['FIELD_TYPE']."_".$fq['ANSWER']['ID']] = $_REQUEST[$fq['SID']];
}
-
+
$arr['q'][] = $fq;
-
+
$c++;
}
-
+
if(!empty($_SESSION[$_REQUEST['form']."_CAPTCHA"]))
{
if($_SESSION[$_REQUEST['form'].'_CAPTCHA'] != $_REQUEST[$_REQUEST['form'].'_CAPTCHA'])
@@ -621,21 +635,21 @@ switch($PARAM_1)
array_push($form_errors, $_REQUEST['form'].'_CAPTCHA');
}
}
-
+
$arr['FILES'] = $_FILES;
-
+
if(count($form_errors) == 0)
{
if($RESULT_ID = CFormResult::Add($form['ID'], $formAnswers))
{
$arr['status'] = "complete";
-
+
if($attach || array_key_exists("FORM_FILLING", $_REQUEST))
{
if($attach)
{
$arAnswer = CFormResult::GetDataByID($RESULT_ID, Array(), $arResult, $arAnswer2);
-
+
$fields = Array();
$attached_files = Array();
foreach($arAnswer AS $k => $v)
@@ -717,7 +731,7 @@ switch($PARAM_1)
}
$arr['request'] = $_REQUEST;
$arr['answers'] = $formAnswers;
-
+
print json_encode($arr);
die();
}
@@ -735,6 +749,234 @@ switch($PARAM_1)
}
break;
+ case "recovery":
+ {
+ switch($PARAM_3)
+ {
+ case "email":
+ {
+ if(checkRequestIsLocal())
+ {
+ $rs_user = \CUser::GetByLogin($REQ['email']);
+ $ar_user = $rs_user->Fetch();
+
+ if(is_array($ar_user))
+ {
+ \Bitrix\Main\Mail\Event::send([
+ "EVENT_NAME" => "USER_PASSWORD_RECOVERY_CODE",
+ "LID" => "s1",
+ "C_FIELDS" => Array(
+ "EMAIL" => $REQ['email'],
+ "CODE" => $REQ['code'],
+ )
+ ]);
+
+ print json_encode([
+ "status" => "success",
+ ]);
+ }
+ else
+ {
+ print json_encode([
+ "status" => "error",
+ "error" => "wrong_email",
+ "message" => "Wrong email",
+ ]);
+ }
+ }
+ }
+ break;
+
+ case "password":
+ {
+ if(checkRequestIsLocal())
+ {
+ $rs_user = \CUser::GetByLogin($REQ['email']);
+ $ar_user = $rs_user->Fetch();
+
+ if(is_array($ar_user))
+ {
+ $user = new \CUser;
+ $profile = [
+ "PASSWORD" => $REQ['password'],
+ "CONFIRM_PASSWORD" => $REQ['password'],
+ ];
+
+ $user->Update($ar_user['ID'], $profile);
+
+ if($user->LAST_ERROR)
+ {
+ print json_encode([
+ "status" => "error",
+ "error" => "wrong_payload",
+ "message" => $user->LAST_ERROR,
+ ]);
+ }
+ else
+ {
+ /*
+ \Bitrix\Main\Mail\Event::send([
+ "EVENT_NAME" => "USER_INFO",
+ "LID" => "s1",
+ "C_FIELDS" => Array(
+ "EMAIL" => $REQ['email'],
+ "ORG_NAME" => $ar_user['UF_ORG_TITLE'],
+ "LOGIN" => $REQ['email'],
+ "PASS" => $REQ['password'],
+ )
+ ]);
+ */
+
+ print json_encode([
+ "status" => "success",
+ ]);
+ }
+ }
+ else
+ {
+ print json_encode([
+ "status" => "error",
+ "error" => "wrong_email",
+ "message" => "Wrong email",
+ ]);
+ }
+ }
+ }
+ break;
+ }
+ }
+ break;
+
+ case "change":
+ {
+ switch($PARAM_3)
+ {
+ case "password":
+ {
+ if(checkRequestIsLocal())
+ {
+ $user = new \CUser;
+ $login_result = $user->Login($REQ['email'], $REQ['password'], "N");
+
+ if($login_result == 1)
+ {
+ $existed_user_res = \CUser::GetByLogin($REQ['email']);
+ $existed_user = $existed_user_res->Fetch();
+
+ if(is_array($existed_user))
+ {
+ $profile = [
+ "PASSWORD" => $REQ['new_password'],
+ "CONFIRM_PASSWORD" => $REQ['new_password_repeat'],
+ ];
+
+ $user->Update($existed_user['ID'], $profile);
+
+ if($user->LAST_ERROR)
+ {
+ print json_encode([
+ "status" => "error",
+ "error" => "wrong_payload",
+ "message" => $user->LAST_ERROR,
+ ]);
+ }
+ else
+ {
+ print json_encode([
+ "status" => "success",
+ ]);
+ }
+ }
+ else
+ {
+ print json_encode([
+ "status" => "error",
+ "error" => "unknow_user",
+ "message" => "Unknown user",
+ ]);
+ }
+ }
+ else
+ {
+ print json_encode([
+ "status" => "error",
+ "error" => "wrong_email",
+ "message" => "Wrong email",
+ ]);
+ }
+ }
+ }
+ break;
+
+ case "phone":
+ {
+ if(checkRequestIsLocal())
+ {
+ $token = str_replace("Bearer ", "", $_SERVER['REMOTE_USER']);
+ $auth = (array) \Bitrix\Main\Web\JWT::decode($token, $secret, ["HS256"]);
+
+ $user = new \CUser;
+
+ $existed_user_res = \CUser::GetByLogin($REQ['email']);
+ $existed_user = $existed_user_res->Fetch();
+
+ if(is_array($existed_user))
+ {
+ if($existed_user['XML_ID'] == $auth['acc_number'])
+ {
+ $existed_phone_users_res = \CUser::GetList(["ID" => "ASC"], false, [ "UF_PHONE_NUMBER" => $REQ['phone'] ], []);
+ while($existed_phone_user = $existed_phone_users_res->Fetch())
+ {
+ $user->Update($existed_user['ID'], [
+ "UF_PHONE_NUMBER" => "",
+ ]);
+ }
+
+ $profile = [
+ "UF_PHONE_NUMBER" => $REQ['phone'],
+ ];
+
+ $user->Update($existed_user['ID'], $profile);
+
+ if($user->LAST_ERROR)
+ {
+ print json_encode([
+ "status" => "error",
+ "error" => "wrong_payload",
+ "message" => $user->LAST_ERROR,
+ ]);
+ }
+ else
+ {
+ print json_encode([
+ "status" => "success",
+ ]);
+ }
+ }
+ else
+ {
+ print json_encode([
+ "status" => "error",
+ "error" => "wrong_company",
+ "message" => "Wrong company",
+ ]);
+ }
+ }
+ else
+ {
+ print json_encode([
+ "status" => "error",
+ "error" => "wrong_email",
+ "message" => "Wrong email",
+ ]);
+ }
+ }
+ }
+ break;
+ }
+ }
+ break;
+
case "auth":
{
switch($PARAM_3)
@@ -749,14 +991,12 @@ switch($PARAM_1)
$rs_user = \CUser::GetByLogin($REQ['email']);
$ar_user = $rs_user->Fetch();
- //print_r($ar_user);
-
$user_data = [
"email" => $ar_user['LOGIN'],
"name" => $ar_user['NAME'],
"secondname" => $ar_user['SECOND_NAME'],
"lastname" => $ar_user['LAST_NAME'],
- "phone" => $ar_user['UF_PHONE'],
+ "phone" => $ar_user['UF_PHONE_NUMBER'],
"phone_verified" => $ar_user['UF_PHONE_VERIFIED'],
];
@@ -782,64 +1022,11 @@ switch($PARAM_1)
"message" => "Wrong username or password",
]);
}
-
- print $arAuthResult;
}
break;
case "phone":
{
- /*
- $oUserTypeEntity = new CUserTypeEntity();
- //$oUserTypeEntity->Delete(12);
-
- $aUserFields = array(
- 'ENTITY_ID' => 'USER',
- 'FIELD_NAME' => 'UF_PHONE_NUMBER',
- 'USER_TYPE_ID' => 'string',
- 'XML_ID' => 'XML_USER_PHONE_NUMBER',
- 'SORT' => 500,
- 'MULTIPLE' => 'N',
- 'MANDATORY' => 'N',
- 'SHOW_FILTER' => 'N',
- 'SHOW_IN_LIST' => '',
- 'EDIT_IN_LIST' => '',
- 'IS_SEARCHABLE' => 'N',
- 'SETTINGS' => array(
- 'DEFAULT_VALUE' => '',
- 'SIZE' => '20',
- 'ROWS' => '1',
- 'MIN_LENGTH' => '0',
- 'MAX_LENGTH' => '0',
- 'REGEXP' => '',
- ),
- 'EDIT_FORM_LABEL' => array(
- 'ru' => 'Номер телефона',
- 'en' => 'Phone number',
- ),
- 'LIST_COLUMN_LABEL' => array(
- 'ru' => 'Номер телефона',
- 'en' => 'Phone number',
- ),
- 'LIST_FILTER_LABEL' => array(
- 'ru' => 'Номер телефона',
- 'en' => 'Phone number',
- ),
- 'ERROR_MESSAGE' => array(
- 'ru' => 'Ошибка при заполнении пользовательского свойства',
- 'en' => 'An error in completing the user field',
- ),
- 'HELP_MESSAGE' => array(
- 'ru' => '',
- 'en' => '',
- ),
- );
-
- $iUserFieldId = $oUserTypeEntity->Add( $aUserFields ); // int
- print $iUserFieldId;
- die();
- */
-
if(!empty($REQ['phone']))
{
$user = new \CUser;
@@ -850,13 +1037,12 @@ switch($PARAM_1)
while($arUser = $rsUsers->Fetch())
{
array_push($numbers, $arUser);
- //echo $arUser['ID'].' '.$arUser['LOGIN']."\n";
}
if(count($numbers) > 0)
{
$ar_user = $numbers[count( $numbers ) - 1];
-
+
print json_encode([
"status" => "success",
"acc_number" => $ar_user['XML_ID'],
@@ -935,117 +1121,34 @@ switch($PARAM_1)
}
break;
- case "contracts":
+ case "materials":
{
- if($auth['acc_number'])
+ if(CModule::IncludeModule('iblock'))
{
- $token = \Bitrix\Main\Web\JWT::encode(["acc_number" => $auth['acc_number']], $secret_crm, 'HS256', null, null);
- $parameters = ["acc_number" => $auth['acc_number']];
+ $sort = ["ACTIVE_FROM" => "DESC", "SORT" => "DESC"];
+ $filter = ["ACTIVE" => "Y", "IBLOCK_ID" => 21];
+ $options = [];
- $url = API_HOST."/lk/Account/GetContracts/?".http_build_query($parameters);
-
- $c = curl_init();
- curl_setopt($c, CURLOPT_URL, $url);
- curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 30);
- curl_setopt($c, CURLOPT_TIMEOUT, 30);
- curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($c, CURLOPT_POST, 0);
- curl_setopt($c, CURLOPT_HTTPHEADER, [
- "Content-Type: application/json",
- "Authorization: Bearer ".$token."",
- ]);
-
- $response = curl_exec($c);
- curl_close($c);
-
- print json_encode([
- "status" => "success",
- "contracts" => $response,
- ]);
- }
- else
- { header('HTTP/1.0 401 Unauthorized'); print json_encode(["status" => "error", "error" => "unauthorized", "message" => "Unauthorized"]); }
- die();
- }
- break;
-
- case "calendar":
- {
- if($auth['acc_number'])
- {
- $token = \Bitrix\Main\Web\JWT::encode(["acc_number" => $auth['acc_number']], $secret, 'HS256', null, null);
- $parameters = ["acc_number" => $auth['acc_number']];
-
- $url = API_HOST."/lk/Account/GetPaymentCalendar/?".http_build_query($parameters);
-
- $c = curl_init();
- curl_setopt($c, CURLOPT_URL, $url);
- curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 30);
- curl_setopt($c, CURLOPT_TIMEOUT, 30);
- curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($c, CURLOPT_POST, 0);
- curl_setopt($c, CURLOPT_HTTPHEADER, [
- "Content-Type: application/json",
- "Authorization: Bearer ".$token."",
- ]);
-
- $response = curl_exec($c);
- curl_close($c);
-
- print json_encode([
- "status" => "success",
- "contracts" => $response,
- ]);
- }
- else
- { header('HTTP/1.0 401 Unauthorized'); print json_encode(["status" => "error", "error" => "unauthorized", "message" => "Unauthorized"]); }
- die();
- }
- break;
-
- case "contract":
- {
- switch($PARAM_4)
- {
- case "osago":
+ $materials = [];
+ $materials_res = CIBlockElement::GetList($sort, $filter, false, $options);
+ while ($materials_ob_element = $materials_res->GetNextElement())
{
- if($auth['acc_number'])
- {
- $token = \Bitrix\Main\Web\JWT::encode(["acc_number" => $auth['acc_number']], $secret, 'HS256', null, null);
- $parameters = ["acc_number" => $auth['acc_number']];
+ $materials_ar_res = $materials_ob_element->GetFields();
+ $materials_ar_res['PROPERTIES'] = $materials_ob_element->GetProperties();
- $url = API_HOST."/lk/Account/GetPaymentCalendar/?".http_build_query($parameters);
+ $f = CFile::GetByID($materials_ar_res['PROPERTIES']['FILE']['VALUE']);
- $c = curl_init();
- curl_setopt($c, CURLOPT_URL, $url);
- curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 30);
- curl_setopt($c, CURLOPT_TIMEOUT, 30);
- curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($c, CURLOPT_POST, 0);
- curl_setopt($c, CURLOPT_HTTPHEADER, [
- "Content-Type: application/json",
- "Authorization: Bearer ".$token."",
- ]);
-
- $response = curl_exec($c);
- curl_close($c);
-
- print json_encode([
- "status" => "success",
- "contracts" => $response,
- ]);
- }
- else
- { header('HTTP/1.0 401 Unauthorized'); print json_encode(["status" => "error", "error" => "unauthorized", "message" => "Unauthorized"]); }
- die();
+ $materials[] = [
+ "name" => $materials_ar_res['NAME'],
+ "description" => $materials_ar_res['PREVIEW_TEXT'],
+ "filename" => $f->Fetch()['ORIGINAL_NAME'],
+ "url" => CFile::GetPath($materials_ar_res['PROPERTIES']['FILE']['VALUE']),
+ ];
}
- break;
+
+ print json_encode([
+ "materials" => $materials,
+ ]);
}
}
break;
@@ -1073,6 +1176,7 @@ switch($PARAM_1)
"lease_period" => $REQ['lease_period'],
"redemption_payment" => $REQ['redemption_payment'],
]);
+
$c = curl_init();
curl_setopt($c, CURLOPT_URL, API_HOST."/calculator/");
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 30);
diff --git a/catalog/index.php b/catalog/index.php
index a8cf17b..f327968 100644
--- a/catalog/index.php
+++ b/catalog/index.php
@@ -19,6 +19,9 @@ $APPLICATION->SetTitle("Каталог");
"ENGINE_POWER_TO" => $_REQUEST['ENGINE_POWER_TO'],
"ENGINE_VOLUME_FROM" => $_REQUEST['ENGINE_VOLUME_FROM'],
"ENGINE_VOLUME_TO" => $_REQUEST['ENGINE_VOLUME_TO'],
+ "SORT" => $_REQUEST['SORT'],
+ "PATH" => "/catalog/",
+ "PROGRAM" => null,
)
);
?>
diff --git a/index.php b/index.php
index 455e1d3..447f6c6 100644
--- a/index.php
+++ b/index.php
@@ -10,13 +10,16 @@ $APPLICATION->SetTitle("Эволюция автолизинга. Лизинг а