Rev 559 | 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 |
||
511 | daniel-mar | 5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
61 | daniel-mar | 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 | |||
511 | daniel-mar | 20 | if (!defined('INSIDE_OIDPLUS')) die(); |
21 | |||
256 | daniel-mar | 22 | class OIDplusPageRaChangePassword extends OIDplusPagePluginRa { |
61 | daniel-mar | 23 | |
321 | daniel-mar | 24 | public function action($actionID, $params) { |
25 | if ($actionID == 'change_ra_password') { |
||
552 | daniel-mar | 26 | _CheckParamExists($params, 'email'); |
559 | daniel-mar | 27 | |
321 | daniel-mar | 28 | $email = $params['email']; |
61 | daniel-mar | 29 | |
261 | daniel-mar | 30 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); |
236 | daniel-mar | 31 | if ($res->num_rows() == 0) { |
360 | daniel-mar | 32 | throw new OIDplusException(_L('RA does not exist')); |
61 | daniel-mar | 33 | } |
34 | |||
549 | daniel-mar | 35 | if (!OIDplus::authUtils()->isRaLoggedIn($email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
360 | daniel-mar | 36 | throw new OIDplusException(_L('Authentication error. Please log in as admin, or as the RA to update its data.')); |
61 | daniel-mar | 37 | } |
38 | |||
549 | daniel-mar | 39 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
552 | daniel-mar | 40 | _CheckParamExists($params, 'old_password'); |
321 | daniel-mar | 41 | $old_password = $params['old_password']; |
585 | daniel-mar | 42 | } else { |
43 | $old_password = ''; |
||
152 | daniel-mar | 44 | } |
559 | daniel-mar | 45 | |
552 | daniel-mar | 46 | _CheckParamExists($params, 'new_password1'); |
47 | _CheckParamExists($params, 'new_password2'); |
||
559 | daniel-mar | 48 | |
321 | daniel-mar | 49 | $password1 = $params['new_password1']; |
50 | $password2 = $params['new_password2']; |
||
61 | daniel-mar | 51 | |
52 | if ($password1 !== $password2) { |
||
360 | daniel-mar | 53 | throw new OIDplusException(_L('Passwords do not match')); |
61 | daniel-mar | 54 | } |
55 | |||
257 | daniel-mar | 56 | if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) { |
360 | daniel-mar | 57 | $minlen = OIDplus::config()->getValue('ra_min_password_length'); |
58 | throw new OIDplusException(_L('New password is too short. Minimum password length: %1',$minlen)); |
||
61 | daniel-mar | 59 | } |
60 | |||
61 | $ra = new OIDplusRA($email); |
||
433 | daniel-mar | 62 | if (!$ra->isPasswordLess()) { |
549 | daniel-mar | 63 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
433 | daniel-mar | 64 | if (!$ra->checkPassword($old_password)) { |
65 | throw new OIDplusException(_L('Old password incorrect')); |
||
66 | } |
||
152 | daniel-mar | 67 | } |
433 | daniel-mar | 68 | OIDplus::logger()->log("[?WARN/!OK]RA($email)?/[?INFO/!OK]A?", "Password of RA '$email' changed"); |
69 | } else { |
||
70 | OIDplus::logger()->log("[?WARN/!OK]RA($email)?/[?INFO/!OK]A?", "Password of RA '$email' created"); |
||
61 | daniel-mar | 71 | } |
72 | $ra->change_password($password1); |
||
73 | |||
328 | daniel-mar | 74 | return array("status" => 0); |
321 | daniel-mar | 75 | } else { |
360 | daniel-mar | 76 | throw new OIDplusException(_L('Unknown action ID')); |
61 | daniel-mar | 77 | } |
78 | } |
||
79 | |||
75 | daniel-mar | 80 | public function init($html=true) { |
61 | daniel-mar | 81 | // Nothing |
82 | } |
||
83 | |||
84 | public function gui($id, &$out, &$handled) { |
||
85 | if (explode('$',$id)[0] == 'oidplus:change_ra_password') { |
||
86 | $handled = true; |
||
360 | daniel-mar | 87 | |
281 | daniel-mar | 88 | $ra_email = explode('$',$id)[1]; |
433 | daniel-mar | 89 | $ra = new OIDplusRA($ra_email); |
281 | daniel-mar | 90 | |
433 | daniel-mar | 91 | $out['title'] = $ra->isPasswordLess() ? _L('Create password') : _L('Change RA password'); |
241 | daniel-mar | 92 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : ''; |
61 | daniel-mar | 93 | |
549 | daniel-mar | 94 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
281 | daniel-mar | 95 | $out['icon'] = 'img/error_big.png'; |
559 | daniel-mar | 96 | $out['text'] = '<p>'._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>').'</p>'; |
281 | daniel-mar | 97 | return; |
98 | } |
||
61 | daniel-mar | 99 | |
261 | daniel-mar | 100 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
236 | daniel-mar | 101 | if ($res->num_rows() == 0) { |
61 | daniel-mar | 102 | $out['icon'] = 'img/error_big.png'; |
360 | daniel-mar | 103 | $out['text'] = _L('RA "%1" does not exist','<b>'.htmlentities($ra_email).'</b>'); |
281 | daniel-mar | 104 | return; |
61 | daniel-mar | 105 | } |
106 | |||
549 | daniel-mar | 107 | $out['text'] .= '<form id="raChangePasswordForm" action="javascript:void(0);" onsubmit="return OIDplusPageRaChangePassword.raChangePasswordFormOnSubmit();">'; |
281 | daniel-mar | 108 | $out['text'] .= '<input type="hidden" id="email" value="'.htmlentities($ra_email).'"/><br>'; |
360 | daniel-mar | 109 | $out['text'] .= '<div><label class="padding_label">'._L('E-Mail').':</label><b>'.htmlentities($ra_email).'</b></div>'; |
433 | daniel-mar | 110 | if (!$ra->isPasswordLess()) { |
549 | daniel-mar | 111 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
433 | daniel-mar | 112 | $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>'; |
113 | } else { |
||
114 | $out['text'] .= '<div><label class="padding_label">'._L('Old password').':</label><input type="password" id="old_password" value=""/></div>'; |
||
115 | } |
||
61 | daniel-mar | 116 | } |
360 | daniel-mar | 117 | $out['text'] .= '<div><label class="padding_label">'._L('New password').':</label><input type="password" id="new_password1" value=""/></div>'; |
118 | $out['text'] .= '<div><label class="padding_label">'._L('Repeat').':</label><input type="password" id="new_password2" value=""/></div>'; |
||
433 | daniel-mar | 119 | $out['text'] .= '<br><input type="submit" value="'.($ra->isPasswordLess() ? _L('Create password') : _L('Change password')).'"></form>'; |
61 | daniel-mar | 120 | } |
121 | } |
||
122 | |||
106 | daniel-mar | 123 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
281 | daniel-mar | 124 | if (!$ra_email) return false; |
549 | daniel-mar | 125 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false; |
360 | daniel-mar | 126 | |
61 | daniel-mar | 127 | if (file_exists(__DIR__.'/treeicon.png')) { |
241 | daniel-mar | 128 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
61 | daniel-mar | 129 | } else { |
130 | $tree_icon = null; // default icon (folder) |
||
131 | } |
||
132 | |||
433 | daniel-mar | 133 | $ra = new OIDplusRA($ra_email); |
134 | |||
61 | daniel-mar | 135 | $json[] = array( |
136 | 'id' => 'oidplus:change_ra_password$'.$ra_email, |
||
137 | 'icon' => $tree_icon, |
||
433 | daniel-mar | 138 | 'text' => $ra->isPasswordLess() ? _L('Create password') : _L('Change password') |
61 | daniel-mar | 139 | ); |
104 | daniel-mar | 140 | |
141 | return true; |
||
61 | daniel-mar | 142 | } |
108 | daniel-mar | 143 | |
144 | public function tree_search($request) { |
||
145 | return false; |
||
146 | } |
||
433 | daniel-mar | 147 | } |