Rev 1278 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1278 | 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 OIDplusPageAdminCreateRa extends OIDplusPagePluginAdmin { |
26 | class OIDplusPageAdminCreateRa extends OIDplusPagePluginAdmin { |
27 | 27 | ||
- | 28 | ||
28 | /** |
29 | /** |
29 | * @param string $actionID |
- | |
30 | * @param array $params |
30 | * @param array $params |
31 | * @return array |
31 | * @return array |
32 | * @throws OIDplusException |
32 | * @throws OIDplusException |
33 | */ |
33 | */ |
34 | public function action(string $actionID, array $params): array { |
34 | private function action_Create(array $params): array { |
35 | if ($actionID == 'create_ra') { |
- | |
36 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
35 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
37 | throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), null, 401); |
36 | throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), null, 401); |
38 | } |
37 | } |
39 | 38 | ||
40 | _CheckParamExists($params, 'email'); |
39 | _CheckParamExists($params, 'email'); |
41 | _CheckParamExists($params, 'password1'); |
40 | _CheckParamExists($params, 'password1'); |
42 | _CheckParamExists($params, 'password2'); |
41 | _CheckParamExists($params, 'password2'); |
43 | 42 | ||
44 | $email = $params['email']; |
43 | $email = $params['email']; |
45 | $password1 = $params['password1']; |
44 | $password1 = $params['password1']; |
46 | $password2 = $params['password2']; |
45 | $password2 = $params['password2']; |
47 | 46 | ||
48 | if (!OIDplus::mailUtils()->validMailAddress($email)) { |
47 | if (!OIDplus::mailUtils()->validMailAddress($email)) { |
49 | throw new OIDplusException(_L('eMail address is invalid.')); |
48 | throw new OIDplusException(_L('eMail address is invalid.')); |
50 | } |
49 | } |
51 | 50 | ||
52 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); // TODO: this should be a static function in the RA class |
51 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); // TODO: this should be a static function in the RA class |
53 | if ($res->any()) { |
52 | if ($res->any()) { |
54 | throw new OIDplusException(_L('RA does already exist')); |
53 | throw new OIDplusException(_L('RA does already exist')); |
55 | } |
54 | } |
56 | 55 | ||
57 | if ($password1 !== $password2) { |
56 | if ($password1 !== $password2) { |
58 | throw new OIDplusException(_L('Passwords do not match')); |
57 | throw new OIDplusException(_L('Passwords do not match')); |
59 | } |
58 | } |
60 | 59 | ||
61 | if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) { |
60 | if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) { |
62 | $minlen = OIDplus::config()->getValue('ra_min_password_length'); |
61 | $minlen = OIDplus::config()->getValue('ra_min_password_length'); |
63 | throw new OIDplusException(_L('Password is too short. Need at least %1 characters',$minlen)); |
62 | throw new OIDplusException(_L('Password is too short. Need at least %1 characters',$minlen)); |
64 | } |
63 | } |
65 | 64 | ||
66 | OIDplus::logger()->log("V2:[INFO]RA(%1)+[OK/INFO]A", "RA '%1' was created by the admin, without email address verification or invitation", $email); |
65 | OIDplus::logger()->log("V2:[INFO]RA(%1)+[OK/INFO]A", "RA '%1' was created by the admin, without email address verification or invitation", $email); |
67 | 66 | ||
68 | $ra = new OIDplusRA($email); |
67 | $ra = new OIDplusRA($email); |
69 | $ra->register_ra($password1); |
68 | $ra->register_ra($password1); |
70 | 69 | ||
71 | return array("status" => 0); |
70 | return array("status" => 0); |
- | 71 | } |
|
- | 72 | ||
- | 73 | /** |
|
- | 74 | * @param string $actionID |
|
- | 75 | * @param array $params |
|
- | 76 | * @return array |
|
- | 77 | * @throws OIDplusException |
|
- | 78 | */ |
|
- | 79 | public function action(string $actionID, array $params): array { |
|
- | 80 | if ($actionID == 'create_ra') { |
|
- | 81 | return $this->action_Create($params); |
|
72 | } else { |
82 | } else { |
73 | return parent::action($actionID, $params); |
83 | return parent::action($actionID, $params); |
74 | } |
84 | } |
75 | } |
85 | } |
76 | 86 | ||
77 | /** |
87 | /** |
78 | * @param bool $html |
88 | * @param bool $html |
79 | * @return void |
89 | * @return void |
80 | */ |
90 | */ |
81 | public function init(bool $html=true) { |
91 | public function init(bool $html=true) { |
82 | // Nothing |
92 | // Nothing |
83 | } |
93 | } |
84 | 94 | ||
85 | /** |
95 | /** |
86 | * @param string $id |
96 | * @param string $id |
87 | * @param array $out |
97 | * @param array $out |
88 | * @param bool $handled |
98 | * @param bool $handled |
89 | * @return void |
99 | * @return void |
90 | * @throws OIDplusException |
100 | * @throws OIDplusException |
91 | */ |
101 | */ |
92 | public function gui(string $id, array &$out, bool &$handled) { |
102 | public function gui(string $id, array &$out, bool &$handled) { |
93 | $parts = explode('$',$id,2); |
103 | $parts = explode('$',$id,2); |
94 | $id = $parts[0]; |
104 | $id = $parts[0]; |
95 | $email = $parts[1] ?? ''; |
105 | $email = $parts[1] ?? ''; |
96 | 106 | ||
97 | if ($id == 'oidplus:create_ra') { |
107 | if ($id == 'oidplus:create_ra') { |
98 | $handled = true; |
108 | $handled = true; |
99 | 109 | ||
100 | $out['title'] = _L('Manual creation of a RA'); |
110 | $out['title'] = _L('Manual creation of a RA'); |
101 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
111 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
102 | 112 | ||
103 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
113 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
104 | throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), $out['title'], 401); |
114 | throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), $out['title'], 401); |
105 | } |
115 | } |
106 | 116 | ||
107 | $out['text'] .= '<form id="adminCreateRaFrom" action="javascript:void(0);" onsubmit="return OIDplusPageAdminCreateRa.adminCreateRaFormOnSubmit();">'; |
117 | $out['text'] .= '<form id="adminCreateRaFrom" action="javascript:void(0);" onsubmit="return OIDplusPageAdminCreateRa.adminCreateRaFormOnSubmit();">'; |
108 | $out['text'] .= '<div><label class="padding_label">'._L('E-Mail').':</label><input type="text" id="email" value="'.htmlentities($email).'"></div>'; |
118 | $out['text'] .= '<div><label class="padding_label">'._L('E-Mail').':</label><input type="text" id="email" value="'.htmlentities($email).'"></div>'; |
109 | $out['text'] .= '<div><label class="padding_label">'._L('Password').':</label><input type="password" id="password1" value=""/></div>'; |
119 | $out['text'] .= '<div><label class="padding_label">'._L('Password').':</label><input type="password" id="password1" value=""/></div>'; |
110 | $out['text'] .= '<div><label class="padding_label">'._L('Repeat').':</label><input type="password" id="password2" value=""/></div>'; |
120 | $out['text'] .= '<div><label class="padding_label">'._L('Repeat').':</label><input type="password" id="password2" value=""/></div>'; |
111 | $out['text'] .= '<br><input type="submit" value="'._L('Create').'"></form>'; |
121 | $out['text'] .= '<br><input type="submit" value="'._L('Create').'"></form>'; |
112 | } |
122 | } |
113 | } |
123 | } |
114 | 124 | ||
115 | /** |
125 | /** |
116 | * @param array $json |
126 | * @param array $json |
117 | * @param string|null $ra_email |
127 | * @param string|null $ra_email |
118 | * @param bool $nonjs |
128 | * @param bool $nonjs |
119 | * @param string $req_goto |
129 | * @param string $req_goto |
120 | * @return bool |
130 | * @return bool |
121 | * @throws OIDplusException |
131 | * @throws OIDplusException |
122 | */ |
132 | */ |
123 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
133 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
124 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
134 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
125 | 135 | ||
126 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
136 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
127 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
137 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
128 | } else { |
138 | } else { |
129 | $tree_icon = null; // default icon (folder) |
139 | $tree_icon = null; // default icon (folder) |
130 | } |
140 | } |
131 | 141 | ||
132 | $json[] = array( |
142 | $json[] = array( |
133 | 'id' => 'oidplus:create_ra', |
143 | 'id' => 'oidplus:create_ra', |
134 | 'icon' => $tree_icon, |
144 | 'icon' => $tree_icon, |
135 | 'text' => _L('Create RA manually') |
145 | 'text' => _L('Create RA manually') |
136 | ); |
146 | ); |
137 | 147 | ||
138 | return true; |
148 | return true; |
139 | } |
149 | } |
140 | 150 | ||
141 | /** |
151 | /** |
142 | * @param string $request |
152 | * @param string $request |
143 | * @return array|false |
153 | * @return array|false |
144 | */ |
154 | */ |
145 | public function tree_search(string $request) { |
155 | public function tree_search(string $request) { |
146 | return false; |
156 | return false; |
147 | } |
157 | } |
148 | } |
158 | } |
149 | 159 |