85 $this->errorCollection[] =
new Error(
Loc::getMessage(
'B24NET_NETWORK_IN_NOT_ENABLED'), self::ERROR_NETWORK_IN_NOT_ENABLED);
101 $this->errorCollection[] =
new Error(
Loc::getMessage(
'B24NET_NETWORK_IN_NOT_ENABLED'), self::ERROR_NETWORK_IN_NOT_ENABLED);
107 $query = \CBitrix24NetPortalTransport::init();
110 $query->call(
'profile.send', array(
111 'TYPE' =>
'mobile_application_link',
113 'LANGUAGE_ID' => $language_id,
125 if (! self::isPhoneNumberValid($phone))
127 return [
'error' =>
'ERROR_CODE_INVALID_NUMBER'];
130 $phone = self::normalizePhoneNumber($phone);
131 $query = \CBitrix24NetPortalTransport::init();
135 $userId = $USER instanceof \CUser ? $USER->getId() : 0;
136 return $query->call(
'portal.verify.send', array(
138 'LANGUAGE_ID' => $language_id,
139 'USER_ID' => $userId,
154 $phone = self::normalizePhoneNumber($phone);
155 $query = \CBitrix24NetPortalTransport::init();
159 $userId = $USER instanceof \CUser ? $USER->getId() : 0;
160 return $query->call(
'portal.verify.check', array(
163 'USER_ID' => $userId,
178 $query = \CBitrix24NetPortalTransport::init();
181 $result = $query->call(
'portal.verify.status');
182 return (
bool)$result[
'result'];
193 public function getUser($networkId, $lastSearch =
'')
195 $result = $this->
getUsers(Array($networkId), $lastSearch);
197 return $result && isset($result[$networkId])? $result[$networkId]:
null;
206 public function getUsers($networkIds, $lastSearch =
'')
210 $this->errorCollection[] =
new Error(
Loc::getMessage(
'B24NET_NETWORK_IN_NOT_ENABLED'), self::ERROR_NETWORK_IN_NOT_ENABLED);
214 $query = \CBitrix24NetPortalTransport::init();
217 $this->errorCollection[] =
new Error(
Loc::getMessage(
'B24NET_SOCSERV_TRANSPORT_ERROR'), self::ERROR_SOCSERV_TRANSPORT);
221 if (!is_array($networkIds) || empty($networkIds))
223 $this->errorCollection[] =
new Error(
Loc::getMessage(
'B24NET_ERROR_INCORRECT_PARAMS'), self::ERROR_INCORRECT_PARAMS);
227 $queryResult = $query->call(
'profile.search', array(
228 'ID' => array_values($networkIds),
229 'QUERY' => trim($lastSearch)
233 foreach ($queryResult[
'result'] as $user)
235 if (!$user = self::formatUserParam($user))
239 $result[$user[
'NETWORK_ID']] = $user;
244 $this->errorCollection[] =
new Error(
Loc::getMessage(
'B24NET_SEARCH_USER_NOT_FOUND'), self::ERROR_SEARCH_USER_NOT_FOUND);
265 $user = $this->
getUser($networkId, $lastSearch);
287 foreach ($users as $networkId => $userId)
289 $result[$networkId] = $userId;
291 $networkIds = array_diff($networkIds, array_keys($users));
293 if (!empty($networkIds))
295 $users = $this->
getUsers($networkIds, $lastSearch);
301 foreach ($users as $networkId => $userParams)
303 $userId = $this->
addUser($userParams);
306 $result[$networkId] = $userId;
324 $password = md5($params[
'XML_ID'].
'|'.$params[
'CLIENT_DOMAIN'].
'|'.rand(1000,9999).
'|'.time().
'|'.uniqid());
325 $photo = \CFile::MakeFileArray($params[
'PERSONAL_PHOTO_ORIGINAL']);
328 if(Loader::includeModule(
'extranet'))
330 $groups[] = \CExtranet::GetExtranetUserGroupID();
334 'LOGIN' => $params[
'NETWORK_USER_ID'].
'@'.$params[
'CLIENT_DOMAIN'],
335 'NAME' => $params[
'NAME'],
336 'EMAIL' => $params[
'EMAIL'],
337 'LAST_NAME' => $params[
'LAST_NAME'],
338 'SECOND_NAME' => $params[
'SECOND_NAME'],
339 'PERSONAL_GENDER' => $params[
'PERSONAL_GENDER'],
340 'PERSONAL_PHOTO' => $photo,
341 'WORK_POSITION' => $params[
'CLIENT_DOMAIN'],
342 'XML_ID' => $params[
'XML_ID'],
343 'EXTERNAL_AUTH_ID' => self::EXTERNAL_AUTH_ID,
345 "PASSWORD" => $password,
346 "CONFIRM_PASSWORD" => $password,
347 "GROUP_ID" => $groups
349 if (isset($params[
'EMAIL']))
351 $addParams[
'EMAIL'] = $params[
'EMAIL'];
355 $userId = $user->Add($addParams);
356 if (intval($userId) <= 0)
358 $this->errorCollection[] =
new Error($user->LAST_ERROR, self::ERROR_REGISTER_USER);
362 $event =
new Event(
"socialservices",
"OnAfterRegisterUserByNetwork", array($userId, $params[
'NETWORK_USER_ID'], $params[
'CLIENT_DOMAIN']));
375 $result = \Bitrix\Main\UserTable::getById($userId);
376 $user = $result->fetch();
377 if (!$user || $user[
'EXTERNAL_AUTH_ID'] != self::EXTERNAL_AUTH_ID)
382 list($networkId, ) = explode(
'|', $user[
'XML_ID']);
396 return $result && isset($result[$networkId])? $result[$networkId]:
null;
406 if (!is_array($networkIds))
409 $searchArray = Array();
410 foreach ($networkIds as $networkId)
412 $searchArray[] = mb_substr($networkId, 0, 1).intval(mb_substr($networkId, 1)).
"|%";
415 $result = \Bitrix\Main\UserTable::getList(Array(
416 'select' => Array(
'ID',
'WORK_PHONE',
'PERSONAL_PHONE',
'PERSONAL_MOBILE',
'UF_PHONE_INNER',
'XML_ID'),
417 'filter' => Array(
'=%XML_ID' => $searchArray,
'=EXTERNAL_AUTH_ID' => self::EXTERNAL_AUTH_ID),
422 while($user = $result->fetch())
424 list($networkId, ) = explode(
"|", $user[
'XML_ID']);
425 $users[$networkId] = $user[
'ID'];
443 if (empty($params[
'NAME']))
445 if (!empty($params[
'PUBLIC_NAME']))
447 $params[
'NAME'] = $params[
'PUBLIC_NAME'];
449 else if (!empty($params[
'EMAIL']))
451 $params[
'NAME'] = $params[
'EMAIL'];
460 'LOGIN' => $params[
'LOGIN'],
461 'EMAIL' => $params[
'EMAIL'],
462 'NAME' => $params[
'NAME'],
463 'LAST_NAME' => $params[
'LAST_NAME'],
464 'SECOND_NAME' => $params[
'SECOND_NAME'],
465 'PUBLIC_NAME' => $params[
'PUBLIC_NAME'],
466 'PERSONAL_GENDER' => $params[
'PERSONAL_GENDER'],
467 'PERSONAL_PHOTO' => $params[
'PERSONAL_PHOTO_RESIZE'],
468 'PERSONAL_PHOTO_ORIGINAL' => $params[
'PERSONAL_PHOTO'],
469 'XML_ID' => $params[
'ID'].
'|'.$params[
'USER_ID'],
470 'NETWORK_ID' => $params[
'ID'],
471 'NETWORK_USER_ID' => $params[
'USER_ID'],
472 'REMOTE_USER_ID' => $params[
'PROFILE_ID'],
473 'CLIENT_DOMAIN' => $params[
'CLIENT_DOMAIN'],
485 if(static::getAdminPopupSession())
487 $dbRes = UserTable::getList(array(
489 '=USER_ID' => $USER->GetID(),
490 '=EXTERNAL_AUTH_ID' => \CSocServBitrix24Net::ID
495 static::initAdminPopup($params);
499 static::setAdminPopupSession();
506 $option = static::getShowOptions();
507 \CJSCore::registerExt(
"socialservices_admin", array(
508 'js' =>
"/bitrix/js/socialservices/ss_admin.js",
509 'css' =>
"/bitrix/js/socialservices/css/ss_admin.css",
510 'rel' => array(
"ajax",
"window"),
511 'lang_additional' => array(
512 "SS_NETWORK_DISPLAY" => $params[
"SHOW"] ?
"Y" :
"N",
513 "SS_NETWORK_URL" => static::getAuthUrl(
"popup", array(
"admin")),
517 "SS_NETWORK_POPUP_DONTSHOW" =>
Loc::getMessage(
'B24NET_POPUP_DONTSHOW'),
518 "SS_NETWORK_POPUP_COUNT" => $option[
"showcount"],
521 \CJSCore::init(array(
"socialservices_admin"));
524 public static function getAuthUrl($mode =
"page", $addScope =
null)
526 if(Option::get(
"socialservices",
"bitrix24net_id",
"") !=
"")
528 $o = new \CSocServBitrix24Net();
530 if($addScope !==
null)
532 $o->addScope($addScope);
535 return $o->getUrl($mode);
544 $_SESSION[static::ADMIN_SESSION_KEY] = $USER->GetID();
549 global $USER, $CACHE_MANAGER;
551 $CACHE_MANAGER->Clean(
"sso_portal_list_".$userId);
552 if($userId == $USER->GetID())
554 unset($_SESSION[static::ADMIN_SESSION_KEY]);
560 return \CUserOptions::GetOption(
"socialservices",
"networkPopup", array(
"dontshow" =>
"N",
"showcount" => 0));
567 $result = !isset($_SESSION[static::ADMIN_SESSION_KEY]) || $_SESSION[static::ADMIN_SESSION_KEY] !== $USER->GetID();
570 $option = static::getShowOptions();
571 $result = $option[
"dontshow"] !==
"Y";
574 static::setAdminPopupSession();
583 if(isset($settings[
"REGISTER"]))
585 Option::set(
"socialservices",
"new_user_registration_network", $settings[
"REGISTER"] ==
"Y" ?
"Y" :
"N");
588 if(isset($settings[
"REGISTER_CONFIRM"]))
590 Option::set(
"socialservices",
"new_user_registration_confirm", $settings[
"REGISTER_CONFIRM"] ==
"Y" ?
"Y" :
"N");
593 if(isset($settings[
"REGISTER_WHITELIST"]))
595 $value = preg_split(
"/[^a-z0-9\-\.]+/", ToLower($settings[
"REGISTER_WHITELIST"]));
596 Option::set(
"socialservices",
"new_user_registration_whitelist", serialize($value));
599 if(isset($settings[
"REGISTER_TEXT"]))
601 Option::set(
"socialservices",
"new_user_registration_text", trim($settings[
"REGISTER_TEXT"]));
604 if(isset($settings[
"REGISTER_SECRET"]))
606 Option::set(
"socialservices",
"new_user_registration_secret", trim($settings[
"REGISTER_SECRET"]));
609 static::updateRegisterSettings();
615 "REGISTER" => Option::get(
"socialservices",
"new_user_registration_network",
"N"),
616 "REGISTER_CONFIRM" => Option::get(
"socialservices",
"new_user_registration_confirm",
"N"),
617 "REGISTER_WHITELIST" => implode(
';', unserialize(Option::get(
"socialservices",
"new_user_registration_whitelist", serialize(array())))),
618 "REGISTER_TEXT" => Option::get(
"socialservices",
"new_user_registration_text",
""),
619 "REGISTER_SECRET" => Option::get(
"socialservices",
"new_user_registration_secret",
""),
625 $query = \CBitrix24NetPortalTransport::init();
628 $options = static::getRegisterSettings();
630 $query->call(
"portal.option.set", array(
'options' => array(
631 'REGISTER' => $options[
"REGISTER"] ===
"Y",
632 'REGISTER_TEXT' => $options[
"REGISTER_TEXT"],
633 "REGISTER_SECRET" => $options[
"REGISTER_SECRET"],
640 return Option::get(
"socialservices",
"network_last_update_check", 0);
645 Option::set(
"socialservices",
"network_last_update_check", time());
650 $query = \CBitrix24NetPortalTransport::init();
656 "broadcast_last_check" => static::getLastBroadcastCheck()
666 foreach(GetModuleEvents(
"socialservices",
"OnNetworkBroadcast",
true) as $eventHandler)
668 ExecuteModuleEventEx($eventHandler, array($data));
671 static::setLastBroadcastCheck();
676 static::$lastUserStatus = $status;
681 return static::$lastUserStatus;
685 private static function normalizePhoneNumber(
string $number, $defaultCountry =
'')
687 $phoneNumber = \Bitrix\Main\PhoneNumber\Parser::getInstance()->parse($number, $defaultCountry);
695 private static function isPhoneNumberValid(
string $number): bool
697 $phoneNumber = \Bitrix\Main\PhoneNumber\Parser::getInstance()->parse($number);
698 return $phoneNumber->isValid();
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
addUserById($networkId, $lastSearch='')
static getUsersId($networkIds)
const ERROR_REGISTER_USER
static getAdminPopupSession()
static displayAdminPopup(array $params=array())
const ERROR_NETWORK_IN_NOT_ENABLED
static checkPhoneVerificationCode(string $phone, int $code)
addUsersById($networkIds, $lastSearch='')
static getAuthUrl($mode="page", $addScope=null)
static sendMobileApplicationLink($phone, $language_id)
static getUserId($networkId)
static formatUserParam($params)
static initAdminPopup(array $params=array())
static getLastUserStatus()
const ERROR_SOCSERV_TRANSPORT
getUsers($networkIds, $lastSearch='')
const ERROR_SEARCH_STRING_TO_SHORT
static processBroadcastData($data)
static getPortalVerificationStatus()
static setAdminPopupSession()
static getRegisterSettings()
const ERROR_INCORRECT_PARAMS
static setRegisterSettings($settings=array())
static setLastBroadcastCheck()
static clearAdminPopupSession($userId)
static getNetworkId($userId)
static getLastBroadcastCheck()
const ERROR_SEARCH_USER_NOT_FOUND
static checkBroadcastData()
getUser($networkId, $lastSearch='')
static updateRegisterSettings()
static setLastUserStatus($status)
static sendPhoneVerificationCode(string $phone, string $language_id)