1
0
Fork 0
mirror of synced 2025-04-18 16:41:02 +00:00

repair registration with sms

This commit is contained in:
Sergey Chazov 2021-09-24 15:58:01 +03:00 committed by Neur0toxine
parent c1b0266c35
commit 8ca12c5ddf
4 changed files with 59 additions and 66 deletions

View file

@ -180,7 +180,7 @@ function sendVerificationCode() {
{
data: {
sessid: BX.bitrix_sessid(),
code: verificationCode,
verificationCode: verificationCode,
checkId: checkId
}
}

View file

@ -148,7 +148,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && $_REQUEST["register_submit_button"]
{
$arError = $arResult["ERRORS"];
foreach($arError as $key => $error)
if(intval($key) == 0 && $key !== 0)
if(intval($key) == 0 && $key !== 0)
$arError[$key] = str_replace("#FIELD_NAME#", '"'.$key.'"', $error);
CEventLog::Log("SECURITY", "USER_REGISTER_FAIL", "main", false, implode("<br>", $arError));
}
@ -172,7 +172,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && $_REQUEST["register_submit_button"]
$arResult['VALUES']["USER_IP"] = $_SERVER["REMOTE_ADDR"];
$arResult['VALUES']["USER_HOST"] = @gethostbyaddr($_SERVER["REMOTE_ADDR"]);
if($arResult["VALUES"]["AUTO_TIME_ZONE"] <> "Y" && $arResult["VALUES"]["AUTO_TIME_ZONE"] <> "N")
$arResult["VALUES"]["AUTO_TIME_ZONE"] = "";
@ -198,7 +198,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && $_REQUEST["register_submit_button"]
$ID = $user->Add($arResult["VALUES"]);
}
if (intval($ID) > 0)
if ((int) $ID > 0)
{
if($arResult["PHONE_REGISTRATION"] == true && $arResult['VALUES']["PHONE_NUMBER"] <> '')
{
@ -322,11 +322,11 @@ foreach ($arResult["REQUIRED_FIELDS"] as $field)
$arResult["BACKURL"] = htmlspecialcharsbx($_REQUEST["backurl"]);
// get countries list
if (in_array("PERSONAL_COUNTRY", $arResult["SHOW_FIELDS"]) || in_array("WORK_COUNTRY", $arResult["SHOW_FIELDS"]))
if (in_array("PERSONAL_COUNTRY", $arResult["SHOW_FIELDS"]) || in_array("WORK_COUNTRY", $arResult["SHOW_FIELDS"]))
$arResult["COUNTRIES"] = GetCountryArray();
// get date format
if (in_array("PERSONAL_BIRTHDAY", $arResult["SHOW_FIELDS"]))
if (in_array("PERSONAL_BIRTHDAY", $arResult["SHOW_FIELDS"]))
$arResult["DATE_FORMAT"] = CLang::GetDateFormat("SHORT");
// ********************* User properties ***************************************************
@ -360,7 +360,7 @@ if ($arResult["USE_CAPTCHA"] == "Y")
$arResult["CAPTCHA_CODE"] = htmlspecialcharsbx($APPLICATION->CaptchaGetCode());
// set title
if ($arParams["SET_TITLE"] == "Y")
if ($arParams["SET_TITLE"] == "Y")
$APPLICATION->SetTitle(GetMessage("REGISTER_DEFAULT_TITLE"));
//time zones

View file

@ -42,7 +42,7 @@ class CookieService
return (isset($_COOKIE['_rc']) && $_COOKIE['_rc'] != '') ? $_COOKIE['_rc'] : null;
}
/**
* Получает десерализованное содержимое куки
*
@ -53,42 +53,43 @@ class CookieService
{
try {
$application = Application::getInstance();
if ($application === null) {
return null;
}
$cookieJson = $application->getContext()->getRequest()->getCookie($cookieName);
if ($cookieJson !== null) {
return Deserializer::deserialize($cookieJson, SmsCookie::class);
}
} catch (SystemException | Exception $exception) {
Logger::getInstance()->write($exception->getMessage());
}
return null;
}
/**
* @param string $cookieName
* @param \Intaro\RetailCrm\Model\Api\SmsVerification $smsVerification
*
* @return \Intaro\RetailCrm\Model\Bitrix\SmsCookie
* @throws \ReflectionException
*/
public function setSmsCookie(string $cookieName, SmsVerification $smsVerification): SmsCookie
{
$resendAvailable = $smsVerification->createdAt->modify('+1 minutes');
$smsCookie = new SmsCookie();
$smsCookie->createdAt = $smsVerification->createdAt;
$smsCookie->resendAvailable = $resendAvailable;
$smsCookie->isVerified = !empty($smsVerification->verifiedAt);
$smsCookie->expiredAt = $smsVerification->expiredAt;
$smsCookie->checkId = $smsVerification->checkId;
$serializedArray = Serializer::serialize($smsCookie);
$cookie = new Cookie(
$cookieName,
$serializedArray,
@ -97,9 +98,9 @@ class CookieService
'YYYY.MM.DD HH:MI:SS'
)
);
Context::getCurrent()->getResponse()->addCookie($cookie);
return $smsCookie;
}
}

