1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
userphoneauth.php
См. документацию.
1<?php
8
9namespace Bitrix\Main;
10
11use Bitrix\Main\ORM\Query\Join;
12use Bitrix\Main\ORM\Data;
13use Bitrix\Main\ORM\Fields;
14use Bitrix\Main\Localization\Loc;
15
33{
34 public static function getTableName()
35 {
36 return 'b_user_phone_auth';
37 }
38
39 public static function getMap()
40 {
41 return array(
42 new Fields\IntegerField("USER_ID", array(
43 'primary' => true,
44 )),
45
46 new Fields\StringField("PHONE_NUMBER", array(
47 'validation' => function() {
48 return array(
49 new Fields\Validators\LengthValidator(1, null, ["MIN" => Loc::getMessage("user_phone_auth_err_number")]),
50 array(__CLASS__, 'validatePhoneNumber'),
51 new Fields\Validators\UniqueValidator(Loc::getMessage("user_phone_auth_err_duplicte")),
52 );
53 }
54 )),
55
56 new Fields\SecretField("OTP_SECRET", array(
57 'crypto_enabled' => static::cryptoEnabled("OTP_SECRET"),
58 )),
59
60 new Fields\IntegerField("ATTEMPTS", array(
61 "default_value" => 0,
62 )),
63
64 new Fields\BooleanField("CONFIRMED", array(
65 "values" => array("N", "Y"),
66 "default_value" => "N",
67 )),
68
69 new Fields\DatetimeField("DATE_SENT"),
70
72 'USER',
73 UserTable::class,
74 Join::on('this.USER_ID', 'ref.ID')
75 ))->configureJoinType('inner'),
76 );
77 }
78
83 public static function validatePhoneNumber($value)
84 {
85 $phoneNumber = PhoneNumber\Parser::getInstance()->parse($value);
86 if($phoneNumber->isValid())
87 {
88 return true;
89 }
90 else
91 {
92 return Loc::getMessage("user_phone_auth_err_incorrect_number");
93 }
94 }
95
96 public static function onBeforeAdd(ORM\Event $event)
97 {
98 return static::modifyFields($event);
99 }
100
101 public static function onBeforeUpdate(ORM\Event $event)
102 {
103 return static::modifyFields($event);
104 }
105
106 protected static function modifyFields(ORM\Event $event)
107 {
108 $fields = $event->getParameter('fields');
109 $result = new ORM\EventResult();
110 $modifiedFields = array();
111
112 if(isset($fields["PHONE_NUMBER"]))
113 {
114 //normalize the number
115 $modifiedFields["PHONE_NUMBER"] = static::normalizePhoneNumber($fields["PHONE_NUMBER"]);
116 }
117
118 $result->modifyFields($modifiedFields);
119
120 return $result;
121 }
122
123 public static function normalizePhoneNumber($number, $defaultCountry = '')
124 {
125 $phoneNumber = PhoneNumber\Parser::getInstance()->parse($number, $defaultCountry);
126 return $phoneNumber->format(PhoneNumber\Format::E164);
127 }
128}
Определения event.php:5
static getInstance()
Определения parser.php:78
static getMap()
Определения userphoneauth.php:39
static validatePhoneNumber($value)
Определения userphoneauth.php:83
static onBeforeAdd(ORM\Event $event)
Определения userphoneauth.php:96
static normalizePhoneNumber($number, $defaultCountry='')
Определения userphoneauth.php:123
static onBeforeUpdate(ORM\Event $event)
Определения userphoneauth.php:101
static getTableName()
Определения userphoneauth.php:34
static modifyFields(ORM\Event $event)
Определения userphoneauth.php:106
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$event
Определения prolog_after.php:141
$fields
Определения yandex_run.php:501