Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
phoneauth.php
1
<?php
8
namespace
Bitrix\Main\Controller
;
9
10
use
Bitrix\Main
;
11
use
Bitrix\Main\Component
;
12
use
Bitrix\Main\Localization\Loc
;
13
14
class
PhoneAuth
extends
Main\Engine\Controller
15
{
16
const
SIGNATURE_SALT
=
'phone_auth_sms'
;
17
18
public
function
resendCodeAction
($signedData)
19
{
20
if
(($params = static::extractData($signedData)) ===
false
)
21
{
22
$this->
addError
(
new
Main\
Error
(
Loc::getMessage
(
"main_register_incorrect_request"
),
"ERR_SIGNATURE"
));
23
return
null
;
24
}
25
if
($params[
"phoneNumber"
] ==
''
)
26
{
27
$this->
addError
(
new
Main\
Error
(
Loc::getMessage
(
"main_register_incorrect_request"
),
"ERR_PARAMS"
));
28
return
null
;
29
}
30
if
($params[
"smsTemplate"
] ==
''
)
31
{
32
$params[
"smsTemplate"
] =
"SMS_USER_CONFIRM_NUMBER"
;
33
}
34
35
$result = \CUser::SendPhoneCode($params[
"phoneNumber"
], $params[
"smsTemplate"
]);
36
37
if
(!$result->isSuccess())
38
{
39
$this->
addErrors
($result->getErrors());
40
return
null
;
41
}
42
43
return
[
44
'DATA_SIGN'
=> static::signData([
45
'phoneNumber'
=> $params[
"phoneNumber"
],
46
'smsTemplate'
=> $params[
"smsTemplate"
]
47
]),
48
'DATE_SEND'
=> \CUser::PHONE_CODE_RESEND_INTERVAL,
49
];
50
}
51
52
public
function
confirmAction
($code, $signedData)
53
{
54
global $USER;
55
56
try
57
{
58
$signer =
new
Main\Security\Sign\Signer
();
59
$userId = $signer->unsign($signedData, static::SIGNATURE_SALT);
60
}
61
catch
(\
Bitrix
\Main\
SystemException
$exception)
62
{
63
$this->
addError
(
new
Main\
Error
(
Loc::getMessage
(
'main_register_incorrect_request'
),
'ERR_SIGNATURE'
));
64
return
null
;
65
}
66
67
if
(!preg_match(
'/^[0-9]{6}$/'
, $code))
68
{
69
$this->
addError
(
new
Main\
Error
(
Loc::getMessage
(
'main_err_confirm_code_format'
),
'ERR_CONFIRM_CODE'
));
70
return
null
;
71
}
72
73
$phoneRecord = Main\UserPhoneAuthTable::getList([
74
'filter'
=> [
75
'=USER_ID'
=> $userId
76
],
77
'select'
=> [
'USER_ID'
,
'PHONE_NUMBER'
,
'USER.ID'
,
'USER.ACTIVE'
],
78
])->fetchObject();
79
80
if
(!$phoneRecord)
81
{
82
$this->
addError
(
new
Main\
Error
(
Loc::getMessage
(
'main_register_no_user'
),
'ERR_NOT_FOUND'
));
83
return
null
;
84
}
85
86
if
(\CUser::VerifyPhoneCode($phoneRecord->getPhoneNumber(), $code))
87
{
88
if
($phoneRecord->getUser()->getActive() && !$USER->IsAuthorized())
89
{
90
$USER->Authorize($userId);
91
}
92
93
return
true
;
94
}
95
else
96
{
97
$this->
addError
(
new
Main\
Error
(
Loc::getMessage
(
'main_err_confirm'
),
'ERR_CONFIRM_CODE'
));
98
return
null
;
99
}
100
}
101
102
public
function
configureActions
()
103
{
104
return
[
105
'resendCode'
=> [
106
'-prefilters'
=> [
107
Main\Engine\ActionFilter\Authentication::class,
108
],
109
],
110
'confirm'
=> [
111
'-prefilters'
=> [
112
Main\Engine\ActionFilter\Authentication::class,
113
],
114
],
115
];
116
}
117
123
public
static
function
signData
(array $data)
124
{
125
return
Component\ParameterSigner::signParameters(self::SIGNATURE_SALT, $data);
126
}
127
133
public
static
function
extractData
($signedData)
134
{
135
try
136
{
137
return
Component\ParameterSigner::unsignParameters(self::SIGNATURE_SALT, $signedData);
138
}
139
catch
(Main\
SystemException
$exception)
140
{
141
return
false
;
142
}
143
}
144
}
Bitrix\Main\Controller\PhoneAuth
Definition
phoneauth.php:15
Bitrix\Main\Controller\PhoneAuth\SIGNATURE_SALT
const SIGNATURE_SALT
Definition
phoneauth.php:16
Bitrix\Main\Controller\PhoneAuth\resendCodeAction
resendCodeAction($signedData)
Definition
phoneauth.php:18
Bitrix\Main\Controller\PhoneAuth\extractData
static extractData($signedData)
Definition
phoneauth.php:133
Bitrix\Main\Controller\PhoneAuth\confirmAction
confirmAction($code, $signedData)
Definition
phoneauth.php:52
Bitrix\Main\Controller\PhoneAuth\signData
static signData(array $data)
Definition
phoneauth.php:123
Bitrix\Main\Controller\PhoneAuth\configureActions
configureActions()
Definition
phoneauth.php:102
Bitrix\Main\Engine\Controller
Definition
controller.php:32
Bitrix\Main\Engine\Controller\addError
addError(Error $error)
Definition
controller.php:1051
Bitrix\Main\Engine\Controller\addErrors
addErrors(array $errors)
Definition
controller.php:1064
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\Security\Sign\Signer
Definition
signer.php:13
Bitrix\Main\SystemException
Definition
exception.php:8
Bitrix\Main\Component
Definition
baseufcomponent.php:3
Bitrix\Main\Controller
Definition
agreement.php:2
Bitrix\Main
Bitrix
modules
main
lib
controller
phoneauth.php
Создано системой
1.10.0