API user & company fix when updating
This commit is contained in:
parent
3c3eb40e98
commit
d65f45e242
@ -406,6 +406,13 @@ switch($PARAM_1)
|
||||
{
|
||||
switch($PARAM_2)
|
||||
{
|
||||
case "test":
|
||||
{
|
||||
if($auth['username'] !== 'crm') { header('HTTP/1.0 401 Unauthorized'); print json_encode(["status" => "error", "error" => "unauthorized", "message" => "Unauthorized"]); die(); }
|
||||
die("OK");
|
||||
}
|
||||
break;
|
||||
|
||||
case "registration":
|
||||
{
|
||||
if($auth['username'] !== 'crm') { header('HTTP/1.0 401 Unauthorized'); print json_encode(["status" => "error", "error" => "unauthorized", "message" => "Unauthorized"]); die(); }
|
||||
@ -465,6 +472,9 @@ switch($PARAM_1)
|
||||
if($user_registered_id !== null)
|
||||
{
|
||||
//user exists
|
||||
/*
|
||||
пользователь с указанным $REQ['email'] сущестуют
|
||||
*/
|
||||
|
||||
if($company_registered_id === null)
|
||||
{
|
||||
@ -490,55 +500,6 @@ 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"
|
||||
]);
|
||||
@ -664,14 +625,23 @@ switch($PARAM_1)
|
||||
if($user_registered !== null)
|
||||
{
|
||||
// user exists
|
||||
/*
|
||||
пользователь с указанным $REQ['email'] сущестуют
|
||||
*/
|
||||
|
||||
if($company_registered_id !== null)
|
||||
{
|
||||
//existed company
|
||||
/*
|
||||
компания с указанным $REQ['crm_id'] сущестуют
|
||||
*/
|
||||
|
||||
$profile["PASSWORD"] = $REQ['password'];
|
||||
$profile["CONFIRM_PASSWORD"] = $REQ['password'];
|
||||
|
||||
/*
|
||||
устанавливаем указанному юзеру параметры из сфрормрованного пакета (из данных из CRM)
|
||||
*/
|
||||
$user = new \CUser;
|
||||
$user->Update($user_registered, $profile);
|
||||
|
||||
@ -689,6 +659,8 @@ switch($PARAM_1)
|
||||
]);
|
||||
}
|
||||
|
||||
setCompanyForUser($user_registered, $REQ, true);
|
||||
|
||||
print json_encode([
|
||||
"status" => "success"
|
||||
]);
|
||||
@ -711,6 +683,9 @@ switch($PARAM_1)
|
||||
else
|
||||
{
|
||||
// new user
|
||||
/*
|
||||
новый пользователь
|
||||
*/
|
||||
|
||||
if($company_registered_id !== null)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user