View file

@ -16,18 +16,14 @@ namespace Intaro\RetailCrm\Service;
use CUser;
use DateTime;
use Intaro\RetailCrm\Component\ConfigProvider;
use Intaro\RetailCrm\Component\Constants;
use Intaro\RetailCrm\Component\Factory\ClientFactory;
use Intaro\RetailCrm\Component\Json\Deserializer;
use Intaro\RetailCrm\Component\Json\Serializer;
use Intaro\RetailCrm\Component\ServiceLocator;
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountActivateRequest;
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountCreateRequest;
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountEditRequest;
use Intaro\RetailCrm\Model\Api\Request\SmsVerification\SmsVerificationConfirmRequest;
use Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountActivateResponse;
use Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountCreateResponse;
use Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountEditResponse;
use Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationConfirmResponse;
use Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationStatusRequest;
use Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationStatusResponse;
@ -219,49 +215,6 @@ class LoyaltyAccountService
}
//НЕТ. Аккаунт не активен
//Пробуем активировать аккаунт
$activateResponse = $this->activateLoyaltyAccount($loyalty->getIdInLoyalty());
if ($activateResponse === null) {
return ['msg' => GetMessage('ACTIVATE_ERROR')];
}
//Если отметка не стоит, но аккаунт активирован на стороне CRM
if ($activateResponse->errorMsg === GetMessage('ALREADY_ACTIVE')) {
$this->setLoyaltyActivateFlag($USER->GetID());
return ['msg' => GetMessage('REG_COMPLETE')];
}
if ($activateResponse->success && $activateResponse->loyaltyAccount->active === true) {
$this->setLoyaltyActivateFlag($USER->GetID());
return ['msg' => GetMessage('REG_COMPLETE')];
}
$requiredFields = $this->checkErrors($activateResponse);
//если есть незаполненные обязательные поля
if ($_GET['activate'] === 'Y' && count($requiredFields) > 0) {
return [
'msg' => GetMessage('ACTIVATE_YOUR_ACCOUNT'),
'form' => [
'button' => [
'name' => GetMessage('ACTIVATE'),
'action' => 'activateAccount',
],
'fields' => $this->getStandardFields($this->user),
'externalFields' => $this->getExternalFields($requiredFields),
],
];
}
if ($_GET['activate'] !== 'Y' && count($requiredFields) > 0) {
return [
'msg' => GetMessage('GO_TO_PERSONAL'),
];
}
return $this->tryActivate($loyalty->getIdInLoyalty());
}
@ -308,9 +261,12 @@ class LoyaltyAccountService
* @param int $idInLoyalty
*
* @return array
* @throws \ReflectionException
*/
public function tryActivate(int $idInLoyalty): array
{
global $USER;
/** @var \Intaro\RetailCrm\Service\CookieService $service */
$service = ServiceLocator::get(CookieService::class);
@ -346,6 +302,43 @@ class LoyaltyAccountService
//Пробуем активировать аккаунт
$activateResponse = $this->activateLoyaltyAccount($idInLoyalty);
if ($activateResponse === null) {
return ['msg' => GetMessage('ACTIVATE_ERROR')];
}
//Если отметка не стоит, но аккаунт активирован на стороне CRM
if (
($activateResponse->success && $activateResponse->loyaltyAccount->active === true)
|| $activateResponse->errorMsg === GetMessage('ALREADY_ACTIVE')
) {
$this->setLoyaltyActivateFlag($USER->GetID());
return ['msg' => GetMessage('REG_COMPLETE')];
}
$requiredFields = $this->checkErrors($activateResponse);
//если есть незаполненные обязательные поля
if ($_GET['activate'] === 'Y' && count($requiredFields) > 0) {
return [
'msg' => GetMessage('ACTIVATE_YOUR_ACCOUNT'),
'form' => [
'button' => [
'name' => GetMessage('ACTIVATE'),
'action' => 'activateAccount',
],
'fields' => $this->getStandardFields($this->user),
'externalFields' => $this->getExternalFields($requiredFields),
],
];
}
if ($_GET['activate'] !== 'Y' && count($requiredFields) > 0) {
return [
'msg' => GetMessage('GO_TO_PERSONAL'),
];
}
if ($activateResponse !== null
&& isset($activateResponse->loyaltyAccount->active)
&& $activateResponse->loyaltyAccount->active === true
@ -437,7 +430,6 @@ class LoyaltyAccountService
*/
private function getStandardFields(User $user): array
{
$resultFields = [];
$userFields = Serializer::serializeArray($user->getLoyalty());
$userFields['PERSONAL_PHONE'] = $user->getPersonalPhone();