- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/controller/authcode.php
- Класс: BitrixMainControllerAuthCode
- Вызов: AuthCode::confirmAction
public function confirmAction($code, $signedData)
{
global $USER;
try
{
$params = ComponentParameterSigner::unsignParameters(self::SIGNATURE_SALT, $signedData);
}
catch(MainSystemException $e)
{
$this->addError(new MainError(Loc::getMessage("main_authcode_incorrect_request"), "ERR_SIGNATURE"));
return null;
}
if(!preg_match('/^[0-9]{6}$/', $code))
{
$this->addError(new MainError(Loc::getMessage("main_authcode_incorrect_code"), "ERR_FORMAT_CODE"));
return null;
}
$context = new MainAuthenticationContext();
$context->setUserId($params["userId"]);
$shortCode = new MainAuthenticationShortCode($context);
$result = $shortCode->verify($code);
if($result->isSuccess())
{
$codeUser = $shortCode->getUser();
if(!$USER->IsAuthorized() && $codeUser->getActive() && !$codeUser->getBlocked())
{
if(MainLoader::includeModule("security"))
{
if(MfaOtp::verifyUser(["USER_ID" => $params["userId"]]) == false)
{
$this->addError(new MainError(Loc::getMessage("main_authcode_otp_required"), 'ERR_OTP_REQUIRED'));
$this->checkOtpCaptcha();
return null;
}
}
$USER->Authorize($params["userId"]);
}
return true;
}
else
{
//replace the error message with the more specific one
if($result->getErrorCollection()->getErrorByCode("ERR_CONFIRM_CODE") !== null)
{
$this->addError(new MainError(Loc::getMessage("main_authcode_incorrect_code_input"), 'ERR_CONFIRM_CODE'));
}
if($result->getErrorCollection()->getErrorByCode("ERR_RETRY_COUNT") !== null)
{
$this->addError(new MainError(Loc::getMessage("main_authcode_retry_count"), "ERR_RETRY_COUNT"));
}
return null;
}
}