-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclass.php
106 lines (81 loc) · 3.4 KB
/
class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<? if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) {
die();
}
use Bitrix\Main\Application;
use Bitrix\Main\Loader;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\SystemException;
class CCodeBlogChangePasswordComponent extends \CBitrixComponent
{
protected $requiredModules = [];
protected function isAjax() {
return isset($_REQUEST['ajax']) && $_REQUEST['ajax'] == 'y';
}
protected function checkModules() {
foreach ($this->requiredModules as $moduleName) {
if (!Loader::includeModule($moduleName)) {
throw new SystemException(Loc::getMessage('COMPONENT_CHANGE_NO_MODULE', ['#MODULE#',
$moduleName]));
}
}
return $this;
}
/**
* Event called from includeComponent before component execution.
* Takes component parameters as argument and should return it formatted as needed.
*
* @param array [string]mixed $arParams
*
* @return array[string]mixed
*/
public function onPrepareComponentParams($params) {
$request = Application::getInstance()->getContext()->getRequest();
$params['INPUT_DATA']['LOGIN'] = trim($request->getQuery('USER_LOGIN'));
$params['INPUT_DATA']['USER_CHECKWORD'] = trim($request->getQuery('USER_CHECKWORD'));
$params['INPUT_DATA']['USER_PASSWORD'] = trim($request->getQuery('USER_PASSWORD'));
$params['INPUT_DATA']['USER_CONFIRM_PASSWORD'] = trim($request->getQuery('USER_CONFIRM_PASSWORD'));
$params['INPUT_DATA']['CHANGE_PASSWORD_SUBMIT'] = trim($request->getQuery('CHANGE_PASSWORD_SUBMIT'));
return $params;
}
/**
* Event called from includeComponent before component execution.
* Includes component.php from within lang directory of the component.
*
* @return void
*/
public function onIncludeComponentLang() {
$this->includeComponentLang(basename(__FILE__));
Loc::loadMessages(__FILE__);
}
protected function prepareResult() {
if ($this->arParams['INPUT_DATA']['CHANGE_PASSWORD_SUBMIT'] == 'y') {
global $USER;
$this->arResult = $USER->ChangePassword($this->arParams['INPUT_DATA']['LOGIN'], $this->arParams['INPUT_DATA']['USER_CHECKWORD'], $this->arParams['INPUT_DATA']['USER_PASSWORD'], $this->arParams['INPUT_DATA']['USER_CONFIRM_PASSWORD']);
} else {
$this->arResult = ['MESSAGE' => '',
'TYPE' => 'EMPTY'];
}
return $this;
}
public function executeComponent() {
global $APPLICATION;
try {
$this->checkModules()->prepareResult();
if ($this->isAjax()) {
$APPLICATION->restartBuffer();
echo json_encode(['status' => 'ok',
'data' => $this->arResult], JSON_FORCE_OBJECT);
die();
}
$this->includeComponentTemplate();
} catch (SystemException $e) {
if ($this->isAjax()) {
$APPLICATION->restartBuffer();
echo json_encode(['status' => 'error',
'data' => $e->getMessage()], JSON_FORCE_OBJECT);
die();
}
self::__showError($e->getMessage());
}
}
}