Rev 360 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
61 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
5 | * Copyright 2019 Daniel Marschall, ViaThinkSoft |
||
6 | * |
||
7 | * Licensed under the Apache License, Version 2.0 (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 |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
256 | daniel-mar | 20 | class OIDplusPageRaChangePassword extends OIDplusPagePluginRa { |
61 | daniel-mar | 21 | |
321 | daniel-mar | 22 | public function action($actionID, $params) { |
23 | if ($actionID == 'change_ra_password') { |
||
24 | $email = $params['email']; |
||
61 | daniel-mar | 25 | |
261 | daniel-mar | 26 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); |
236 | daniel-mar | 27 | if ($res->num_rows() == 0) { |
360 | daniel-mar | 28 | throw new OIDplusException(_L('RA does not exist')); |
61 | daniel-mar | 29 | } |
30 | |||
31 | if (!OIDplus::authUtils()::isRaLoggedIn($email) && !OIDplus::authUtils()::isAdminLoggedIn()) { |
||
360 | daniel-mar | 32 | throw new OIDplusException(_L('Authentication error. Please log in as admin, or as the RA to update its data.')); |
61 | daniel-mar | 33 | } |
34 | |||
152 | daniel-mar | 35 | if (!OIDplus::authUtils()::isAdminLoggedIn()) { |
321 | daniel-mar | 36 | $old_password = $params['old_password']; |
152 | daniel-mar | 37 | } |
321 | daniel-mar | 38 | $password1 = $params['new_password1']; |
39 | $password2 = $params['new_password2']; |
||
61 | daniel-mar | 40 | |
41 | if ($password1 !== $password2) { |
||
360 | daniel-mar | 42 | throw new OIDplusException(_L('Passwords do not match')); |
61 | daniel-mar | 43 | } |
44 | |||
257 | daniel-mar | 45 | if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) { |
360 | daniel-mar | 46 | $minlen = OIDplus::config()->getValue('ra_min_password_length'); |
47 | throw new OIDplusException(_L('New password is too short. Minimum password length: %1',$minlen)); |
||
61 | daniel-mar | 48 | } |
49 | |||
50 | $ra = new OIDplusRA($email); |
||
152 | daniel-mar | 51 | if (!OIDplus::authUtils()::isAdminLoggedIn()) { |
52 | if (!$ra->checkPassword($old_password)) { |
||
360 | daniel-mar | 53 | throw new OIDplusException(_L('Old password incorrect')); |
152 | daniel-mar | 54 | } |
61 | daniel-mar | 55 | } |
288 | daniel-mar | 56 | OIDplus::logger()->log("[?WARN/!OK]RA($email)?/[?INFO/!OK]A?", "Password of RA '$email' changed"); |
61 | daniel-mar | 57 | $ra->change_password($password1); |
58 | |||
328 | daniel-mar | 59 | return array("status" => 0); |
321 | daniel-mar | 60 | } else { |
360 | daniel-mar | 61 | throw new OIDplusException(_L('Unknown action ID')); |
61 | daniel-mar | 62 | } |
63 | } |
||
64 | |||
75 | daniel-mar | 65 | public function init($html=true) { |
61 | daniel-mar | 66 | // Nothing |
67 | } |
||
68 | |||
69 | public function gui($id, &$out, &$handled) { |
||
70 | if (explode('$',$id)[0] == 'oidplus:change_ra_password') { |
||
71 | $handled = true; |
||
360 | daniel-mar | 72 | |
281 | daniel-mar | 73 | $ra_email = explode('$',$id)[1]; |
74 | |||
360 | daniel-mar | 75 | $out['title'] = _L('Change RA password'); |
241 | daniel-mar | 76 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : ''; |
61 | daniel-mar | 77 | |
281 | daniel-mar | 78 | if (!OIDplus::authUtils()::isRaLoggedIn($ra_email) && !OIDplus::authUtils()::isAdminLoggedIn()) { |
79 | $out['icon'] = 'img/error_big.png'; |
||
360 | daniel-mar | 80 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as the requested RA %2.',OIDplus::gui()->link('oidplus:login'),'<b>'.htmlentities($ra_email).'</b>').'</p>'; |
281 | daniel-mar | 81 | return; |
82 | } |
||
61 | daniel-mar | 83 | |
261 | daniel-mar | 84 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
236 | daniel-mar | 85 | if ($res->num_rows() == 0) { |
61 | daniel-mar | 86 | $out['icon'] = 'img/error_big.png'; |
360 | daniel-mar | 87 | $out['text'] = _L('RA "%1" does not exist','<b>'.htmlentities($ra_email).'</b>'); |
281 | daniel-mar | 88 | return; |
61 | daniel-mar | 89 | } |
90 | |||
428 | daniel-mar | 91 | $out['text'] .= '<form id="raChangePasswordForm" action="javascript:void(0);" onsubmit="return raChangePasswordFormOnSubmit();">'; |
281 | daniel-mar | 92 | $out['text'] .= '<input type="hidden" id="email" value="'.htmlentities($ra_email).'"/><br>'; |
360 | daniel-mar | 93 | $out['text'] .= '<div><label class="padding_label">'._L('E-Mail').':</label><b>'.htmlentities($ra_email).'</b></div>'; |
281 | daniel-mar | 94 | if (OIDplus::authUtils()::isAdminLoggedIn()) { |
360 | daniel-mar | 95 | $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>'; |
61 | daniel-mar | 96 | } else { |
360 | daniel-mar | 97 | $out['text'] .= '<div><label class="padding_label">'._L('Old password').':</label><input type="password" id="old_password" value=""/></div>'; |
61 | daniel-mar | 98 | } |
360 | daniel-mar | 99 | $out['text'] .= '<div><label class="padding_label">'._L('New password').':</label><input type="password" id="new_password1" value=""/></div>'; |
100 | $out['text'] .= '<div><label class="padding_label">'._L('Repeat').':</label><input type="password" id="new_password2" value=""/></div>'; |
||
101 | $out['text'] .= '<br><input type="submit" value="'._L('Change password').'"></form>'; |
||
61 | daniel-mar | 102 | } |
103 | } |
||
104 | |||
106 | daniel-mar | 105 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
281 | daniel-mar | 106 | if (!$ra_email) return false; |
107 | if (!OIDplus::authUtils()::isRaLoggedIn($ra_email) && !OIDplus::authUtils()::isAdminLoggedIn()) return false; |
||
360 | daniel-mar | 108 | |
61 | daniel-mar | 109 | if (file_exists(__DIR__.'/treeicon.png')) { |
241 | daniel-mar | 110 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
61 | daniel-mar | 111 | } else { |
112 | $tree_icon = null; // default icon (folder) |
||
113 | } |
||
114 | |||
115 | $json[] = array( |
||
116 | 'id' => 'oidplus:change_ra_password$'.$ra_email, |
||
117 | 'icon' => $tree_icon, |
||
360 | daniel-mar | 118 | 'text' => _L('Change password') |
61 | daniel-mar | 119 | ); |
104 | daniel-mar | 120 | |
121 | return true; |
||
61 | daniel-mar | 122 | } |
108 | daniel-mar | 123 | |
124 | public function tree_search($request) { |
||
125 | return false; |
||
126 | } |
||
360 | daniel-mar | 127 | } |