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