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