codestyle fix after review
This commit is contained in:
parent
39ced72ada
commit
fdd991bff9
7 changed files with 100 additions and 66 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
use Intaro\RetailCrm\Component\ServiceLocator;
|
||||
use Intaro\RetailCrm\Service\CollectorCookieExtractor;
|
||||
use Intaro\RetailCrm\Service\UserVerificationService;
|
||||
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\AnnotationRegistry;
|
||||
|
||||
|
@ -27,5 +28,6 @@ ServiceLocator::registerServices([
|
|||
\Intaro\RetailCrm\Service\Utils::class,
|
||||
Logger::class,
|
||||
AnnotationReader::class,
|
||||
CollectorCookieExtractor::class
|
||||
CollectorCookieExtractor::class,
|
||||
UserVerificationService::class
|
||||
]);
|
||||
|
|
|
@ -33,7 +33,6 @@ use Intaro\RetailCrm\Model\Api\Response\OperationResponse;
|
|||
*/
|
||||
trait CustomersCorporateTrait
|
||||
{
|
||||
|
||||
/**
|
||||
* Create customers corporate
|
||||
*
|
||||
|
|
|
@ -25,7 +25,7 @@ class ClientFactory
|
|||
*
|
||||
* @return \Intaro\RetailCrm\Component\ApiClient\ClientAdapter|null
|
||||
*/
|
||||
public static function creacteClientAdapter(): ?ClientAdapter
|
||||
public static function createClientAdapter(): ?ClientAdapter
|
||||
{
|
||||
$apiHost = ConfigProvider::getApiUrl();
|
||||
$apiKey = ConfigProvider::getApiKey();
|
||||
|
|
|
@ -14,29 +14,102 @@ namespace Intaro\RetailCrm\Controller\Loyalty;
|
|||
use Bitrix\Main\Engine\ActionFilter\Authentication;
|
||||
use Bitrix\Main\Engine\ActionFilter\HttpMethod;
|
||||
use Bitrix\Main\Engine\Controller;
|
||||
use Bitrix\Main\Request;
|
||||
use Intaro\RetailCrm\Component\ServiceLocator;
|
||||
use Intaro\RetailCrm\Service\UserVerificationService;
|
||||
|
||||
/**
|
||||
* Class AdminPanel
|
||||
* @package Intaro\RetailCrm\Controller\Loyalty
|
||||
*/
|
||||
class AdminPanel extends Controller
|
||||
{
|
||||
|
||||
/** @var int */
|
||||
const DEFAULT_CODE_LENGHT = 4;
|
||||
|
||||
/** @var UserVerificationService */
|
||||
private $service;
|
||||
|
||||
/**
|
||||
* AdminPanel constructor.
|
||||
* @param \Bitrix\Main\Request|null $request
|
||||
*/
|
||||
public function __construct(Request $request = null)
|
||||
{
|
||||
$this->service = ServiceLocator::get(UserVerificationService::class);
|
||||
parent::__construct($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send verification sms
|
||||
*
|
||||
* @param string $actionType
|
||||
* @param int|null $orderId
|
||||
* @param int $verificationLength
|
||||
* @return \Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationCreateResponse|null
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function sendSmsAction(
|
||||
string $actionType = 'verify_customer',
|
||||
int $orderId = null,
|
||||
int $verificationLength = self::DEFAULT_CODE_LENGHT
|
||||
) {
|
||||
return $this->service->sendSms($actionType, $orderId, $verificationLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Контроллер получает статус текущего состояния верификации
|
||||
*
|
||||
* @param string $checkId
|
||||
* @return \Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationStatusResponse|null
|
||||
*/
|
||||
public function getSmsStatusAction(string $checkId)
|
||||
{
|
||||
return $this->service->getSmsStatus($checkId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Контроллер подтверждает верификацию
|
||||
*
|
||||
* @param string $code
|
||||
* @param string $checkId
|
||||
* @return \Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationConfirmResponse|null
|
||||
*/
|
||||
public function confirmVerificationAction(string $code, string $checkId)
|
||||
{
|
||||
return $this->service->confirmVerification($code, $checkId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Контроллер проверяет, зарегистрирован ли пользователь в программе лояльности
|
||||
*
|
||||
* @param int $userId
|
||||
* @return bool
|
||||
*/
|
||||
public function checkPlRegistrationStatusAction(int $userId)
|
||||
{
|
||||
return $this->service->checkPlRegistrationStatus($userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \array[][]
|
||||
*/
|
||||
public function configureActions(): array
|
||||
{
|
||||
return [
|
||||
'sendSms' => [
|
||||
'sendSms' => [
|
||||
'-prefilters' => [
|
||||
new Authentication,
|
||||
new HttpMethod(['GET']),
|
||||
],
|
||||
],
|
||||
'getSmsStatus' => [
|
||||
'getSmsStatus' => [
|
||||
'-prefilters' => [
|
||||
new Authentication,
|
||||
new HttpMethod(['GET']),
|
||||
],
|
||||
],
|
||||
'confirmVerification' => [
|
||||
'confirmVerification' => [
|
||||
'-prefilters' => [
|
||||
new Authentication,
|
||||
new HttpMethod(['GET']),
|
||||
|
@ -50,54 +123,4 @@ class AdminPanel extends Controller
|
|||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* send verification sms
|
||||
*
|
||||
* @param string $actionType
|
||||
* @param int|null $orderId
|
||||
* @param int $verificationLength
|
||||
* @return \Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationCreateResponse|null
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function sendSmsAction(
|
||||
string $actionType = 'verify_customer',
|
||||
int $orderId = null,
|
||||
int $verificationLength = self::DEFAULT_CODE_LENGHT
|
||||
) {
|
||||
$service = new UserVerificationService();
|
||||
return $service->sendSms($actionType, $orderId, $verificationLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $checkId
|
||||
* @return \Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationStatusResponse|null
|
||||
*/
|
||||
public function getSmsStatusAction(string $checkId)
|
||||
{
|
||||
$service = new UserVerificationService();
|
||||
return $service->getSmsStatus($checkId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param string $checkId
|
||||
* @return \Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationConfirmResponse|null
|
||||
*/
|
||||
public function confirmVerificationAction(string $code, string $checkId)
|
||||
{
|
||||
$service = new UserVerificationService();
|
||||
return $service->confirmVerification($code, $checkId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @return bool
|
||||
*/
|
||||
public function checkPlRegistrationStatusAction(int $userId)
|
||||
{
|
||||
$service = new UserVerificationService();
|
||||
return $service->checkPlRegistrationStatus($userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,15 +21,19 @@ use Intaro\RetailCrm\Model\Bitrix\User;
|
|||
class CurrentUserProvider
|
||||
{
|
||||
/**
|
||||
* @param $userId
|
||||
* Получает текущего пользователя
|
||||
*
|
||||
* @return \Intaro\RetailCrm\Model\Bitrix\User|null
|
||||
*/
|
||||
public function get($userId): ?User
|
||||
public function get(): ?User
|
||||
{
|
||||
return UserRepository::getById($userId);
|
||||
global $USER;
|
||||
return UserRepository::getById($USER->GetID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Получаем ID пользователя
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getId(): ?int
|
||||
|
@ -37,4 +41,4 @@ class CurrentUserProvider
|
|||
global $USER;
|
||||
return $USER->GetID();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,11 +42,11 @@ class UserRepository extends AbstractRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $where
|
||||
* @param $select
|
||||
* @param array $where
|
||||
* @param array $select
|
||||
* @return mixed|null
|
||||
*/
|
||||
public static function getFirstByParams($where, $select){
|
||||
public static function getFirstByParams(array $where, array $select){
|
||||
try {
|
||||
$user = UserTable::query()
|
||||
->setSelect($select)
|
||||
|
|
|
@ -27,11 +27,13 @@ class UserVerificationService
|
|||
{
|
||||
const NOT_AUTHORIZE = 'Пользователь не авторизован';
|
||||
const DEFAULT_CODE_LENGHT = 4;
|
||||
|
||||
/**
|
||||
* @var \Intaro\RetailCrm\Component\ApiClient\ClientAdapter
|
||||
*/
|
||||
private $client;
|
||||
private $userId;
|
||||
|
||||
/**
|
||||
* @var \CAllUser|\CUser
|
||||
*/
|
||||
|
@ -39,7 +41,7 @@ class UserVerificationService
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = ClientFactory::creacteClientAdapter();
|
||||
$this->client = ClientFactory::createClientAdapter();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,12 +60,14 @@ class UserVerificationService
|
|||
) {
|
||||
$this->checkAuth();
|
||||
$userId = $this->user->GetID();
|
||||
|
||||
$where = [['ID', '=', $userId]];
|
||||
$select = ['PERSONAL_PHONE'];
|
||||
/** @var \Intaro\RetailCrm\Model\Bitrix\User $user */
|
||||
$user = UserRepository::getFirstByParams($where, $select);
|
||||
$request = new SmsVerificationCreateRequest();
|
||||
$request->verification = new SmsVerificationCreate();
|
||||
|
||||
$request->verification->setLength($verificationLength);
|
||||
$request->verification->setPhone($user->getPersonalPhone());
|
||||
$request->verification->setPhone($this->userId);
|
||||
|
@ -75,6 +79,8 @@ class UserVerificationService
|
|||
}
|
||||
|
||||
/**
|
||||
* Получает статус текущего состояния верификации
|
||||
*
|
||||
* @param string $checkId Идентификатор проверки кода
|
||||
* @return \Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationStatusResponse|null
|
||||
*/
|
||||
|
@ -122,4 +128,4 @@ class UserVerificationService
|
|||
throw new Exception(self::NOT_AUTHORIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue