Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
password.php
1
<?php
2
3
namespace
Bitrix\Rest\APAuth
;
4
5
use
Bitrix\Main
;
6
use
Bitrix\Main\Localization\Loc
;
7
use
Bitrix\Main\Security\Random
;
8
use
Bitrix\Rest\Preset\EventController
;
9
10
Loc::loadMessages
(__FILE__);
11
43
class
PasswordTable
extends
Main\Entity\DataManager
44
{
45
const
ACTIVE
=
'Y'
;
46
const
INACTIVE
=
'N'
;
47
48
const
DEFAULT_LENGTH
= 16;
49
55
public
static
function
getTableName
()
56
{
57
return
'b_rest_ap'
;
58
}
59
65
public
static
function
getMap
()
66
{
67
return
array(
68
'ID'
=> array(
69
'data_type'
=>
'integer'
,
70
'primary'
=>
true
,
71
'autocomplete'
=>
true
,
72
),
73
'USER_ID'
=> array(
74
'data_type'
=>
'integer'
,
75
'required'
=>
true
,
76
),
77
'PASSWORD'
=> array(
78
'data_type'
=>
'string'
,
79
'required'
=>
true
,
80
),
81
'ACTIVE'
=> array(
82
'data_type'
=>
'boolean'
,
83
'values'
=> array(static::INACTIVE, static::ACTIVE),
84
),
85
'TITLE'
=> array(
86
'data_type'
=>
'string'
,
87
),
88
'COMMENT'
=> array(
89
'data_type'
=>
'string'
,
90
),
91
'DATE_CREATE'
=> array(
92
'data_type'
=>
'datetime'
,
93
),
94
'DATE_LOGIN'
=> array(
95
'data_type'
=>
'datetime'
,
96
),
97
'LAST_IP'
=> array(
98
'data_type'
=>
'string'
,
99
),
100
);
101
}
102
103
public
static
function
generatePassword
($length = self::DEFAULT_LENGTH)
104
{
105
return
Random::getString($length);
106
}
107
108
117
public
static
function
createPassword
($userId, array $scopeList, $siteTitle, $returnArray =
false
)
118
{
119
$password = static::generatePassword();
120
$passwordData = [
121
'USER_ID'
=> $userId,
122
'PASSWORD'
=> $password,
123
'DATE_CREATE'
=>
new
Main\Type\DateTime
(),
124
'TITLE'
=>
Loc::getMessage
(
'REST_APP_SYSCOMMENT'
, array(
125
'#TITLE#'
=> $siteTitle,
126
)),
127
'COMMENT'
=>
Loc::getMessage
(
'REST_APP_COMMENT'
),
128
];
129
$res = static::add($passwordData);
130
131
if
($res->isSuccess())
132
{
133
$scopeList = array_unique($scopeList);
134
foreach
($scopeList as $scope)
135
{
136
PermissionTable::add(array(
137
'PASSWORD_ID'
=> $res->getId(),
138
'PERM'
=> $scope,
139
));
140
}
141
142
$passwordData[
'ID'
] = $res->getId();
143
if
(!$returnArray)
144
{
145
$return = $password;
146
}
147
else
148
{
149
$return = $passwordData;
150
}
151
152
return
$return;
153
}
154
155
return
false
;
156
}
157
158
public
static
function
onAfterAdd
(Main\
Entity
\
Event
$event)
159
{
160
EventController::onAfterAddAp($event);
161
}
162
}
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\Entity
Definition
entity.php:26
Bitrix\Main\Security\Random
Definition
random.php:6
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Rest\APAuth\PasswordTable
Definition
password.php:44
Bitrix\Rest\APAuth\PasswordTable\generatePassword
static generatePassword($length=self::DEFAULT_LENGTH)
Definition
password.php:103
Bitrix\Rest\APAuth\PasswordTable\getMap
static getMap()
Definition
password.php:65
Bitrix\Rest\APAuth\PasswordTable\createPassword
static createPassword($userId, array $scopeList, $siteTitle, $returnArray=false)
Definition
password.php:117
Bitrix\Rest\APAuth\PasswordTable\DEFAULT_LENGTH
const DEFAULT_LENGTH
Definition
password.php:48
Bitrix\Rest\APAuth\PasswordTable\ACTIVE
const ACTIVE
Definition
password.php:45
Bitrix\Rest\APAuth\PasswordTable\INACTIVE
const INACTIVE
Definition
password.php:46
Bitrix\Rest\APAuth\PasswordTable\onAfterAdd
static onAfterAdd(Main\Entity\Event $event)
Definition
password.php:158
Bitrix\Rest\APAuth\PasswordTable\getTableName
static getTableName()
Definition
password.php:55
Bitrix\Rest\Preset\EventController
Definition
eventcontroller.php:15
Bitrix\Main
Bitrix\Rest\APAuth
Definition
application.php:9
modules
rest
lib
apauth
password.php
Создано системой
1.10.0