- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/authentication/device.php
- Класс: BitrixMainAuthenticationDevice
- Вызов: Device::sendEmail
static function sendEmail(EO_UserDevice $device, EO_UserDeviceLogin $deviceLogin, array $user): void
{
$site = $user['LID'];
if (!$site)
{
$site = MainContext::getCurrent()->getSite();
if (!$site)
{
$site = CSite::GetDefSite();
}
}
$currentLang = MainContext::getCurrent()->getLanguage();
$lang = $user['LANGUAGE_ID'] != '' ? $user['LANGUAGE_ID'] : $currentLang;
// Devices
$deviceTypes = DeviceType::getDescription($lang);
// City and Region names
$geoids = array_filter([$deviceLogin->getCityGeoid(), $deviceLogin->getRegionGeoid()]);
$geonames = GeonameTable::get($geoids);
$city = '';
$region = '';
if (!empty($geonames))
{
$langCode = '';
if ($user['LANGUAGE_ID'] != '' && $user['LANGUAGE_ID'] != $currentLang)
{
$language = LanguageTable::getList([
'filter' => ['=LID' => $user['LANGUAGE_ID'], '=ACTIVE' => 'Y'],
'cache' => ['ttl' => 86400],
])->fetchObject();
if ($language)
{
$langCode = $language->getCode();
}
}
if ($langCode == '')
{
$langCode = MainContext::getCurrent()->getLanguageObject()->getCode();
}
if (($cityCode = $deviceLogin->getCityGeoid()) > 0)
{
$city = $geonames[$cityCode][$langCode] ?? $geonames[$cityCode]['en'] ?? '';
}
if (($regionCode = $deviceLogin->getRegionGeoid()) > 0)
{
$region = $geonames[$regionCode][$langCode] ?? $geonames[$regionCode]['en'] ?? '';
}
}
// Country name
$country = '';
if (($countryCode = $deviceLogin->getCountryIsoCode()) != '')
{
$countries = GetCountries($lang);
$country = $countries[$countryCode]['NAME'];
}
// Combined location
$location = implode(', ', array_filter([$city, $region, $country]));
$fields = [
'EMAIL' => $user['EMAIL'],
'LOGIN' => $user['LOGIN'],
'NAME' => $user['NAME'],
'LAST_NAME' => $user['LAST_NAME'],
'DEVICE' => $deviceTypes[$device->getDeviceType()],
'BROWSER' => $device->getBrowser(),
'PLATFORM' => $device->getPlatform(),
'USER_AGENT' => $device->getUserAgent(),
'IP' => $deviceLogin->getIp(),
'DATE' => $deviceLogin->getLoginDate(),
'COUNTRY' => $country,
'REGION' => $region,
'CITY' => $city,
'LOCATION' => $location,
];
MailEvent::send([
'EVENT_NAME' => self::EMAIL_EVENT,
'C_FIELDS' => $fields,
'LID' => $site,
'LANGUAGE_ID' => $lang,
]);
}