• Модуль: security
  • Путь к файлу: ~/bitrix/modules/security/lib/mfa/recoverycodes.php
  • Класс: BitrixSecurityMfaRecoveryCodesTable
  • Вызов: RecoveryCodesTable::useCode
static function useCode($userId, $searchCode)
{
	$userId = (int) $userId;
	if ($userId <= 0)
		throw new ArgumentTypeException('userId', 'positive integer');

	if (!preg_match(static::CODE_PATTERN, $searchCode))
		throw new ArgumentTypeException('searchCode', sprintf('string, check pattern "%s"', static::CODE_PATTERN));

	$codes = static::getList(array(
		'select' => array('ID', 'CODE'),
		'filter' => array('=USER_ID' => $userId, '=USED' => 'N'),
	));

	$found = false;
	while (($code = $codes->fetch()))
	{
		if($code['CODE'] === $searchCode)
		{
			static::update($code['ID'], array(
				'USED' => 'Y',
				'USING_DATE' => new TypeDateTime,
				'USING_IP' => BitrixMainApplication::getInstance()->getContext()->getRequest()->getRemoteAddress()
			));
			$found = true;
			break;
		}
	}

	return $found;
}