Rev 1267 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1267 | Rev 1293 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
6 | * |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * you may not use this file except in compliance with the License. |
8 | * you may not use this file except in compliance with the License. |
9 | * You may obtain a copy of the License at |
9 | * You may obtain a copy of the License at |
10 | * |
10 | * |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | * |
12 | * |
13 | * Unless required by applicable law or agreed to in writing, software |
13 | * Unless required by applicable law or agreed to in writing, software |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | * See the License for the specific language governing permissions and |
16 | * See the License for the specific language governing permissions and |
17 | * limitations under the License. |
17 | * limitations under the License. |
18 | */ |
18 | */ |
19 | 19 | ||
20 | namespace ViaThinkSoft\OIDplus; |
20 | namespace ViaThinkSoft\OIDplus; |
21 | 21 | ||
22 | // phpcs:disable PSR1.Files.SideEffects |
22 | // phpcs:disable PSR1.Files.SideEffects |
23 | \defined('INSIDE_OIDPLUS') or die; |
23 | \defined('INSIDE_OIDPLUS') or die; |
24 | // phpcs:enable PSR1.Files.SideEffects |
24 | // phpcs:enable PSR1.Files.SideEffects |
25 | 25 | ||
26 | class OIDplusPageRaChangePassword extends OIDplusPagePluginRa { |
26 | class OIDplusPageRaChangePassword extends OIDplusPagePluginRa { |
27 | 27 | ||
28 | /** |
28 | /** |
29 | * @param string $actionID |
- | |
30 | * @param array $params |
29 | * @param array $params |
31 | * @return array |
30 | * @return array |
32 | * @throws OIDplusException |
31 | * @throws OIDplusException |
33 | */ |
32 | */ |
34 | public function action(string $actionID, array $params): array { |
33 | private function action_Update(array $params): array { |
35 | if ($actionID == 'change_ra_password') { |
- | |
36 | _CheckParamExists($params, 'email'); |
34 | _CheckParamExists($params, 'email'); |
37 | 35 | ||
38 | $email = $params['email']; |
36 | $email = $params['email']; |
39 | 37 | ||
40 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); |
38 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); |
41 | if (!$res->any()) { |
39 | if (!$res->any()) { |
42 | throw new OIDplusException(_L('RA does not exist')); |
40 | throw new OIDplusException(_L('RA does not exist')); |
43 | } |
41 | } |
44 | 42 | ||
45 | if (!OIDplus::authUtils()->isRaLoggedIn($email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
43 | if (!OIDplus::authUtils()->isRaLoggedIn($email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
46 | throw new OIDplusException(_L('Authentication error. Please log in as admin, or as the RA to update its data.'), null, 401); |
44 | throw new OIDplusException(_L('Authentication error. Please log in as admin, or as the RA to update its data.'), null, 401); |
47 | } |
45 | } |
48 | 46 | ||
49 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
47 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
50 | _CheckParamExists($params, 'old_password'); |
48 | _CheckParamExists($params, 'old_password'); |
51 | $old_password = $params['old_password']; |
49 | $old_password = $params['old_password']; |
52 | } else { |
50 | } else { |
53 | $old_password = ''; |
51 | $old_password = ''; |
54 | } |
52 | } |
55 | 53 | ||
56 | _CheckParamExists($params, 'new_password1'); |
54 | _CheckParamExists($params, 'new_password1'); |
57 | _CheckParamExists($params, 'new_password2'); |
55 | _CheckParamExists($params, 'new_password2'); |
58 | 56 | ||
59 | $password1 = $params['new_password1']; |
57 | $password1 = $params['new_password1']; |
60 | $password2 = $params['new_password2']; |
58 | $password2 = $params['new_password2']; |
61 | 59 | ||
62 | if ($password1 !== $password2) { |
60 | if ($password1 !== $password2) { |
63 | throw new OIDplusException(_L('Passwords do not match')); |
61 | throw new OIDplusException(_L('Passwords do not match')); |
64 | } |
62 | } |
65 | 63 | ||
66 | if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) { |
64 | if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) { |
67 | $minlen = OIDplus::config()->getValue('ra_min_password_length'); |
65 | $minlen = OIDplus::config()->getValue('ra_min_password_length'); |
68 | throw new OIDplusException(_L('New password is too short. Minimum password length: %1',$minlen)); |
66 | throw new OIDplusException(_L('New password is too short. Minimum password length: %1',$minlen)); |
69 | } |
67 | } |
70 | 68 | ||
71 | $ra = new OIDplusRA($email); |
69 | $ra = new OIDplusRA($email); |
72 | if (!$ra->isPasswordLess()) { |
70 | if (!$ra->isPasswordLess()) { |
73 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
71 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
74 | if (!$ra->checkPassword($old_password)) { |
72 | if (!$ra->checkPassword($old_password)) { |
75 | throw new OIDplusException(_L('Old password incorrect')); |
73 | throw new OIDplusException(_L('Old password incorrect')); |
76 | } |
74 | } |
77 | } |
75 | } |
78 | OIDplus::logger()->log("V2:[OK/WARN]RA(%1)+[OK/INFO]A", "Password of RA '%1' changed", $email); |
76 | OIDplus::logger()->log("V2:[OK/WARN]RA(%1)+[OK/INFO]A", "Password of RA '%1' changed", $email); |
79 | } else { |
77 | } else { |
80 | OIDplus::logger()->log("V2:[OK/WARN]RA(%1)+[OK/INFO]A", "Password of RA '%1' created", $email); |
78 | OIDplus::logger()->log("V2:[OK/WARN]RA(%1)+[OK/INFO]A", "Password of RA '%1' created", $email); |
81 | } |
79 | } |
82 | $ra->change_password($password1); |
80 | $ra->change_password($password1); |
83 | 81 | ||
84 | return array("status" => 0); |
82 | return array("status" => 0); |
- | 83 | } |
|
- | 84 | ||
- | 85 | /** |
|
- | 86 | * @param string $actionID |
|
- | 87 | * @param array $params |
|
- | 88 | * @return array |
|
- | 89 | * @throws OIDplusException |
|
- | 90 | */ |
|
- | 91 | public function action(string $actionID, array $params): array { |
|
- | 92 | if ($actionID == 'change_ra_password') { |
|
- | 93 | return $this->action_Update($params); |
|
85 | } else { |
94 | } else { |
86 | return parent::action($actionID, $params); |
95 | return parent::action($actionID, $params); |
87 | } |
96 | } |
88 | } |
97 | } |
89 | 98 | ||
90 | /** |
99 | /** |
91 | * @param bool $html |
100 | * @param bool $html |
92 | * @return void |
101 | * @return void |
93 | */ |
102 | */ |
94 | public function init(bool $html=true) { |
103 | public function init(bool $html=true) { |
95 | // Nothing |
104 | // Nothing |
96 | } |
105 | } |
97 | 106 | ||
98 | /** |
107 | /** |
99 | * @param string $id |
108 | * @param string $id |
100 | * @param array $out |
109 | * @param array $out |
101 | * @param bool $handled |
110 | * @param bool $handled |
102 | * @return void |
111 | * @return void |
103 | * @throws OIDplusException |
112 | * @throws OIDplusException |
104 | */ |
113 | */ |
105 | public function gui(string $id, array &$out, bool &$handled) { |
114 | public function gui(string $id, array &$out, bool &$handled) { |
106 | if (explode('$',$id)[0] == 'oidplus:change_ra_password') { |
115 | if (explode('$',$id)[0] == 'oidplus:change_ra_password') { |
107 | $handled = true; |
116 | $handled = true; |
108 | 117 | ||
109 | $ra_email = explode('$',$id)[1]; |
118 | $ra_email = explode('$',$id)[1]; |
110 | $ra = new OIDplusRA($ra_email); |
119 | $ra = new OIDplusRA($ra_email); |
111 | 120 | ||
112 | $out['title'] = $ra->isPasswordLess() ? _L('Create password') : _L('Change RA password'); |
121 | $out['title'] = $ra->isPasswordLess() ? _L('Create password') : _L('Change RA password'); |
113 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
122 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
114 | 123 | ||
115 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
124 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
116 | throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as the requested RA %2.',OIDplus::gui()->link('oidplus:login$ra$'.$ra_email),'<b>'.htmlentities($ra_email).'</b>'), $out['title'], 401); |
125 | throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as the requested RA %2.',OIDplus::gui()->link('oidplus:login$ra$'.$ra_email),'<b>'.htmlentities($ra_email).'</b>'), $out['title'], 401); |
117 | } |
126 | } |
118 | 127 | ||
119 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
128 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
120 | if (!$res->any()) { |
129 | if (!$res->any()) { |
121 | throw new OIDplusHtmlException(_L('RA "%1" does not exist','<b>'.htmlentities($ra_email).'</b>'), $out['title']); |
130 | throw new OIDplusHtmlException(_L('RA "%1" does not exist','<b>'.htmlentities($ra_email).'</b>'), $out['title']); |
122 | } |
131 | } |
123 | 132 | ||
124 | $out['text'] .= '<form id="raChangePasswordForm" action="javascript:void(0);" onsubmit="return OIDplusPageRaChangePassword.raChangePasswordFormOnSubmit();">'; |
133 | $out['text'] .= '<form id="raChangePasswordForm" action="javascript:void(0);" onsubmit="return OIDplusPageRaChangePassword.raChangePasswordFormOnSubmit();">'; |
125 | $out['text'] .= '<input type="hidden" id="email" value="'.htmlentities($ra_email).'"/><br>'; |
134 | $out['text'] .= '<input type="hidden" id="email" value="'.htmlentities($ra_email).'"/><br>'; |
126 | $out['text'] .= '<div><label class="padding_label">'._L('E-Mail').':</label><b>'.htmlentities($ra_email).'</b></div>'; |
135 | $out['text'] .= '<div><label class="padding_label">'._L('E-Mail').':</label><b>'.htmlentities($ra_email).'</b></div>'; |
127 | if (!$ra->isPasswordLess()) { |
136 | if (!$ra->isPasswordLess()) { |
128 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
137 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
129 | $out['text'] .= '<div><label class="padding_label">'._L('Old password').':</label><i>'._L('Admin can change the password without verification of the old password.').'</i></div>'; |
138 | $out['text'] .= '<div><label class="padding_label">'._L('Old password').':</label><i>'._L('Admin can change the password without verification of the old password.').'</i></div>'; |
130 | } else { |
139 | } else { |
131 | $out['text'] .= '<div><label class="padding_label">'._L('Old password').':</label><input type="password" id="old_password" value=""/></div>'; |
140 | $out['text'] .= '<div><label class="padding_label">'._L('Old password').':</label><input type="password" id="old_password" value=""/></div>'; |
132 | } |
141 | } |
133 | } |
142 | } |
134 | $out['text'] .= '<div><label class="padding_label">'._L('New password').':</label><input type="password" id="new_password1" value=""/></div>'; |
143 | $out['text'] .= '<div><label class="padding_label">'._L('New password').':</label><input type="password" id="new_password1" value=""/></div>'; |
135 | $out['text'] .= '<div><label class="padding_label">'._L('Repeat').':</label><input type="password" id="new_password2" value=""/></div>'; |
144 | $out['text'] .= '<div><label class="padding_label">'._L('Repeat').':</label><input type="password" id="new_password2" value=""/></div>'; |
136 | $out['text'] .= '<br><input type="submit" value="'.($ra->isPasswordLess() ? _L('Create password') : _L('Change password')).'"></form>'; |
145 | $out['text'] .= '<br><input type="submit" value="'.($ra->isPasswordLess() ? _L('Create password') : _L('Change password')).'"></form>'; |
137 | } |
146 | } |
138 | } |
147 | } |
139 | 148 | ||
140 | /** |
149 | /** |
141 | * @param array $json |
150 | * @param array $json |
142 | * @param string|null $ra_email |
151 | * @param string|null $ra_email |
143 | * @param bool $nonjs |
152 | * @param bool $nonjs |
144 | * @param string $req_goto |
153 | * @param string $req_goto |
145 | * @return bool |
154 | * @return bool |
146 | * @throws OIDplusException |
155 | * @throws OIDplusException |
147 | */ |
156 | */ |
148 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
157 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
149 | if (!$ra_email) return false; |
158 | if (!$ra_email) return false; |
150 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false; |
159 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false; |
151 | 160 | ||
152 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
161 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
153 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
162 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
154 | } else { |
163 | } else { |
155 | $tree_icon = null; // default icon (folder) |
164 | $tree_icon = null; // default icon (folder) |
156 | } |
165 | } |
157 | 166 | ||
158 | $ra = new OIDplusRA($ra_email); |
167 | $ra = new OIDplusRA($ra_email); |
159 | 168 | ||
160 | $json[] = array( |
169 | $json[] = array( |
161 | 'id' => 'oidplus:change_ra_password$'.$ra_email, |
170 | 'id' => 'oidplus:change_ra_password$'.$ra_email, |
162 | 'icon' => $tree_icon, |
171 | 'icon' => $tree_icon, |
163 | 'text' => $ra->isPasswordLess() ? _L('Create password') : _L('Change password') |
172 | 'text' => $ra->isPasswordLess() ? _L('Create password') : _L('Change password') |
164 | ); |
173 | ); |
165 | 174 | ||
166 | return true; |
175 | return true; |
167 | } |
176 | } |
168 | 177 | ||
169 | /** |
178 | /** |
170 | * @param string $request |
179 | * @param string $request |
171 | * @return array|false |
180 | * @return array|false |
172 | */ |
181 | */ |
173 | public function tree_search(string $request) { |
182 | public function tree_search(string $request) { |
174 | return false; |
183 | return false; |
175 | } |
184 | } |
176 | } |
185 | } |
177 | 186 |