- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
- Класс: CIMRestService
- Вызов: CIMRestService::callUserRegister
static function callUserRegister($params, $n, CRestServer $server)
{
global $APPLICATION;
if ($server->getAuthType() !== 'call')
{
throw new BitrixRestRestException("Access for this method allowed only by call authorization.", "WRONG_AUTH_TYPE", CRestServer::STATUS_FORBIDDEN);
}
$params = array_change_key_case($params, CASE_UPPER);
//1. check session info $_SESSION['LIVECHAT']['REGISTER'] - already registered?
if ($_SESSION['CALL']['REGISTER'] &&
!(isset($params['USER_HASH']) &&
trim($params['USER_HASH']) &&
preg_match("/^[a-fA-F0-9]{32}$/i", $params['USER_HASH'])))
{
$params['USER_HASH'] = $_SESSION['CALL']['REGISTER']['hash'];
}
//2. register user
$userData = BitrixImCallUser::register([
'NAME' => $params['NAME'],
'LAST_NAME' => $params['LAST_NAME'],
'AVATAR' => $params['AVATAR'],
'EMAIL' => $params['EMAIL'],
'PERSONAL_WWW' => $params['WWW'],
'PERSONAL_GENDER' => $params['GENDER'],
'WORK_POSITION' => $params['POSITION'],
'USER_HASH' => $params['USER_HASH'],
]);
if (!$userData)
{
throw new BitrixRestRestException(
BitrixImCallUser::getError()->msg,
BitrixImCallUser::getError()->code,
CRestServer::STATUS_WRONG_REQUEST
);
}
$aliasData = BitrixImAlias::get($params['ALIAS']);
if (!$aliasData)
{
throw new BitrixRestRestException("Wrong alias.", "WRONG_ALIAS", CRestServer::STATUS_FORBIDDEN);
}
//3. authorize
BitrixImCallAuth::authorizeById($userData['ID'], true, true);
//4. add to dialog
$chat = new CIMChat(0);
$chat->AddUser($aliasData['ENTITY_ID'], $userData['ID']);
if ($exception = $APPLICATION->GetException())
{
if ($exception->GetID() !== 'NOTHING_TO_ADD')
{
throw new BitrixRestRestException(
"You don't have access",
"WRONG_REQUEST",
CRestServer::STATUS_WRONG_REQUEST
);
}
}
//5. return id and hash
$result = [
'id' => (int)$userData['ID'],
'hash' => $userData['HASH'],
'created' => $userData['CREATED']
];
$_SESSION['CALL']['REGISTER'] = $result;
//6. send notification to chat owner
$chatData = CIMChat::GetChatData(['ID' => $aliasData['ENTITY_ID']]);
$chatTitle = $chatData['chat'][$aliasData['ENTITY_ID']]['name'];
$chatOwnerId = $chatData['chat'][$aliasData['ENTITY_ID']]['owner'];
$notificationText = GetMessage("IM_VIDEOCONF_NEW_GUEST", ['#CHAT_TITLE#' => $chatTitle]);
$publicLink = $aliasData['LINK'];
$conferenceLinkText = GetMessage("IM_VIDEOCONF_JOIN_LINK");
$conferenceLink = "{$conferenceLinkText}";
CIMNotify::Add(
[
'TO_USER_ID' => $chatOwnerId,
'MESSAGE' => $notificationText . "[br]" . $conferenceLink
]
);
return $result;
}