public static function SendPhoneCode($phoneNumber, $smsTemplate, $siteId = null)
public static function VerifyPhoneCode($phoneNumber, $code)
<?if(!isset($arResult["SHOW_SMS_FIELD"]) || $arResult["SHOW_SMS_FIELD"] !== true):?>
<form //..............
<input type="text" required name="PHONE_NUMBER">
</form>
<?endif;?>
<?if($arResult["SHOW_SMS_FIELD"] == true):?>
<?CJSCore::Init('phone_auth');?>
<form method="post" action="<?=$arResult["AUTH_URL"]?>" name="regform">
<input type="hidden" name="SIGNED_DATA" value="<?=htmlspecialcharsbx($arResult["SIGNED_DATA"])?>" />
<div class="bx-authform-formgroup-container">
<div class="bx-authform-label-container"><span class="bx-authform-starrequired">*</span><?echo GetMessage("main_register_sms_code")?></div>
<div class="bx-authform-input-container">
<input type="text" name="SMS_CODE" maxlength="255" value="<?=htmlspecialcharsbx($arResult["SMS_CODE"])?>" autocomplete="off" />
</div>
</div>
<div class="bx-authform-formgroup-container">
<input type="submit" class="btn btn-primary" name="code_submit_button" value="<?echo GetMessage("main_register_sms_send")?>" />
</div>
</form>
<div id="bx_auth_error" style="display:none" class="alert alert-danger"></div>
<div id="bx_auth_resend"></div>
<script>
new BX.PhoneAuth({
containerId: 'bx_auth_resend',
errorContainerId: 'bx_auth_error',
interval: <?=$arResult["PHONE_CODE_RESEND_INTERVAL"]?>,
data:
<?=CUtil::PhpToJSObject([
'signedData' => $arResult["SIGNED_DATA"],
])?>,
onError:
function(response)
{
var errorNode = BX('bx_auth_error');
errorNode.innerHTML = '';
for(var i = 0; i < response.errors.length; i++)
{
errorNode.innerHTML = errorNode.innerHTML + BX.util.htmlspecialchars(response.errors[i].message) + '<br />';
}
errorNode.style.display = '';
}
});
</script>
<?endif;?>
$arResult["PHONE_CODE_RESEND_INTERVAL"] = \CUser::PHONE_CODE_RESEND_INTERVAL;
$phoneNumber = $_REQUEST['PHONE_NUMBER'] ?? null;
$signedData = $_REQUEST['SIGNED_DATA'] ?? null;
if(!empty($phoneNumber))
{
$smsTemplate = 'SMS_USER_RESTORE_PASSWORD'; // только указываешь свой шаблон (создаешь сначала в админке)
$result = \CUser::SendPhoneCode($phoneNumber, $smsTemplate, SITE_ID);
if($result->isSuccess()) {
$arResult['SIGNED_DATA'] = \Bitrix\Main\Controller\PhoneAuth::signData([
'phoneNumber' => $phoneNumber,
'smsTemplate' => $smsTemplate
]);
$arResult["SHOW_SMS_FIELD"] = true;
}
else {
$arResult['ERROR_MESSAGE'] = $result->getErrorMessages();
}
if(!empty($signedData)) {
$arResult["SIGNED_DATA"] = $signedData;
$arResult["SHOW_SMS_FIELD"] = true;
}
// verify phone code
$isNeedVerifySmsCode = $_SERVER["REQUEST_METHOD"] == "POST" && $_REQUEST["code_submit_button"] <> '' && !$USER->IsAuthorized() && !empty($signedData);
if($isNeedVerifySmsCode)
{
$smsCode = $_REQUEST['SMS_CODE'];
if(($params = \Bitrix\Main\Controller\PhoneAuth::extractData($signedData)) !== false)
{
if(($userId = CUser::VerifyPhoneCode($params['phoneNumber'], $smsCode)))
{
$USER->Authorize($userId);
}
else
{
$arResult['ERROR_MESSAGE'] = 'Error verify code'; // здесь сам ошибку придумай
$arResult["SHOW_SMS_FIELD"] = true;
$arResult["SMS_CODE"] = $smsCode;
$arResult["SIGNED_DATA"] = $signedData;
}
}
}
}