Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
password.php
1<?php
2
3namespace Bitrix\Rest\APAuth;
4
9
10Loc::loadMessages(__FILE__);
11
43class 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}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static generatePassword($length=self::DEFAULT_LENGTH)
Definition password.php:103
static createPassword($userId, array $scopeList, $siteTitle, $returnArray=false)
Definition password.php:117
static onAfterAdd(Main\Entity\Event $event)
Definition password.php:158