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