Rev 1283 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1283 | 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 OIDplusPageRaChangeEMail extends OIDplusPagePluginRa { |
26 | class OIDplusPageRaChangeEMail 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 | * @throws OIDplusMailException |
32 | * @throws OIDplusMailException |
34 | */ |
33 | */ |
35 | public function action(string $actionID, array $params): array { |
34 | private function action_Request(array $params): array { |
36 | if ($actionID == 'change_ra_email') { |
- | |
37 | if (!OIDplus::config()->getValue('allow_ra_email_change') && !OIDplus::authUtils()->isAdminLoggedIn()) { |
35 | if (!OIDplus::config()->getValue('allow_ra_email_change') && !OIDplus::authUtils()->isAdminLoggedIn()) { |
38 | throw new OIDplusException(_L('This functionality has been disabled by the administrator.')); |
36 | throw new OIDplusException(_L('This functionality has been disabled by the administrator.')); |
39 | } |
37 | } |
40 | 38 | ||
41 | _CheckParamExists($params, 'old_email'); |
39 | _CheckParamExists($params, 'old_email'); |
42 | _CheckParamExists($params, 'new_email'); |
40 | _CheckParamExists($params, 'new_email'); |
43 | 41 | ||
44 | $old_email = $params['old_email']; |
42 | $old_email = $params['old_email']; |
45 | $new_email = $params['new_email']; |
43 | $new_email = $params['new_email']; |
46 | 44 | ||
47 | $ra = new OIDplusRA($old_email); |
45 | $ra = new OIDplusRA($old_email); |
48 | if ($ra->isPasswordLess() && !OIDplus::authUtils()->isAdminLoggedIn()) { |
46 | if ($ra->isPasswordLess() && !OIDplus::authUtils()->isAdminLoggedIn()) { |
49 | throw new OIDplusException(_L('E-Mail-Address cannot be changed because this user does not have a password')); |
47 | throw new OIDplusException(_L('E-Mail-Address cannot be changed because this user does not have a password')); |
50 | } |
48 | } |
51 | 49 | ||
52 | if (!OIDplus::authUtils()->isRaLoggedIn($old_email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
50 | if (!OIDplus::authUtils()->isRaLoggedIn($old_email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
53 | throw new OIDplusException(_L('Authentication error. Please log in as admin, or as the RA to update its email address.'), null, 401); |
51 | throw new OIDplusException(_L('Authentication error. Please log in as admin, or as the RA to update its email address.'), null, 401); |
54 | } |
52 | } |
55 | 53 | ||
56 | if (!OIDplus::mailUtils()->validMailAddress($new_email)) { |
54 | if (!OIDplus::mailUtils()->validMailAddress($new_email)) { |
57 | throw new OIDplusException(_L('eMail address is invalid.')); |
55 | throw new OIDplusException(_L('eMail address is invalid.')); |
58 | } |
56 | } |
59 | 57 | ||
60 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($old_email)); |
58 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($old_email)); |
61 | if (!$res->any()) { |
59 | if (!$res->any()) { |
62 | throw new OIDplusException(_L('eMail address does not exist anymore. It was probably already changed.')); |
60 | throw new OIDplusException(_L('eMail address does not exist anymore. It was probably already changed.')); |
63 | } |
61 | } |
64 | 62 | ||
65 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($new_email)); |
63 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($new_email)); |
66 | if ($res->any()) { |
64 | if ($res->any()) { |
67 | throw new OIDplusException(_L('eMail address is already used by another RA. To merge accounts, please contact the superior RA of your objects and request an owner change of your objects.')); |
65 | throw new OIDplusException(_L('eMail address is already used by another RA. To merge accounts, please contact the superior RA of your objects and request an owner change of your objects.')); |
68 | } |
66 | } |
69 | 67 | ||
70 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
68 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
71 | $ra_was_logged_in = OIDplus::authUtils()->isRaLoggedIn($old_email); |
69 | $ra_was_logged_in = OIDplus::authUtils()->isRaLoggedIn($old_email); |
72 | 70 | ||
73 | $ra = new OIDplusRA($old_email); |
71 | $ra = new OIDplusRA($old_email); |
74 | 72 | ||
75 | // Change RA email |
73 | // Change RA email |
76 | $ra->change_email($new_email); |
74 | $ra->change_email($new_email); |
77 | OIDplus::logger()->log("V2:[WARN]RA(%1)+[INFO]RA(%2)+[OK]A", "Admin changed email address '%1' to '%2'", $old_email, $new_email); |
75 | OIDplus::logger()->log("V2:[WARN]RA(%1)+[INFO]RA(%2)+[OK]A", "Admin changed email address '%1' to '%2'", $old_email, $new_email); |
78 | 76 | ||
79 | // Change objects |
77 | // Change objects |
80 | $res = OIDplus::db()->query("select id from ###objects where ra_email = ?", array($old_email)); |
78 | $res = OIDplus::db()->query("select id from ###objects where ra_email = ?", array($old_email)); |
81 | while ($row = $res->fetch_array()) { |
79 | while ($row = $res->fetch_array()) { |
82 | OIDplus::logger()->log("V2:[INFO]OID(%1)+SUPOID(%1)", "Admin changed email address of RA '%2' (owner of %1) to '%3'", $row['id'], $old_email, $new_email); |
80 | OIDplus::logger()->log("V2:[INFO]OID(%1)+SUPOID(%1)", "Admin changed email address of RA '%2' (owner of %1) to '%3'", $row['id'], $old_email, $new_email); |
83 | } |
81 | } |
84 | OIDplus::db()->query("update ###objects set ra_email = ? where ra_email = ?", array($new_email, $old_email)); |
82 | OIDplus::db()->query("update ###objects set ra_email = ? where ra_email = ?", array($new_email, $old_email)); |
85 | OIDplusObject::resetObjectInformationCache(); |
83 | OIDplusObject::resetObjectInformationCache(); |
86 | 84 | ||
87 | // Re-login |
85 | // Re-login |
88 | if ($ra_was_logged_in) { |
86 | if ($ra_was_logged_in) { |
89 | OIDplus::authUtils()->raLogout($old_email); |
87 | OIDplus::authUtils()->raLogout($old_email); |
90 | OIDplus::authUtils()->raLogin($new_email); |
88 | OIDplus::authUtils()->raLogin($new_email); |
91 | } |
89 | } |
92 | 90 | ||
93 | return array("status" => 0); |
91 | return array("status" => 0); |
94 | } else { |
92 | } else { |
95 | OIDplus::logger()->log("V2:[INFO]RA(%1)+RA(%2)", "Requested email address change from '%1' to '%2'", $old_email, $new_email); |
93 | OIDplus::logger()->log("V2:[INFO]RA(%1)+RA(%2)", "Requested email address change from '%1' to '%2'", $old_email, $new_email); |
96 | 94 | ||
97 | $activate_url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL) . '?goto='.urlencode('oidplus:activate_new_ra_email$'.$old_email.'$'.$new_email.'$'.OIDplus::authUtils()->makeAuthKey(['5ef24124-f4fb-11ed-b67e-3c4a92df8582',$old_email,$new_email])); |
95 | $activate_url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL) . '?goto='.urlencode('oidplus:activate_new_ra_email$'.$old_email.'$'.$new_email.'$'.OIDplus::authUtils()->makeAuthKey(['5ef24124-f4fb-11ed-b67e-3c4a92df8582',$old_email,$new_email])); |
98 | 96 | ||
99 | $message = file_get_contents(__DIR__ . '/change_request_email.tpl'); |
97 | $message = file_get_contents(__DIR__ . '/change_request_email.tpl'); |
100 | $message = str_replace('{{SYSTEM_URL}}', OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL), $message); |
98 | $message = str_replace('{{SYSTEM_URL}}', OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL), $message); |
101 | $message = str_replace('{{SYSTEM_TITLE}}', OIDplus::config()->getValue('system_title'), $message); |
99 | $message = str_replace('{{SYSTEM_TITLE}}', OIDplus::config()->getValue('system_title'), $message); |
102 | $message = str_replace('{{ADMIN_EMAIL}}', OIDplus::config()->getValue('admin_email'), $message); |
100 | $message = str_replace('{{ADMIN_EMAIL}}', OIDplus::config()->getValue('admin_email'), $message); |
103 | $message = str_replace('{{OLD_EMAIL}}', $old_email, $message); |
101 | $message = str_replace('{{OLD_EMAIL}}', $old_email, $message); |
104 | $message = str_replace('{{NEW_EMAIL}}', $new_email, $message); |
102 | $message = str_replace('{{NEW_EMAIL}}', $new_email, $message); |
105 | $message = str_replace('{{ACTIVATE_URL}}', $activate_url, $message); |
103 | $message = str_replace('{{ACTIVATE_URL}}', $activate_url, $message); |
106 | OIDplus::mailUtils()->sendMail($new_email, OIDplus::config()->getValue('system_title').' - Change email request', $message); |
104 | OIDplus::mailUtils()->sendMail($new_email, OIDplus::config()->getValue('system_title').' - Change email request', $message); |
107 | 105 | ||
108 | return array("status" => 0); |
106 | return array("status" => 0); |
109 | } |
107 | } |
110 | } |
108 | } |
111 | 109 | ||
- | 110 | /** |
|
- | 111 | * @param array $params |
|
- | 112 | * @return array |
|
- | 113 | * @throws OIDplusException |
|
- | 114 | * @throws OIDplusMailException |
|
- | 115 | */ |
|
112 | else if ($actionID == 'activate_new_ra_email') { |
116 | private function action_Activate(array $params): array { |
113 | if (!OIDplus::config()->getValue('allow_ra_email_change')) { |
117 | if (!OIDplus::config()->getValue('allow_ra_email_change')) { |
114 | throw new OIDplusException(_L('This functionality has been disabled by the administrator.')); |
118 | throw new OIDplusException(_L('This functionality has been disabled by the administrator.')); |
115 | } |
119 | } |
116 | 120 | ||
117 | _CheckParamExists($params, 'old_email'); |
121 | _CheckParamExists($params, 'old_email'); |
118 | _CheckParamExists($params, 'new_email'); |
122 | _CheckParamExists($params, 'new_email'); |
119 | _CheckParamExists($params, 'password'); |
123 | _CheckParamExists($params, 'password'); |
120 | _CheckParamExists($params, 'auth'); |
124 | _CheckParamExists($params, 'auth'); |
121 | 125 | ||
122 | $old_email = $params['old_email']; |
126 | $old_email = $params['old_email']; |
123 | $new_email = $params['new_email']; |
127 | $new_email = $params['new_email']; |
124 | $password = $params['password']; |
128 | $password = $params['password']; |
125 | 129 | ||
126 | $auth = $params['auth']; |
130 | $auth = $params['auth']; |
127 | 131 | ||
128 | $ra_was_logged_in = OIDplus::authUtils()->isRaLoggedIn($old_email); |
132 | $ra_was_logged_in = OIDplus::authUtils()->isRaLoggedIn($old_email); |
129 | 133 | ||
130 | $ra = new OIDplusRA($old_email); |
134 | $ra = new OIDplusRA($old_email); |
131 | if ($ra->isPasswordLess() && !OIDplus::authUtils()->isAdminLoggedIn()) { |
135 | if ($ra->isPasswordLess() && !OIDplus::authUtils()->isAdminLoggedIn()) { |
132 | throw new OIDplusException(_L('E-Mail-Address cannot be changed because this user does not have a password')); |
136 | throw new OIDplusException(_L('E-Mail-Address cannot be changed because this user does not have a password')); |
133 | } |
137 | } |
134 | 138 | ||
135 | if (!OIDplus::authUtils()->validateAuthKey(['5ef24124-f4fb-11ed-b67e-3c4a92df8582',$old_email,$new_email], $auth, OIDplus::config()->getValue('max_ra_email_change_time', -1))) { |
139 | if (!OIDplus::authUtils()->validateAuthKey(['5ef24124-f4fb-11ed-b67e-3c4a92df8582',$old_email,$new_email], $auth, OIDplus::config()->getValue('max_ra_email_change_time', -1))) { |
136 | throw new OIDplusException(_L('Invalid or expired authentication key')); |
140 | throw new OIDplusException(_L('Invalid or expired authentication key')); |
137 | } |
141 | } |
138 | 142 | ||
139 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($old_email)); |
143 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($old_email)); |
140 | if (!$res->any()) { |
144 | if (!$res->any()) { |
141 | throw new OIDplusException(_L('eMail address does not exist anymore. It was probably already changed.')); |
145 | throw new OIDplusException(_L('eMail address does not exist anymore. It was probably already changed.')); |
142 | } |
146 | } |
143 | 147 | ||
144 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($new_email)); |
148 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($new_email)); |
145 | if ($res->any()) { |
149 | if ($res->any()) { |
146 | throw new OIDplusException(_L('eMail address is already used by another RA. To merge accounts, please contact the superior RA of your objects and request an owner change of your objects.')); |
150 | throw new OIDplusException(_L('eMail address is already used by another RA. To merge accounts, please contact the superior RA of your objects and request an owner change of your objects.')); |
147 | } |
151 | } |
148 | 152 | ||
149 | $ra = new OIDplusRA($old_email); |
153 | $ra = new OIDplusRA($old_email); |
150 | if (!$ra->isPasswordLess()) { |
154 | if (!$ra->isPasswordLess()) { |
151 | if (!$ra->checkPassword($password)) { |
155 | if (!$ra->checkPassword($password)) { |
152 | throw new OIDplusException(_L('Wrong password')); |
156 | throw new OIDplusException(_L('Wrong password')); |
153 | } |
157 | } |
154 | } |
158 | } |
155 | 159 | ||
156 | // Change address of RA |
160 | // Change address of RA |
157 | $ra->change_email($new_email); |
161 | $ra->change_email($new_email); |
158 | OIDplus::logger()->log("V2:[OK]RA(%2)+RA(%1)", "RA '%1' has changed their email address to '%2'", $old_email, $new_email); |
162 | OIDplus::logger()->log("V2:[OK]RA(%2)+RA(%1)", "RA '%1' has changed their email address to '%2'", $old_email, $new_email); |
159 | 163 | ||
160 | // Change objects |
164 | // Change objects |
161 | $res = OIDplus::db()->query("select id from ###objects where ra_email = ?", array($old_email)); |
165 | $res = OIDplus::db()->query("select id from ###objects where ra_email = ?", array($old_email)); |
162 | while ($row = $res->fetch_array()) { |
166 | while ($row = $res->fetch_array()) { |
163 | OIDplus::logger()->log("V2:[INFO]OID(%1)+SUPOID(%1)", "RA '%2' (owner of %1) has changed their email address to '%3'", $row['id'], $old_email, $new_email); |
167 | OIDplus::logger()->log("V2:[INFO]OID(%1)+SUPOID(%1)", "RA '%2' (owner of %1) has changed their email address to '%3'", $row['id'], $old_email, $new_email); |
164 | } |
168 | } |
165 | OIDplus::db()->query("update ###objects set ra_email = ? where ra_email = ?", array($new_email, $old_email)); |
169 | OIDplus::db()->query("update ###objects set ra_email = ? where ra_email = ?", array($new_email, $old_email)); |
166 | OIDplusObject::resetObjectInformationCache(); |
170 | OIDplusObject::resetObjectInformationCache(); |
167 | 171 | ||
168 | // Re-login |
172 | // Re-login |
169 | if ($ra_was_logged_in) { |
173 | if ($ra_was_logged_in) { |
170 | OIDplus::authUtils()->raLogout($old_email); |
174 | OIDplus::authUtils()->raLogout($old_email); |
171 | OIDplus::authUtils()->raLogin($new_email); |
175 | OIDplus::authUtils()->raLogin($new_email); |
172 | } |
176 | } |
173 | 177 | ||
174 | // Send email |
178 | // Send email |
175 | $message = file_get_contents(__DIR__ . '/email_change_confirmation.tpl'); |
179 | $message = file_get_contents(__DIR__ . '/email_change_confirmation.tpl'); |
176 | $message = str_replace('{{SYSTEM_URL}}', OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL), $message); |
180 | $message = str_replace('{{SYSTEM_URL}}', OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL), $message); |
177 | $message = str_replace('{{SYSTEM_TITLE}}', OIDplus::config()->getValue('system_title'), $message); |
181 | $message = str_replace('{{SYSTEM_TITLE}}', OIDplus::config()->getValue('system_title'), $message); |
178 | $message = str_replace('{{ADMIN_EMAIL}}', OIDplus::config()->getValue('admin_email'), $message); |
182 | $message = str_replace('{{ADMIN_EMAIL}}', OIDplus::config()->getValue('admin_email'), $message); |
179 | $message = str_replace('{{OLD_EMAIL}}', $old_email, $message); |
183 | $message = str_replace('{{OLD_EMAIL}}', $old_email, $message); |
180 | $message = str_replace('{{NEW_EMAIL}}', $new_email, $message); |
184 | $message = str_replace('{{NEW_EMAIL}}', $new_email, $message); |
181 | OIDplus::mailUtils()->sendMail($old_email, OIDplus::config()->getValue('system_title').' - eMail address changed', $message); |
185 | OIDplus::mailUtils()->sendMail($old_email, OIDplus::config()->getValue('system_title').' - eMail address changed', $message); |
182 | 186 | ||
183 | return array("status" => 0); |
187 | return array("status" => 0); |
- | 188 | } |
|
- | 189 | ||
- | 190 | /** |
|
- | 191 | * @param string $actionID |
|
- | 192 | * @param array $params |
|
- | 193 | * @return array |
|
- | 194 | * @throws OIDplusException |
|
- | 195 | * @throws OIDplusMailException |
|
- | 196 | */ |
|
- | 197 | public function action(string $actionID, array $params): array { |
|
- | 198 | if ($actionID == 'change_ra_email') { |
|
- | 199 | return $this->action_Request($params); |
|
- | 200 | } else if ($actionID == 'activate_new_ra_email') { |
|
- | 201 | return $this->action_Activate($params); |
|
184 | } else { |
202 | } else { |
185 | return parent::action($actionID, $params); |
203 | return parent::action($actionID, $params); |
186 | } |
204 | } |
187 | } |
205 | } |
188 | 206 | ||
189 | /** |
207 | /** |
190 | * @param bool $html |
208 | * @param bool $html |
191 | * @return void |
209 | * @return void |
192 | * @throws OIDplusException |
210 | * @throws OIDplusException |
193 | */ |
211 | */ |
194 | public function init(bool $html=true) { |
212 | public function init(bool $html=true) { |
195 | OIDplus::config()->prepareConfigKey('max_ra_email_change_time', 'Max RA email change time in seconds (0 = infinite)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
213 | OIDplus::config()->prepareConfigKey('max_ra_email_change_time', 'Max RA email change time in seconds (0 = infinite)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
196 | if (!is_numeric($value) || ($value < 0)) { |
214 | if (!is_numeric($value) || ($value < 0)) { |
197 | throw new OIDplusException(_L('Please enter a valid value.')); |
215 | throw new OIDplusException(_L('Please enter a valid value.')); |
198 | } |
216 | } |
199 | }); |
217 | }); |
200 | OIDplus::config()->prepareConfigKey('allow_ra_email_change', 'Allow that RAs change their email address (0/1)', '1', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
218 | OIDplus::config()->prepareConfigKey('allow_ra_email_change', 'Allow that RAs change their email address (0/1)', '1', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
201 | if (($value != '0') && ($value != '1')) { |
219 | if (($value != '0') && ($value != '1')) { |
202 | throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).')); |
220 | throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).')); |
203 | } |
221 | } |
204 | }); |
222 | }); |
205 | } |
223 | } |
206 | 224 | ||
207 | /** |
225 | /** |
208 | * @param string $id |
226 | * @param string $id |
209 | * @param array $out |
227 | * @param array $out |
210 | * @param bool $handled |
228 | * @param bool $handled |
211 | * @return void |
229 | * @return void |
212 | * @throws OIDplusException |
230 | * @throws OIDplusException |
213 | */ |
231 | */ |
214 | public function gui(string $id, array &$out, bool &$handled) { |
232 | public function gui(string $id, array &$out, bool &$handled) { |
215 | if (explode('$',$id)[0] == 'oidplus:change_ra_email') { |
233 | if (explode('$',$id)[0] == 'oidplus:change_ra_email') { |
216 | $handled = true; |
234 | $handled = true; |
217 | 235 | ||
218 | $ra_email = explode('$',$id)[1]; |
236 | $ra_email = explode('$',$id)[1]; |
219 | 237 | ||
220 | $out['title'] = _L('Change RA email'); |
238 | $out['title'] = _L('Change RA email'); |
221 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
239 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
222 | 240 | ||
223 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
241 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
224 | throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as the requested RA %2 or as admin.',OIDplus::gui()->link('oidplus:login$ra$'.$ra_email),'<b>'.htmlentities($ra_email).'</b>'), $out['title'], 401); |
242 | throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as the requested RA %2 or as admin.',OIDplus::gui()->link('oidplus:login$ra$'.$ra_email),'<b>'.htmlentities($ra_email).'</b>'), $out['title'], 401); |
225 | } |
243 | } |
226 | 244 | ||
227 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
245 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
228 | if (!$res->any()) { |
246 | if (!$res->any()) { |
229 | throw new OIDplusHtmlException(_L('RA "%1" does not exist','<b>'.htmlentities($ra_email).'</b>'), $out['title']); |
247 | throw new OIDplusHtmlException(_L('RA "%1" does not exist','<b>'.htmlentities($ra_email).'</b>'), $out['title']); |
230 | } |
248 | } |
231 | 249 | ||
232 | if (!OIDplus::config()->getValue('allow_ra_email_change') && !OIDplus::authUtils()->isAdminLoggedIn()) { |
250 | if (!OIDplus::config()->getValue('allow_ra_email_change') && !OIDplus::authUtils()->isAdminLoggedIn()) { |
233 | throw new OIDplusException(_L('This functionality has been disabled by the administrator.'), $out['title']); |
251 | throw new OIDplusException(_L('This functionality has been disabled by the administrator.'), $out['title']); |
234 | } |
252 | } |
235 | 253 | ||
236 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
254 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
237 | $ra = new OIDplusRA($ra_email); |
255 | $ra = new OIDplusRA($ra_email); |
238 | if ($ra->isPasswordLess()) { |
256 | if ($ra->isPasswordLess()) { |
239 | $out['text'] .= '<p>'._L('Attention: This user does not have a password because they log in using LDAP or Google OAuth etc.').'</p>'; |
257 | $out['text'] .= '<p>'._L('Attention: This user does not have a password because they log in using LDAP or Google OAuth etc.').'</p>'; |
240 | $out['text'] .= '<p>'._L('If you change the email address, the user cannot log in anymore, because the LDAP/OAuth plugin identifies the user via email address, not OpenID.').'</p>'; |
258 | $out['text'] .= '<p>'._L('If you change the email address, the user cannot log in anymore, because the LDAP/OAuth plugin identifies the user via email address, not OpenID.').'</p>'; |
241 | $out['text'] .= '<p>'._L('If you want to change the email address of the user, please <a %1>define a password</a> for them, so that they can use the regular login method using their new email address.', OIDplus::gui()->link('oidplus:change_ra_password$'.$ra_email)).'</p>'; |
259 | $out['text'] .= '<p>'._L('If you want to change the email address of the user, please <a %1>define a password</a> for them, so that they can use the regular login method using their new email address.', OIDplus::gui()->link('oidplus:change_ra_password$'.$ra_email)).'</p>'; |
242 | } |
260 | } |
243 | 261 | ||
244 | $out['text'] .= '<form id="changeRaEmailForm" action="javascript:void(0);" action="javascript:void(0);" onsubmit="return OIDplusPageRaChangeEMail.changeRaEmailFormOnSubmit(true);">'; |
262 | $out['text'] .= '<form id="changeRaEmailForm" action="javascript:void(0);" action="javascript:void(0);" onsubmit="return OIDplusPageRaChangeEMail.changeRaEmailFormOnSubmit(true);">'; |
245 | $out['text'] .= '<input type="hidden" id="old_email" value="'.htmlentities($ra_email).'"/><br>'; |
263 | $out['text'] .= '<input type="hidden" id="old_email" value="'.htmlentities($ra_email).'"/><br>'; |
246 | $out['text'] .= '<div><label class="padding_label">'._L('Old address').':</label><b>'.htmlentities($ra_email).'</b></div>'; |
264 | $out['text'] .= '<div><label class="padding_label">'._L('Old address').':</label><b>'.htmlentities($ra_email).'</b></div>'; |
247 | $out['text'] .= '<div><label class="padding_label">'._L('New address').':</label><input type="text" id="new_email" value=""/></div>'; |
265 | $out['text'] .= '<div><label class="padding_label">'._L('New address').':</label><input type="text" id="new_email" value=""/></div>'; |
248 | $out['text'] .= '<br><input type="submit" value="'._L('Change password').'"> '._L('(admin does not require email verification)').'</form>'; |
266 | $out['text'] .= '<br><input type="submit" value="'._L('Change password').'"> '._L('(admin does not require email verification)').'</form>'; |
249 | } else { |
267 | } else { |
250 | $ra = new OIDplusRA($ra_email); |
268 | $ra = new OIDplusRA($ra_email); |
251 | if ($ra->isPasswordLess()) { |
269 | if ($ra->isPasswordLess()) { |
252 | $out['icon'] = 'img/error.png'; |
270 | $out['icon'] = 'img/error.png'; |
253 | $out['text'] .= '<p>'._L('Attention: You are logged in without password (via LDAP or Google OAuth etc.).').'</p>'; |
271 | $out['text'] .= '<p>'._L('Attention: You are logged in without password (via LDAP or Google OAuth etc.).').'</p>'; |
254 | $out['text'] .= '<p>'._L('Therefore, you cannot change your email address, otherwise you would lose access to your account!').'</p>'; |
272 | $out['text'] .= '<p>'._L('Therefore, you cannot change your email address, otherwise you would lose access to your account!').'</p>'; |
255 | $out['text'] .= '<p>'._L('If you want to change your email address, then please <a %1>setup a password</a> first, and then use the regular login method to log in using your new email address.', OIDplus::gui()->link('oidplus:change_ra_password$'.$ra_email)).'</p>'; |
273 | $out['text'] .= '<p>'._L('If you want to change your email address, then please <a %1>setup a password</a> first, and then use the regular login method to log in using your new email address.', OIDplus::gui()->link('oidplus:change_ra_password$'.$ra_email)).'</p>'; |
256 | return; // throw new OIDplusHtmlException($out['text'], $out['title']); |
274 | return; // throw new OIDplusHtmlException($out['text'], $out['title']); |
257 | } |
275 | } |
258 | 276 | ||
259 | $out['text'] .= '<form id="changeRaEmailForm" action="javascript:void(0);" action="javascript:void(0);" onsubmit="return OIDplusPageRaChangeEMail.changeRaEmailFormOnSubmit(false);">'; |
277 | $out['text'] .= '<form id="changeRaEmailForm" action="javascript:void(0);" action="javascript:void(0);" onsubmit="return OIDplusPageRaChangeEMail.changeRaEmailFormOnSubmit(false);">'; |
260 | $out['text'] .= '<input type="hidden" id="old_email" value="'.htmlentities($ra_email).'"/><br>'; |
278 | $out['text'] .= '<input type="hidden" id="old_email" value="'.htmlentities($ra_email).'"/><br>'; |
261 | $out['text'] .= '<div><label class="padding_label">'._L('Old address').':</label><b>'.htmlentities($ra_email).'</b></div>'; |
279 | $out['text'] .= '<div><label class="padding_label">'._L('Old address').':</label><b>'.htmlentities($ra_email).'</b></div>'; |
262 | $out['text'] .= '<div><label class="padding_label">'._L('New address').':</label><input type="text" id="new_email" value=""/></div>'; |
280 | $out['text'] .= '<div><label class="padding_label">'._L('New address').':</label><input type="text" id="new_email" value=""/></div>'; |
263 | $out['text'] .= '<br><input type="submit" value="'._L('Send new activation email').'"></form>'; |
281 | $out['text'] .= '<br><input type="submit" value="'._L('Send new activation email').'"></form>'; |
264 | } |
282 | } |
265 | } else if (explode('$',$id)[0] == 'oidplus:activate_new_ra_email') { |
283 | } else if (explode('$',$id)[0] == 'oidplus:activate_new_ra_email') { |
266 | $handled = true; |
284 | $handled = true; |
267 | 285 | ||
268 | $old_email = explode('$',$id)[1]; |
286 | $old_email = explode('$',$id)[1]; |
269 | $new_email = explode('$',$id)[2]; |
287 | $new_email = explode('$',$id)[2]; |
270 | $auth = explode('$',$id)[3]; |
288 | $auth = explode('$',$id)[3]; |
271 | 289 | ||
272 | $out['title'] = _L('Perform email address change'); |
290 | $out['title'] = _L('Perform email address change'); |
273 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
291 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
274 | 292 | ||
275 | if (!OIDplus::config()->getValue('allow_ra_email_change') && !OIDplus::authUtils()->isAdminLoggedIn()) { |
293 | if (!OIDplus::config()->getValue('allow_ra_email_change') && !OIDplus::authUtils()->isAdminLoggedIn()) { |
276 | throw new OIDplusException(_L('This functionality has been disabled by the administrator.'), $out['title']); |
294 | throw new OIDplusException(_L('This functionality has been disabled by the administrator.'), $out['title']); |
277 | } |
295 | } |
278 | 296 | ||
279 | $ra = new OIDplusRA($old_email); |
297 | $ra = new OIDplusRA($old_email); |
280 | if ($ra->isPasswordLess() && !OIDplus::authUtils()->isAdminLoggedIn()) { |
298 | if ($ra->isPasswordLess() && !OIDplus::authUtils()->isAdminLoggedIn()) { |
281 | throw new OIDplusException(_L('E-Mail-Address cannot be changed because this user does not have a password'), $out['title']); |
299 | throw new OIDplusException(_L('E-Mail-Address cannot be changed because this user does not have a password'), $out['title']); |
282 | } |
300 | } |
283 | 301 | ||
284 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($old_email)); |
302 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($old_email)); |
285 | if (!$res->any()) { |
303 | if (!$res->any()) { |
286 | throw new OIDplusException(_L('eMail address does not exist anymore. It was probably already changed.'), $out['title']); |
304 | throw new OIDplusException(_L('eMail address does not exist anymore. It was probably already changed.'), $out['title']); |
287 | } else { |
305 | } else { |
288 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($new_email)); |
306 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($new_email)); |
289 | if ($res->any()) { |
307 | if ($res->any()) { |
290 | throw new OIDplusException(_L('eMail address is already used by another RA. To merge accounts, please contact the superior RA of your objects and request an owner change of your objects.'), $out['title']); |
308 | throw new OIDplusException(_L('eMail address is already used by another RA. To merge accounts, please contact the superior RA of your objects and request an owner change of your objects.'), $out['title']); |
291 | } else { |
309 | } else { |
292 | if (!OIDplus::authUtils()->validateAuthKey(['5ef24124-f4fb-11ed-b67e-3c4a92df8582',$old_email,$new_email], $auth, OIDplus::config()->getValue('max_ra_email_change_time', -1))) { |
310 | if (!OIDplus::authUtils()->validateAuthKey(['5ef24124-f4fb-11ed-b67e-3c4a92df8582',$old_email,$new_email], $auth, OIDplus::config()->getValue('max_ra_email_change_time', -1))) { |
293 | throw new OIDplusException(_L('Invalid authorization. Is the URL OK?'), $out['title']); |
311 | throw new OIDplusException(_L('Invalid authorization. Is the URL OK?'), $out['title']); |
294 | } else { |
312 | } else { |
295 | $out['text'] = '<p>'._L('Old eMail-Address').': <b>'.$old_email.'</b></p> |
313 | $out['text'] = '<p>'._L('Old eMail-Address').': <b>'.$old_email.'</b></p> |
296 | <p>'._L('New eMail-Address').': <b>'.$new_email.'</b></p> |
314 | <p>'._L('New eMail-Address').': <b>'.$new_email.'</b></p> |
297 | 315 | ||
298 | <form id="activateNewRaEmailForm" action="javascript:void(0);" onsubmit="return OIDplusPageRaChangeEMail.activateNewRaEmailFormOnSubmit();"> |
316 | <form id="activateNewRaEmailForm" action="javascript:void(0);" onsubmit="return OIDplusPageRaChangeEMail.activateNewRaEmailFormOnSubmit();"> |
299 | <input type="hidden" id="old_email" value="'.htmlentities($old_email).'"/> |
317 | <input type="hidden" id="old_email" value="'.htmlentities($old_email).'"/> |
300 | <input type="hidden" id="new_email" value="'.htmlentities($new_email).'"/> |
318 | <input type="hidden" id="new_email" value="'.htmlentities($new_email).'"/> |
301 | <input type="hidden" id="auth" value="'.htmlentities($auth).'"/> |
319 | <input type="hidden" id="auth" value="'.htmlentities($auth).'"/> |
302 | 320 | ||
303 | <div><label class="padding_label">'._L('Please verify your password').':</label><input type="password" id="password" value=""/></div> |
321 | <div><label class="padding_label">'._L('Please verify your password').':</label><input type="password" id="password" value=""/></div> |
304 | <br><input type="submit" value="'._L('Change email address').'"> |
322 | <br><input type="submit" value="'._L('Change email address').'"> |
305 | </form>'; |
323 | </form>'; |
306 | } |
324 | } |
307 | } |
325 | } |
308 | } |
326 | } |
309 | } |
327 | } |
310 | } |
328 | } |
311 | 329 | ||
312 | /** |
330 | /** |
313 | * @param array $json |
331 | * @param array $json |
314 | * @param string|null $ra_email |
332 | * @param string|null $ra_email |
315 | * @param bool $nonjs |
333 | * @param bool $nonjs |
316 | * @param string $req_goto |
334 | * @param string $req_goto |
317 | * @return bool |
335 | * @return bool |
318 | * @throws OIDplusException |
336 | * @throws OIDplusException |
319 | */ |
337 | */ |
320 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
338 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
321 | if (!$ra_email) return false; |
339 | if (!$ra_email) return false; |
322 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false; |
340 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false; |
323 | 341 | ||
324 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
342 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
325 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
343 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
326 | } else { |
344 | } else { |
327 | $tree_icon = null; // default icon (folder) |
345 | $tree_icon = null; // default icon (folder) |
328 | } |
346 | } |
329 | 347 | ||
330 | $json[] = array( |
348 | $json[] = array( |
331 | 'id' => 'oidplus:change_ra_email$'.$ra_email, |
349 | 'id' => 'oidplus:change_ra_email$'.$ra_email, |
332 | 'icon' => $tree_icon, |
350 | 'icon' => $tree_icon, |
333 | 'text' => _L('Change email address') |
351 | 'text' => _L('Change email address') |
334 | ); |
352 | ); |
335 | 353 | ||
336 | return true; |
354 | return true; |
337 | } |
355 | } |
338 | 356 | ||
339 | /** |
357 | /** |
340 | * @param string $request |
358 | * @param string $request |
341 | * @return array|false |
359 | * @return array|false |
342 | */ |
360 | */ |
343 | public function tree_search(string $request) { |
361 | public function tree_search(string $request) { |
344 | return false; |
362 | return false; |
345 | } |
363 | } |
346 | } |
364 | } |
347 | 365 |