- Модуль: socialservices
- Путь к файлу: ~/bitrix/modules/socialservices/classes/general/google.php
- Класс: CSocServGoogleOAuth
- Вызов: CSocServGoogleOAuth::prepareUser
public function prepareUser($arGoogleUser, $short = false)
{
$first_name = "";
$last_name = "";
if(is_array($arGoogleUser['name']))
{
$first_name = $arGoogleUser['name']['givenName'];
$last_name = $arGoogleUser['name']['familyName'];
}
elseif($arGoogleUser['name'] <> '')
{
$aName = explode(" ", $arGoogleUser['name']);
if($arGoogleUser['given_name'] <> '')
$first_name = $arGoogleUser['given_name'];
else
$first_name = $aName[0];
if($arGoogleUser['family_name'] <> '')
$last_name = $arGoogleUser['family_name'];
elseif(isset($aName[1]))
$last_name = $aName[1];
}
$id = $arGoogleUser['id'] ?? $arGoogleUser['sub'];
$email = $arGoogleUser['email'];
if($arGoogleUser['email'] <> '')
{
$dbRes = BitrixMainUserTable::getList(array(
'filter' => array(
'=EXTERNAL_AUTH_ID' => 'socservices',
'=XML_ID' => $email,
),
'select' => array('ID'),
'limit' => 1
));
if($dbRes->fetch())
{
$id = $email;
}
}
$arFields = array(
'EXTERNAL_AUTH_ID' => static::ID,
'XML_ID' => $id,
'LOGIN' => static::LOGIN_PREFIX.$id,
'EMAIL' => $email,
'NAME'=> $first_name,
'LAST_NAME'=> $last_name,
'OATOKEN' => $this->entityOAuth->getToken(),
'OATOKEN_EXPIRES' => $this->entityOAuth->getAccessTokenExpires(),
'REFRESH_TOKEN' => $this->entityOAuth->getRefreshToken(),
);
if($arGoogleUser['gender'] <> '')
{
if($arGoogleUser['gender'] == 'male')
{
$arFields["PERSONAL_GENDER"] = 'M';
}
elseif($arGoogleUser['gender'] == 'female')
{
$arFields["PERSONAL_GENDER"] = 'F';
}
}
if(!$short && isset($arGoogleUser['picture']) && static::CheckPhotoURI($arGoogleUser['picture']))
{
$arGoogleUser['picture'] = preg_replace("/?.*$/", '', $arGoogleUser['picture']);
$arPic = false;
if ($arGoogleUser['picture'])
{
$temp_path = CFile::GetTempName('', sha1($arGoogleUser['picture']));
$http = new HttpClient();
$http->setPrivateIp(false);
if($http->download($arGoogleUser['picture'], $temp_path))
{
$arPic = CFile::MakeFileArray($temp_path);
}
}
if($arPic)
{
$arFields["PERSONAL_PHOTO"] = $arPic;
}
}
$arFields["PERSONAL_WWW"] = isset($arGoogleUser['link'])
? $arGoogleUser['link']
: $arGoogleUser['url'];
if(SITE_ID <> '')
{
$arFields["SITE_ID"] = SITE_ID;
}
return $arFields;
}