account update API release
This commit is contained in:
parent
1ed8b34b1d
commit
76bcef4144
814
api/index.php
814
api/index.php
@ -82,6 +82,11 @@ use Bitrix\Main\Context,
|
||||
|
||||
function checkRequestIsLocal()
|
||||
{
|
||||
if(!MODE_PRODUCTION)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if(strpos($_SERVER['HTTP_X_FORWARDED_FOR'], SELF_IP) > -1)
|
||||
{
|
||||
return true;
|
||||
@ -114,6 +119,102 @@ function checkRecaptchaRequest($token, $ipAddress)
|
||||
return $response_decoded['success'];
|
||||
}
|
||||
|
||||
function getCompaniesForUser($user_id)
|
||||
{
|
||||
if(CModule::IncludeModule('iblock'))
|
||||
{
|
||||
$existed_client_as_user_res = CIBlockElement::GetList([ 'id' => 'desc' ], [ 'IBLOCK_ID' => IBLOCK_ID_CLIENTS, 'PROPERTY_USERS' => $user_id ], false, []);
|
||||
|
||||
$companies = [];
|
||||
|
||||
while ($existed_client_as_user_element = $existed_client_as_user_res->GetNextElement())
|
||||
{
|
||||
$existed_client_as_user_record = $existed_client_as_user_element->GetFields();
|
||||
$existed_client_as_user_record['PROPERTIES'] = $existed_client_as_user_element->GetProperties();
|
||||
|
||||
$company = [
|
||||
"acc_number" => $existed_client_as_user_record['CODE'],
|
||||
"title" => $existed_client_as_user_record['PROPERTIES']['COMPANY']['~VALUE'],
|
||||
"inn" => $existed_client_as_user_record['PROPERTIES']['INN']['~VALUE'],
|
||||
"kpp" => $existed_client_as_user_record['PROPERTIES']['KPP']['~VALUE'],
|
||||
"ogrn" => $existed_client_as_user_record['PROPERTIES']['OGRN']['~VALUE'],
|
||||
"is_admin" => false,
|
||||
];
|
||||
|
||||
foreach($existed_client_as_user_record['PROPERTIES']['ADMINS']['VALUE'] AS $k => $v)
|
||||
{
|
||||
if($v == $user_id)
|
||||
{
|
||||
$company['is_admin'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
array_push($companies, $company);
|
||||
}
|
||||
|
||||
return $companies;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
function getUsersForCompany($code)
|
||||
{
|
||||
if(CModule::IncludeModule('iblock'))
|
||||
{
|
||||
$company_res = CIBlockElement::GetList([ 'id' => 'desc' ], [ 'IBLOCK_ID' => IBLOCK_ID_CLIENTS, 'CODE' => $code ], false, []);
|
||||
|
||||
$users = [];
|
||||
|
||||
while ($company_element = $company_res->GetNextElement())
|
||||
{
|
||||
$company_record = $company_element->GetFields();
|
||||
$company_record['PROPERTIES'] = $company_element->GetProperties();
|
||||
$user = [];
|
||||
|
||||
//print_r($company_record);
|
||||
//die();
|
||||
|
||||
foreach($company_record['PROPERTIES']['USERS']['VALUE'] AS $user_id)
|
||||
{
|
||||
$user_res = \CUser::GetList(["ID" => "ASC"], false, [ "ID" => $user_id ], []);
|
||||
while($user_element = $user_res->Fetch())
|
||||
{
|
||||
$companies = getCompaniesForUser($user_element['ID']);
|
||||
$user = [
|
||||
"email" => $user_element['LOGIN'],
|
||||
"name" => $user_element['LAST_NAME'],
|
||||
"last" => $user_element['LAST_LOGIN'],
|
||||
"companies" => $companies,
|
||||
"is_admin" => in_array($user_element['ID'], $company_record['PROPERTIES']['ADMINS']['VALUE']),
|
||||
];
|
||||
///print_r($user_element);
|
||||
//$rs_user = \CUser::GetByLogin($user_element['LOGIN']);
|
||||
//$ar_user = $rs_user->Fetch();
|
||||
|
||||
//array_push($existed_accounts, $existed_user['XML_ID']);
|
||||
|
||||
/*
|
||||
foreach($company_record['PROPERTIES']['ADMINS']['VALUE'] AS $k => $v)
|
||||
{
|
||||
if($v == $user_id)
|
||||
{
|
||||
$company['is_admin'] = true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
array_push($users, $user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
if($_SERVER['REMOTE_USER'] && strpos($_SERVER['REMOTE_USER'], "Bearer") > -1)
|
||||
{
|
||||
$token = str_replace("Bearer ", "", $_SERVER['REMOTE_USER']);
|
||||
@ -240,6 +341,55 @@ switch($PARAM_1)
|
||||
)
|
||||
]);
|
||||
|
||||
$user_properties = [
|
||||
'COMPANY' => $REQ['org_title'],
|
||||
'INN' => (string)$REQ['inn'],
|
||||
'KPP' => (string)$REQ['kpp'],
|
||||
'OGRN' => (string)$REQ['ogrn'],
|
||||
'ADMINS' => [ $ID ],
|
||||
'USERS' => [ $ID ],
|
||||
];
|
||||
|
||||
$ar_new_client = [
|
||||
'IBLOCK_ID' => IBLOCK_ID_CLIENTS,
|
||||
'NAME' => $REQ['org_title'],
|
||||
'CODE' => $REQ['crm_id'],
|
||||
'PROPERTY_VALUES' => $user_properties,
|
||||
'ACTIVE' => 'Y', // активен
|
||||
];
|
||||
|
||||
$new_client = new CIBlockElement;
|
||||
if($new_client_id = $new_client->Add($ar_new_client))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
$existed_client_res = CIBlockElement::GetList([ 'id' => 'desc' ], [ 'IBLOCK_ID' => IBLOCK_ID_CLIENTS, 'CODE' => $REQ['crm_id'] ], false, []);
|
||||
while ($existed_client_element = $existed_client_res->GetNextElement())
|
||||
{
|
||||
$existed_client_record = $existed_client_element->GetFields();
|
||||
$existed_client_record['PROPERTIES'] = $existed_client_element->GetProperties();
|
||||
|
||||
$admins = $existed_client_record['PROPERTIES']['ADMINS']['VALUE'];
|
||||
$users = $existed_client_record['PROPERTIES']['USERS']['VALUE'];
|
||||
|
||||
array_push($admins, $ID);
|
||||
array_push($users, $ID);
|
||||
|
||||
$admins = array_unique($admins);
|
||||
$users = array_unique($users);
|
||||
|
||||
$updated_fields = [
|
||||
'PROPERTY_VALUES' => [
|
||||
'ADMINS' => $admins,
|
||||
'USERS' => $users,
|
||||
]
|
||||
];
|
||||
|
||||
CIBlockElement::SetPropertyValuesEx($existed_client_record['ID'], IBLOCK_ID_CLIENTS, [ 'ADMINS' => $admins, 'USERS' => $users, ]);
|
||||
}
|
||||
}
|
||||
|
||||
print json_encode([
|
||||
"status" => "success"
|
||||
]);
|
||||
@ -332,6 +482,110 @@ switch($PARAM_1)
|
||||
}
|
||||
break;
|
||||
|
||||
case "check":
|
||||
{
|
||||
if(CModule::IncludeModule('iblock'))
|
||||
{
|
||||
if(checkRequestIsLocal())
|
||||
{
|
||||
try
|
||||
{
|
||||
$user_registered = false;
|
||||
$ar_user;
|
||||
|
||||
$existed_accounts = [];
|
||||
$auth = (array) \Bitrix\Main\Web\JWT::decode($REQ['token'], $secret_crm, ["HS256"]);
|
||||
|
||||
$default_admin_id;
|
||||
|
||||
$existed_client_as_admin_res = CIBlockElement::GetList([ 'ID' => 'ASC' ], [ 'IBLOCK_ID' => IBLOCK_ID_CLIENTS, 'CODE' => $auth['acc_number'] ], false, []);
|
||||
while ($existed_client_as_admin_element = $existed_client_as_admin_res->GetNextElement())
|
||||
{
|
||||
$existed_client_as_admin_record = $existed_client_as_admin_element->GetFields();
|
||||
$existed_client_as_admin_record['PROPERTIES'] = $existed_client_as_admin_element->GetProperties();
|
||||
$default_admin_id = $existed_client_as_admin_record['PROPERTIES']['ADMINS']['VALUE'][0];
|
||||
$user_registered = true;
|
||||
}
|
||||
|
||||
$existed_users_res = \CUser::GetList(["ID" => "ASC"], false, [ "ID" => $default_admin_id ], []);
|
||||
while($existed_user = $existed_users_res->Fetch())
|
||||
{
|
||||
$rs_user = \CUser::GetByLogin($existed_user['LOGIN']);
|
||||
$ar_user = $rs_user->Fetch();
|
||||
|
||||
array_push($existed_accounts, $existed_user['XML_ID']);
|
||||
}
|
||||
|
||||
if(isset($REQ['filter']))
|
||||
{
|
||||
if(!in_array($auth['acc_number'], $existed_accounts))
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "access_denied",
|
||||
]);
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
if($user_registered)
|
||||
{
|
||||
$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_NUMBER'],
|
||||
"phone_verified" => $ar_user['UF_PHONE_VERIFIED'],
|
||||
];
|
||||
|
||||
$companies = getCompaniesForUser($ar_user['ID']);
|
||||
$company_data = [
|
||||
"inn" => $companies[0]['inn'],
|
||||
"kpp" => $companies[0]['kpp'],
|
||||
"ogrn" => $companies[0]['ogrn'],
|
||||
"title" => $companies[0]['title'],
|
||||
];
|
||||
|
||||
print json_encode([
|
||||
"status" => "success",
|
||||
"user" => $user_data,
|
||||
"company" => $company_data,
|
||||
"companies" => $companies,
|
||||
"token" => \Bitrix\Main\Web\JWT::encode([ "acc_number" => $auth['acc_number'], "is_admin" => $companies[0]['is_admin'], "login" => $ar_user['LOGIN'], "companies" => $companies ], $secret, 'HS256', null, null),
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "unknown account",
|
||||
]);
|
||||
}
|
||||
die();
|
||||
}
|
||||
catch(\Exception $e)
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_jwt",
|
||||
"message" => $e->getMessage(),
|
||||
]);
|
||||
die();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_source",
|
||||
"error" => "Wrong source",
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
print json_encode([
|
||||
@ -347,6 +601,272 @@ switch($PARAM_1)
|
||||
}
|
||||
break;
|
||||
|
||||
case "admin":
|
||||
{
|
||||
switch($PARAM_2)
|
||||
{
|
||||
case "users":
|
||||
{
|
||||
if(CModule::IncludeModule('iblock'))
|
||||
{
|
||||
if(checkRequestIsLocal())
|
||||
{
|
||||
try
|
||||
{
|
||||
$user_registered = false;
|
||||
$ar_user;
|
||||
|
||||
$existed_accounts = [];
|
||||
$auth = (array) \Bitrix\Main\Web\JWT::decode($REQ['token'], $secret_crm, ["HS256"]);
|
||||
|
||||
$users = getUsersForCompany($auth['acc_number']);
|
||||
print json_encode([
|
||||
"status" => "success",
|
||||
"users" => $users,
|
||||
]);
|
||||
}
|
||||
catch(\Exception $e)
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_jwt",
|
||||
"message" => $e->getMessage(),
|
||||
]);
|
||||
die();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_source",
|
||||
"error" => "Wrong source",
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "invite":
|
||||
{
|
||||
if(CModule::IncludeModule('iblock'))
|
||||
{
|
||||
if(checkRequestIsLocal())
|
||||
{
|
||||
try
|
||||
{
|
||||
$auth = (array) \Bitrix\Main\Web\JWT::decode($REQ['token'], $secret_crm, ["HS256"]);
|
||||
|
||||
$rs_user = \CUser::GetByLogin($auth['email']);
|
||||
$ar_user = $rs_user->Fetch();
|
||||
|
||||
$existed_user = false;
|
||||
$user_id_to_add = null;
|
||||
|
||||
if(is_array($ar_user))
|
||||
{
|
||||
//existed user
|
||||
$existed_user = true;
|
||||
$user_id_to_add = intval($ar_user['ID']);
|
||||
|
||||
$user = new CUser;
|
||||
$user->Update($user_id_to_add, [ "BLOCKED" => "N" ]);
|
||||
}
|
||||
else
|
||||
{
|
||||
//new user
|
||||
$password = randString(8);
|
||||
|
||||
$user = new \CUser;
|
||||
$profile = [
|
||||
"LOGIN" => $auth['email'],
|
||||
"LAST_NAME" => $auth['name'],
|
||||
"PASSWORD" => $password,
|
||||
"CONFIRM_PASSWORD" => $password,
|
||||
"EMAIL" => $auth['email'],
|
||||
];
|
||||
|
||||
$ID = $user->Add($profile);
|
||||
if (intval($ID) > 0)
|
||||
{
|
||||
$user_id_to_add = intval($ID);
|
||||
}
|
||||
}
|
||||
|
||||
//add user to company (companies)
|
||||
$companies_list_message = "Список компаний к которым Вам предоставлен доступ:<br><br>\n\n";
|
||||
foreach($auth['companies'] AS $company_acc_number)
|
||||
{
|
||||
$existed_client_res = CIBlockElement::GetList([ 'id' => 'desc' ], [ 'IBLOCK_ID' => IBLOCK_ID_CLIENTS, 'CODE' => $company_acc_number ], false, []);
|
||||
|
||||
while ($existed_client_element = $existed_client_res->GetNextElement())
|
||||
{
|
||||
$existed_client_record = $existed_client_element->GetFields();
|
||||
$existed_client_record['PROPERTIES'] = $existed_client_element->GetProperties();
|
||||
|
||||
$companies_list_message .= $existed_client_record['NAME'].", ИНН: ".$existed_client_record['PROPERTIES']['INN']['VALUE']."<br>\n";
|
||||
|
||||
$users = $existed_client_record['PROPERTIES']['USERS']['VALUE'];
|
||||
array_push($users, $user_id_to_add);
|
||||
|
||||
$users = array_unique($users);
|
||||
|
||||
CIBlockElement::SetPropertyValuesEx($existed_client_record['ID'], IBLOCK_ID_CLIENTS, [ 'USERS' => $users, ]);
|
||||
}
|
||||
}
|
||||
|
||||
if($existed_user)
|
||||
{
|
||||
\Bitrix\Main\Mail\Event::send([
|
||||
"EVENT_NAME" => "CLIENT_USER_INVITE",
|
||||
"LID" => "s1",
|
||||
"C_FIELDS" => Array(
|
||||
"EMAIL" => $auth['email'],
|
||||
"COMPANIES" => $companies_list_message,
|
||||
)
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
\Bitrix\Main\Mail\Event::send([
|
||||
"EVENT_NAME" => "CLIENT_NEW_USER_INVITE",
|
||||
"LID" => "s1",
|
||||
"C_FIELDS" => Array(
|
||||
"EMAIL" => $auth['email'],
|
||||
"PASSWORD" => $password,
|
||||
"COMPANIES" => $companies_list_message,
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
print json_encode([
|
||||
"status" => "success",
|
||||
]);
|
||||
}
|
||||
catch(\Exception $e)
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_jwt",
|
||||
"message" => $e->getMessage(),
|
||||
]);
|
||||
die();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_source",
|
||||
"error" => "Wrong source",
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "remove":
|
||||
{
|
||||
if(CModule::IncludeModule('iblock'))
|
||||
{
|
||||
if(checkRequestIsLocal())
|
||||
{
|
||||
try
|
||||
{
|
||||
$auth = (array) \Bitrix\Main\Web\JWT::decode($REQ['token'], $secret_crm, ["HS256"]);
|
||||
|
||||
$existed_users = [];
|
||||
$removed_users = [];
|
||||
|
||||
foreach($auth['emails'] AS $email)
|
||||
{
|
||||
$rs_user = \CUser::GetByLogin($email);
|
||||
$ar_user = $rs_user->Fetch();
|
||||
|
||||
$existed_users[$ar_user['ID']] = $email;
|
||||
}
|
||||
|
||||
$existed_client_res = CIBlockElement::GetList([ 'id' => 'desc' ], [ 'IBLOCK_ID' => IBLOCK_ID_CLIENTS, 'CODE' => $auth['acc_number'] ], false, []);
|
||||
|
||||
$users = [];
|
||||
while ($existed_client_element = $existed_client_res->GetNextElement())
|
||||
{
|
||||
$existed_client_record = $existed_client_element->GetFields();
|
||||
$existed_client_record['PROPERTIES'] = $existed_client_element->GetProperties();
|
||||
|
||||
$company_users = $existed_client_record['PROPERTIES']['USERS']['VALUE'];
|
||||
|
||||
$company_new_users = [];
|
||||
foreach($company_users AS $company_user_id)
|
||||
{
|
||||
if(!isset($existed_users[$company_user_id]))
|
||||
{
|
||||
array_push($company_new_users, $company_user_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
array_push($removed_users, $company_user_id);
|
||||
}
|
||||
}
|
||||
|
||||
$company_new_users = array_unique($company_new_users);
|
||||
|
||||
CIBlockElement::SetPropertyValuesEx($existed_client_record['ID'], IBLOCK_ID_CLIENTS, [ 'USERS' => $company_new_users, ]);
|
||||
}
|
||||
|
||||
foreach($removed_users AS $removed_user_id)
|
||||
{
|
||||
$user_companies = getCompaniesForUser($removed_user_id);
|
||||
|
||||
if(count($user_companies) === 0)
|
||||
{
|
||||
$user = new CUser;
|
||||
$user->Update($removed_user_id, [ "BLOCKED" => "Y" ]);
|
||||
}
|
||||
}
|
||||
|
||||
print json_encode([
|
||||
"status" => "success",
|
||||
]);
|
||||
|
||||
die();
|
||||
}
|
||||
catch(\Exception $e)
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_jwt",
|
||||
"message" => $e->getMessage(),
|
||||
]);
|
||||
die();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_source",
|
||||
"error" => "Wrong source",
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_admin_uri",
|
||||
"message" => "Empty admin URI",
|
||||
]);
|
||||
|
||||
die();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
case "catalog":
|
||||
{
|
||||
switch($PARAM_2)
|
||||
@ -355,7 +875,7 @@ switch($PARAM_1)
|
||||
{
|
||||
if(CModule::IncludeModule('iblock'))
|
||||
{
|
||||
$filter = [ "ACTIVE" => "Y", "IBLOCK_ID" => 1 ];
|
||||
$filter = [ "ACTIVE" => "Y", ];
|
||||
|
||||
if(!empty($REQ['PROGRAM'])) { $filter['PROPERTY_LEASING_PROGRAMS'] = $REQ['PROGRAM']; }
|
||||
|
||||
@ -373,10 +893,33 @@ switch($PARAM_1)
|
||||
$filter['><PROPERTY_ENGINE_VOLUME'] = [ !empty($REQ['ENGINE_VOLUME_FROM']) ? $REQ['ENGINE_VOLUME_FROM'] : 0, !empty($REQ['ENGINE_VOLUME_TO']) ? $REQ['ENGINE_VOLUME_TO'] : 10000 ];
|
||||
}
|
||||
|
||||
$total = CIBlockElement::GetList([ "SORT" => "ASC", "NAME" => "ASC" ], $filter, [], []);
|
||||
$total = CIBlockElement::GetList([ "SORT" => "ASC", "NAME" => "ASC" ], array_merge([ "IBLOCK_ID" => 1 ], $filter), [], []);
|
||||
|
||||
$gear = [];
|
||||
$drive = [];
|
||||
$body = [];
|
||||
$fuel = [];
|
||||
|
||||
$iterator = CIBlockElement::GetPropertyValues( 1, $filter, true, [ 'ID' => [ 7, 8, 9, 12 ] ] );
|
||||
while ($row = $iterator->Fetch())
|
||||
{
|
||||
//print_r($row);
|
||||
array_push($gear, $row[7]);
|
||||
array_push($drive, $row[8]);
|
||||
array_push($body, $row[9]);
|
||||
array_push($fuel, $row[12]);
|
||||
}
|
||||
$gear = array_unique($gear);
|
||||
$drive = array_unique($drive);
|
||||
$body = array_unique($body);
|
||||
$fuel = array_unique($fuel);
|
||||
|
||||
print json_encode([
|
||||
"total" => $total,
|
||||
"gear" => $gear,
|
||||
"drive" => $drive,
|
||||
"body" => $body,
|
||||
"fuel" => $fuel,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@ -872,6 +1415,14 @@ switch($PARAM_1)
|
||||
]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_source",
|
||||
"message" => "Wrong source",
|
||||
]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@ -929,6 +1480,14 @@ switch($PARAM_1)
|
||||
]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_source",
|
||||
"message" => "Wrong source",
|
||||
]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -993,6 +1552,14 @@ switch($PARAM_1)
|
||||
]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_source",
|
||||
"message" => "Wrong source",
|
||||
]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1059,6 +1626,14 @@ switch($PARAM_1)
|
||||
]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_source",
|
||||
"message" => "Wrong source",
|
||||
]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1088,18 +1663,20 @@ switch($PARAM_1)
|
||||
"phone_verified" => $ar_user['UF_PHONE_VERIFIED'],
|
||||
];
|
||||
|
||||
$companies = getCompaniesForUser($ar_user['ID']);
|
||||
$company_data = [
|
||||
"inn" => $ar_user['UF_INN'],
|
||||
"kpp" => $ar_user['UF_KPP'],
|
||||
"ogrn" => $ar_user['UF_OGRN'],
|
||||
"title" => $ar_user['UF_ORG_TITLE'],
|
||||
"inn" => $companies[0]['inn'],
|
||||
"kpp" => $companies[0]['kpp'],
|
||||
"ogrn" => $companies[0]['ogrn'],
|
||||
"title" => $companies[0]['title'],
|
||||
];
|
||||
|
||||
print json_encode([
|
||||
"status" => "success",
|
||||
"user" => $user_data,
|
||||
"company" => $company_data,
|
||||
"token" => \Bitrix\Main\Web\JWT::encode(["acc_number" => $ar_user['XML_ID']], $secret, 'HS256', null, null),
|
||||
"companies" => $companies,
|
||||
"token" => \Bitrix\Main\Web\JWT::encode([ "acc_number" => $companies[0]['acc_number'], "is_admin" => $companies[0]['is_admin'], "login" => $ar_user['LOGIN'], "companies" => $companies ], $secret, 'HS256', null, null),
|
||||
]);
|
||||
}
|
||||
else
|
||||
@ -1117,43 +1694,58 @@ switch($PARAM_1)
|
||||
{
|
||||
if(!empty($REQ['phone']))
|
||||
{
|
||||
$user = new \CUser;
|
||||
$filter = ["UF_PHONE_NUMBER" => $REQ['phone']];
|
||||
|
||||
$numbers = [];
|
||||
$rsUsers = CUser::GetList(["ID" => "ASC"], false, $filter, array("SELECT"=>array("UF_*")));
|
||||
while($arUser = $rsUsers->Fetch())
|
||||
if(checkRequestIsLocal())
|
||||
{
|
||||
array_push($numbers, $arUser);
|
||||
}
|
||||
$user = new \CUser;
|
||||
$filter = ["UF_PHONE_NUMBER" => $REQ['phone']];
|
||||
|
||||
if(count($numbers) > 0)
|
||||
{
|
||||
$ar_user = $numbers[count( $numbers ) - 1];
|
||||
$numbers = [];
|
||||
$rsUsers = CUser::GetList(["ID" => "ASC"], false, $filter, array("SELECT"=>array("UF_*")));
|
||||
while($arUser = $rsUsers->Fetch())
|
||||
{
|
||||
array_push($numbers, $arUser);
|
||||
}
|
||||
|
||||
print json_encode([
|
||||
"status" => "success",
|
||||
"acc_number" => $ar_user['XML_ID'],
|
||||
"user" => [
|
||||
"email" => $ar_user['LOGIN'],
|
||||
"name" => $ar_user['NAME'],
|
||||
"secondname" => $ar_user['SECOND_NAME'],
|
||||
"lastname" => $ar_user['LAST_NAME'],
|
||||
"phone_number" => $ar_user['UF_PHONE_NUMBER'],
|
||||
"phone_verified" => $ar_user['UF_PHONE_VERIFIED'],
|
||||
],
|
||||
"company" => [
|
||||
"inn" => $ar_user['UF_INN'],
|
||||
"kpp" => $ar_user['UF_KPP'],
|
||||
"ogrn" => $ar_user['UF_OGRN'],
|
||||
"title" => $ar_user['UF_ORG_TITLE'],
|
||||
],
|
||||
]);
|
||||
if(count($numbers) > 0)
|
||||
{
|
||||
$ar_user = $numbers[count( $numbers ) - 1];
|
||||
$companies = getCompaniesForUser($ar_user['ID']);
|
||||
|
||||
print json_encode([
|
||||
"status" => "success",
|
||||
"acc_number" => $ar_user['XML_ID'],
|
||||
"user" => [
|
||||
"email" => $ar_user['LOGIN'],
|
||||
"name" => $ar_user['NAME'],
|
||||
"secondname" => $ar_user['SECOND_NAME'],
|
||||
"lastname" => $ar_user['LAST_NAME'],
|
||||
"phone_number" => $ar_user['UF_PHONE_NUMBER'],
|
||||
"phone_verified" => $ar_user['UF_PHONE_VERIFIED'],
|
||||
],
|
||||
"company" => [
|
||||
"inn" => $companies[0]['inn'],
|
||||
"kpp" => $companies[0]['kpp'],
|
||||
"ogrn" => $companies[0]['ogrn'],
|
||||
"title" => $companies[0]['title'],
|
||||
],
|
||||
"companies" => $companies,
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "unknown_user",
|
||||
"message" => "Unknown user",
|
||||
]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_source",
|
||||
"message" => "Wrong source",
|
||||
]);
|
||||
}
|
||||
}
|
||||
@ -1165,11 +1757,46 @@ switch($PARAM_1)
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_auth_uri",
|
||||
"message" => "Empty auth URI",
|
||||
]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
die();
|
||||
}
|
||||
break;
|
||||
|
||||
case "companies":
|
||||
{
|
||||
try
|
||||
{
|
||||
$auth = (array) \Bitrix\Main\Web\JWT::decode($token, $secret, ["HS256"]);
|
||||
print_r($auth);
|
||||
|
||||
//print json_encode([
|
||||
// "status" => "success",
|
||||
// "token" => $auth['username'],
|
||||
//]);
|
||||
//die();
|
||||
}
|
||||
catch(\Exception $e)
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_jwt",
|
||||
"message" => $e->getMessage(),
|
||||
]);
|
||||
die();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "rules":
|
||||
{
|
||||
if(CModule::IncludeModule('iblock'))
|
||||
@ -1241,6 +1868,121 @@ switch($PARAM_1)
|
||||
}
|
||||
break;
|
||||
|
||||
case "support":
|
||||
{
|
||||
switch($PARAM_3)
|
||||
{
|
||||
case "themes":
|
||||
{
|
||||
if(CModule::IncludeModule('iblock'))
|
||||
{
|
||||
$sort = ["ACTIVE_FROM" => "DESC", "SORT" => "DESC"];
|
||||
$filter = ["ACTIVE" => "Y", "IBLOCK_ID" => 25];
|
||||
$options = [];
|
||||
|
||||
/*
|
||||
if(!empty($REQ['query']))
|
||||
{
|
||||
$filter['<DATE_ACTIVE_FROM'] = $REQ['date'];
|
||||
$options['nPageSize'] = 1;
|
||||
$sort["ACTIVE_FROM"] = "DESC";
|
||||
}
|
||||
*/
|
||||
|
||||
$themes = [];
|
||||
$themes_res = CIBlockSection::GetList( [ "SORT" => "ASC" ], [ 'IBLOCK_ID' => 25, 'GLOBAL_ACTIVE' => 'Y', ], false, );
|
||||
while($theme_result = $themes_res->GetNext())
|
||||
{
|
||||
$theme = ["id" => md5($theme_result['NAME']), "name" => $theme_result['NAME']];
|
||||
|
||||
$question_filter = [ 'IBLOCK_ID' => 25, 'SECTION_ID' => $theme_result['ID'], 'ACTIVE' => 'Y', ];
|
||||
|
||||
if(isset($REQ['query']) && !empty($REQ['query']))
|
||||
{
|
||||
$question_filter[ 'SEARCHABLE_CONTENT' ] = '%'.$REQ['query'].'%';
|
||||
}
|
||||
|
||||
$questions = [];
|
||||
$questions_res = CIBlockElement::GetList([ "SORT" => "ASC" ], $question_filter, false, []);
|
||||
while ($questions_ob_element = $questions_res->GetNextElement())
|
||||
{
|
||||
$questions_ar_res = $questions_ob_element->GetFields();
|
||||
$questions_ar_res['PROPERTIES'] = $questions_ob_element->GetProperties();
|
||||
|
||||
$templates = [];
|
||||
if(count($questions_ar_res['PROPERTIES']['TEMPLATE_FILE']['VALUE']) > 0)
|
||||
{
|
||||
foreach($questions_ar_res['PROPERTIES']['TEMPLATE_FILE']['VALUE'] AS $file_id)
|
||||
{
|
||||
$f = CFile::GetByID($file_id);
|
||||
|
||||
$file = [
|
||||
"filename" => $f->Fetch()['ORIGINAL_NAME'],
|
||||
"url" => CFile::GetPath($file_id),
|
||||
];
|
||||
$file['extension'] = strtoupper(get_ext_from_mime($f->arResult[0]['CONTENT_TYPE']));
|
||||
|
||||
$templates[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
$documents = null;
|
||||
|
||||
$question = [
|
||||
"theme_id" => md5($theme['name']),
|
||||
"theme" => $theme['name'],
|
||||
"id" => md5($questions_ar_res['NAME']),
|
||||
"title" => $questions_ar_res['NAME'],
|
||||
"answer" => $questions_ar_res['PREVIEW_TEXT'],
|
||||
"request" => $questions_ar_res['PROPERTIES']['REQUEST']['VALUE_XML_ID'] == "YES" ? true : false,
|
||||
"templates" => count($templates) > 0 ? $templates : null,
|
||||
"documents" => $questions_ar_res['PROPERTIES']['DOCUMENTS']['~VALUE'] !== "" ? $questions_ar_res['PROPERTIES']['DOCUMENTS']['~VALUE']['TEXT'] : null,
|
||||
];
|
||||
|
||||
$questions[] = $question;
|
||||
//$questions[] = $questions_ar_res;
|
||||
/*[
|
||||
"name" => $questions_ar_res['NAME'],
|
||||
"filename" => $f->Fetch()['ORIGINAL_NAME'],
|
||||
"url" => CFile::GetPath($rules_ar_res['PROPERTIES']['FILE']['VALUE']),
|
||||
];
|
||||
*/
|
||||
}
|
||||
|
||||
$theme['questions'] = $questions;
|
||||
array_push($themes, $theme);
|
||||
//print_r($theme_result);
|
||||
//print "\n\n";
|
||||
}
|
||||
|
||||
/*
|
||||
$rules_res = CIBlockElement::GetList($sort, $filter, false, $options);
|
||||
while ($rules_ob_element = $rules_res->GetNextElement())
|
||||
{
|
||||
$rules_ar_res = $rules_ob_element->GetFields();
|
||||
$rules_ar_res['PROPERTIES'] = $rules_ob_element->GetProperties();
|
||||
|
||||
$f = CFile::GetByID($rules_ar_res['PROPERTIES']['FILE']['VALUE']);
|
||||
|
||||
$rules[] = [
|
||||
"name" => $rules_ar_res['NAME'],
|
||||
"active_from" => $rules_ar_res['ACTIVE_FROM'],
|
||||
"filename" => $f->Fetch()['ORIGINAL_NAME'],
|
||||
"url" => CFile::GetPath($rules_ar_res['PROPERTIES']['FILE']['VALUE']),
|
||||
];
|
||||
}
|
||||
*/
|
||||
|
||||
print json_encode([
|
||||
"themes" => $themes,
|
||||
]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
print json_encode([
|
||||
|
||||
@ -33,6 +33,73 @@ function get_related_array($iblock_id, $ids)
|
||||
return $ar_res;
|
||||
}
|
||||
|
||||
function get_ext_from_mime($mime)
|
||||
{
|
||||
$mime_map = [
|
||||
'application/x-compressed' => '7zip',
|
||||
'image/bmp' => 'bmp',
|
||||
'image/x-bmp' => 'bmp',
|
||||
'image/x-bitmap' => 'bmp',
|
||||
'image/x-xbitmap' => 'bmp',
|
||||
'image/x-win-bitmap' => 'bmp',
|
||||
'image/x-windows-bmp' => 'bmp',
|
||||
'image/ms-bmp' => 'bmp',
|
||||
'image/x-ms-bmp' => 'bmp',
|
||||
'application/bmp' => 'bmp',
|
||||
'application/x-bmp' => 'bmp',
|
||||
'application/x-win-bitmap' => 'bmp',
|
||||
'text/x-comma-separated-values' => 'csv',
|
||||
'text/comma-separated-values' => 'csv',
|
||||
'application/vnd.msexcel' => 'csv',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
|
||||
'application/x-msdownload' => 'exe',
|
||||
'image/gif' => 'gif',
|
||||
'application/x-gzip' => 'gzip',
|
||||
'text/html' => 'html',
|
||||
'image/jpeg' => 'jpeg',
|
||||
'image/pjpeg' => 'jpeg',
|
||||
'application/pdf' => 'pdf',
|
||||
'application/octet-stream' => 'pdf',
|
||||
'image/png' => 'png',
|
||||
'image/x-png' => 'png',
|
||||
'application/powerpoint' => 'ppt',
|
||||
'application/vnd.ms-powerpoint' => 'ppt',
|
||||
'application/vnd.ms-office' => 'ppt',
|
||||
'application/msword' => 'doc',
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
|
||||
'application/x-rar' => 'rar',
|
||||
'application/rar' => 'rar',
|
||||
'application/x-rar-compressed' => 'rar',
|
||||
'text/rtf' => 'rtf',
|
||||
'text/richtext' => 'rtx',
|
||||
'application/x-tar' => 'tar',
|
||||
'application/x-gzip-compressed' => 'tgz',
|
||||
'image/tiff' => 'tiff',
|
||||
'text/plain' => 'txt',
|
||||
'application/excel' => 'xl',
|
||||
'application/msexcel' => 'xls',
|
||||
'application/x-msexcel' => 'xls',
|
||||
'application/x-ms-excel' => 'xls',
|
||||
'application/x-excel' => 'xls',
|
||||
'application/x-dos_ms_excel' => 'xls',
|
||||
'application/xls' => 'xls',
|
||||
'application/x-xls' => 'xls',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
|
||||
'application/vnd.ms-excel' => 'xlsx',
|
||||
'application/xml' => 'xml',
|
||||
'text/xml' => 'xml',
|
||||
'text/xsl' => 'xsl',
|
||||
'application/xspf+xml' => 'xspf',
|
||||
'application/x-zip' => 'zip',
|
||||
'application/zip' => 'zip',
|
||||
'application/x-zip-compressed' => 'zip',
|
||||
'application/s-compressed' => 'zip',
|
||||
'multipart/x-zip' => 'zip',
|
||||
];
|
||||
|
||||
return isset($mime_map[ $mime ]) ? $mime_map[ $mime ] : false;
|
||||
}
|
||||
|
||||
AddEventHandler("main", "OnEpilog", "OnEpilogHandler", 1);
|
||||
function OnEpilogHandler()
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user